| 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; |
| 104 | import android.view.KeyEvent; |
| 105 | import android.view.MotionEvent; |
| 106 | import android.view.RawInputEvent; |
| 107 | import android.view.Surface; |
| 108 | import android.view.SurfaceSession; |
| 109 | import android.view.View; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 110 | import android.view.ViewConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import android.view.ViewTreeObserver; |
| 112 | import android.view.WindowManager; |
| 113 | import android.view.WindowManagerImpl; |
| 114 | import android.view.WindowManagerPolicy; |
| 115 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 116 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | import android.view.animation.Animation; |
| 118 | import android.view.animation.AnimationUtils; |
| 119 | import android.view.animation.Transformation; |
| 120 | |
| 121 | import java.io.BufferedWriter; |
| 122 | import java.io.File; |
| 123 | import java.io.FileDescriptor; |
| 124 | import java.io.IOException; |
| 125 | import java.io.OutputStream; |
| 126 | import java.io.OutputStreamWriter; |
| 127 | import java.io.PrintWriter; |
| 128 | import java.io.StringWriter; |
| 129 | import java.net.Socket; |
| 130 | import java.util.ArrayList; |
| 131 | import java.util.HashMap; |
| 132 | import java.util.HashSet; |
| 133 | import java.util.Iterator; |
| 134 | import java.util.List; |
| 135 | |
| 136 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 137 | public class WindowManagerService extends IWindowManager.Stub |
| 138 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | static final String TAG = "WindowManager"; |
| 140 | static final boolean DEBUG = false; |
| 141 | static final boolean DEBUG_FOCUS = false; |
| 142 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 143 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 144 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_LAYERS = false; |
| 146 | static final boolean DEBUG_INPUT = false; |
| 147 | static final boolean DEBUG_INPUT_METHOD = false; |
| 148 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 149 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 151 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 153 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 154 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 155 | static final boolean DEBUG_WALLPAPER = false; |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 156 | static final boolean DEBUG_FREEZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 158 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 159 | static final boolean MEASURE_LATENCY = false; |
| 160 | static private LatencyTimer lt; |
| 161 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | static final boolean PROFILE_ORIENTATION = false; |
| 163 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 164 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 165 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 167 | static final int KEY_REPEAT_DELAY = 50; |
| 168 | |
| 169 | /** How much to multiply the policy's type layer, to reserve room |
| 170 | * for multiple windows of the same type and Z-ordering adjustment |
| 171 | * with TYPE_LAYER_OFFSET. */ |
| 172 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 173 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 175 | * or below others in the same layer. */ |
| 176 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 177 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | /** How much to increment the layer for each window, to reserve room |
| 179 | * for effect surfaces between them. |
| 180 | */ |
| 181 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 182 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | /** The maximum length we will accept for a loaded animation duration: |
| 184 | * this is 10 seconds. |
| 185 | */ |
| 186 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 187 | |
| 188 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 189 | * value to another, when no window animation is driving it. |
| 190 | */ |
| 191 | static final int DEFAULT_DIM_DURATION = 200; |
| 192 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 193 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 194 | * compatible windows. |
| 195 | */ |
| 196 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 199 | */ |
| 200 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 201 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 202 | static final int INJECT_FAILED = 0; |
| 203 | static final int INJECT_SUCCEEDED = 1; |
| 204 | static final int INJECT_NO_PERMISSION = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 205 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 207 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 208 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 209 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 210 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 211 | /** The minimum time between dispatching touch events. */ |
| 212 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 213 | |
| 214 | // Last touch event time |
| 215 | long mLastTouchEventTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 216 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 217 | // Last touch event type |
| 218 | int mLastTouchEventType = OTHER_EVENT; |
| 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 | // Time to wait before calling useractivity again. This saves CPU usage |
| 221 | // when we get a flood of touch events. |
| 222 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 223 | |
| 224 | // Last time we call user activity |
| 225 | long mLastUserActivityCallTime = 0; |
| 226 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 227 | // Last time we updated battery stats |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 228 | long mLastBatteryStatsCallTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 229 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 231 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 235 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 236 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 237 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 239 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 241 | private static final int ALLOW_DISABLE_YES = 1; |
| 242 | private static final int ALLOW_DISABLE_NO = 0; |
| 243 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 244 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 245 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 246 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 247 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | public void acquired() { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 249 | if (shouldAllowDisableKeyguard()) { |
| 250 | mPolicy.enableKeyguard(false); |
| 251 | mKeyguardDisabled = true; |
| 252 | } else { |
| 253 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 254 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | } |
| 256 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 257 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 258 | synchronized (mKeyguardTokenWatcher) { |
| 259 | mKeyguardDisabled = false; |
| 260 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | }; |
| 264 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 265 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 266 | @Override |
| 267 | public void onReceive(Context context, Intent intent) { |
| 268 | mPolicy.enableKeyguard(true); |
| 269 | synchronized(mKeyguardTokenWatcher) { |
| 270 | // lazily evaluate this next time we're asked to disable keyguard |
| 271 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 272 | mKeyguardDisabled = false; |
| 273 | } |
| 274 | } |
| 275 | }; |
| 276 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | final Context mContext; |
| 278 | |
| 279 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 280 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 284 | |
| 285 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 286 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | /** |
| 290 | * All currently active sessions with clients. |
| 291 | */ |
| 292 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | /** |
| 295 | * Mapping from an IWindow IBinder to the server's Window object. |
| 296 | * This is also used as the lock for all of our state. |
| 297 | */ |
| 298 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 299 | |
| 300 | /** |
| 301 | * Mapping from a token IBinder to a WindowToken object. |
| 302 | */ |
| 303 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 304 | new HashMap<IBinder, WindowToken>(); |
| 305 | |
| 306 | /** |
| 307 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 308 | * over them. |
| 309 | */ |
| 310 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | /** |
| 313 | * Window tokens that are in the process of exiting, but still |
| 314 | * on screen for animations. |
| 315 | */ |
| 316 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 317 | |
| 318 | /** |
| 319 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 320 | * controlling the ordering of windows in different applications. This |
| 321 | * contains WindowToken objects. |
| 322 | */ |
| 323 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 324 | |
| 325 | /** |
| 326 | * Application tokens that are in the process of exiting, but still |
| 327 | * on screen for animations. |
| 328 | */ |
| 329 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 330 | |
| 331 | /** |
| 332 | * List of window tokens that have finished starting their application, |
| 333 | * and now need to have the policy remove their windows. |
| 334 | */ |
| 335 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 336 | |
| 337 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 338 | * This was the app token that was used to retrieve the last enter |
| 339 | * animation. It will be used for the next exit animation. |
| 340 | */ |
| 341 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 342 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 343 | /** |
| 344 | * These were the layout params used to retrieve the last enter animation. |
| 345 | * They will be used for the next exit animation. |
| 346 | */ |
| 347 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 348 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 349 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | * Z-ordered (bottom-most first) list of all Window objects. |
| 351 | */ |
| 352 | final ArrayList mWindows = new ArrayList(); |
| 353 | |
| 354 | /** |
| 355 | * Windows that are being resized. Used so we can tell the client about |
| 356 | * the resize after closing the transaction in which we resized the |
| 357 | * underlying surface. |
| 358 | */ |
| 359 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 360 | |
| 361 | /** |
| 362 | * Windows whose animations have ended and now must be removed. |
| 363 | */ |
| 364 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 365 | |
| 366 | /** |
| 367 | * Windows whose surface should be destroyed. |
| 368 | */ |
| 369 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 370 | |
| 371 | /** |
| 372 | * Windows that have lost input focus and are waiting for the new |
| 373 | * focus window to be displayed before they are told about this. |
| 374 | */ |
| 375 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 376 | |
| 377 | /** |
| 378 | * This is set when we have run out of memory, and will either be an empty |
| 379 | * list or contain windows that need to be force removed. |
| 380 | */ |
| 381 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 382 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 386 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | Surface mBlurSurface; |
| 388 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | int mTransactionSequence = 0; |
| 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 | final float[] mTmpFloats = new float[9]; |
| 393 | |
| 394 | boolean mSafeMode; |
| 395 | boolean mDisplayEnabled = false; |
| 396 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 397 | int mInitialDisplayWidth = 0; |
| 398 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | int mRotation = 0; |
| 400 | int mRequestedRotation = 0; |
| 401 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 402 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | ArrayList<IRotationWatcher> mRotationWatchers |
| 404 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 405 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | boolean mLayoutNeeded = true; |
| 407 | boolean mAnimationPending = false; |
| 408 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 409 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | boolean mWindowsFreezingScreen = false; |
| 411 | long mFreezeGcPending = 0; |
| 412 | int mAppsFreezingScreen = 0; |
| 413 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 414 | int mLayoutSeq = 0; |
| 415 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 416 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 417 | boolean mFocusMayChange; |
| 418 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 419 | Configuration mCurConfiguration = new Configuration(); |
| 420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | // This is held as long as we have the screen frozen, to give us time to |
| 422 | // perform a rotation animation when turning off shows the lock screen which |
| 423 | // changes the orientation. |
| 424 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | // State management of app transitions. When we are preparing for a |
| 427 | // transition, mNextAppTransition will be the kind of transition to |
| 428 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 429 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 430 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 431 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 432 | String mNextAppTransitionPackage; |
| 433 | int mNextAppTransitionEnter; |
| 434 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 436 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | boolean mAppTransitionTimeout = false; |
| 438 | boolean mStartingIconInTransition = false; |
| 439 | boolean mSkipAppTransitionAnimation = false; |
| 440 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 441 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 442 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 443 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 444 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | //flag to detect fat touch events |
| 446 | boolean mFatTouch = false; |
| 447 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 448 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | H mH = new H(); |
| 450 | |
| 451 | WindowState mCurrentFocus = null; |
| 452 | WindowState mLastFocus = null; |
| 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 | // This just indicates the window the input method is on top of, not |
| 455 | // necessarily the window its input is going to. |
| 456 | WindowState mInputMethodTarget = null; |
| 457 | WindowState mUpcomingInputMethodTarget = null; |
| 458 | boolean mInputMethodTargetWaitingAnim; |
| 459 | int mInputMethodAnimLayerAdjustment; |
| 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 | WindowState mInputMethodWindow = null; |
| 462 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 463 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 464 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 465 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 466 | // If non-null, this is the currently visible window that is associated |
| 467 | // with the wallpaper. |
| 468 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 469 | // If non-null, we are in the middle of animating from one wallpaper target |
| 470 | // to another, and this is the lower one in Z-order. |
| 471 | WindowState mLowerWallpaperTarget = null; |
| 472 | // If non-null, we are in the middle of animating from one wallpaper target |
| 473 | // to another, and this is the higher one in Z-order. |
| 474 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 475 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 476 | float mLastWallpaperX = -1; |
| 477 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 478 | float mLastWallpaperXStep = -1; |
| 479 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 480 | boolean mSendingPointersToWallpaper = false; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 481 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 482 | // changing its scroll position. |
| 483 | WindowState mWaitingOnWallpaper; |
| 484 | // The last time we had a timeout when waiting for a wallpaper. |
| 485 | long mLastWallpaperTimeoutTime; |
| 486 | // We give a wallpaper up to 150ms to finish scrolling. |
| 487 | static final long WALLPAPER_TIMEOUT = 150; |
| 488 | // Time we wait after a timeout before trying to wait again. |
| 489 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 490 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | AppWindowToken mFocusedApp = null; |
| 492 | |
| 493 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | float mWindowAnimationScale = 1.0f; |
| 496 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 497 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 499 | final KeyQ mQueue; |
| 500 | final InputDispatcherThread mInputThread; |
| 501 | |
| 502 | // Who is holding the screen on. |
| 503 | Session mHoldingScreenOn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 504 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 505 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | /** |
| 508 | * Whether the UI is currently running in touch mode (not showing |
| 509 | * navigational focus because the user is directly pressing the screen). |
| 510 | */ |
| 511 | boolean mInTouchMode = false; |
| 512 | |
| 513 | private ViewServer mViewServer; |
| 514 | |
| 515 | final Rect mTempRect = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 516 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 517 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 518 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 519 | |
| 520 | // The frame use to limit the size of the app running in compatibility mode. |
| 521 | Rect mCompatibleScreenFrame = new Rect(); |
| 522 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 523 | Surface mBackgroundFillerSurface = null; |
| 524 | boolean mBackgroundFillerShown = false; |
| 525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | public static WindowManagerService main(Context context, |
| 527 | PowerManagerService pm, boolean haveInputMethods) { |
| 528 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 529 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | synchronized (thr) { |
| 532 | while (thr.mService == null) { |
| 533 | try { |
| 534 | thr.wait(); |
| 535 | } catch (InterruptedException e) { |
| 536 | } |
| 537 | } |
| 538 | } |
| 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 | return thr.mService; |
| 541 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 542 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | static class WMThread extends Thread { |
| 544 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 545 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | private final Context mContext; |
| 547 | private final PowerManagerService mPM; |
| 548 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | public WMThread(Context context, PowerManagerService pm, |
| 551 | boolean haveInputMethods) { |
| 552 | super("WindowManager"); |
| 553 | mContext = context; |
| 554 | mPM = pm; |
| 555 | mHaveInputMethods = haveInputMethods; |
| 556 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | public void run() { |
| 559 | Looper.prepare(); |
| 560 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 561 | mHaveInputMethods); |
| 562 | android.os.Process.setThreadPriority( |
| 563 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 564 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | synchronized (this) { |
| 566 | mService = s; |
| 567 | notifyAll(); |
| 568 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 569 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | Looper.loop(); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | static class PolicyThread extends Thread { |
| 575 | private final WindowManagerPolicy mPolicy; |
| 576 | private final WindowManagerService mService; |
| 577 | private final Context mContext; |
| 578 | private final PowerManagerService mPM; |
| 579 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 580 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | public PolicyThread(WindowManagerPolicy policy, |
| 582 | WindowManagerService service, Context context, |
| 583 | PowerManagerService pm) { |
| 584 | super("WindowManagerPolicy"); |
| 585 | mPolicy = policy; |
| 586 | mService = service; |
| 587 | mContext = context; |
| 588 | mPM = pm; |
| 589 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 590 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | public void run() { |
| 592 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 593 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 594 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 596 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | android.os.Process.setThreadPriority( |
| 598 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 599 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 600 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | synchronized (this) { |
| 602 | mRunning = true; |
| 603 | notifyAll(); |
| 604 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 605 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | Looper.loop(); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | private WindowManagerService(Context context, PowerManagerService pm, |
| 611 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 612 | if (MEASURE_LATENCY) { |
| 613 | lt = new LatencyTimer(100, 1000); |
| 614 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 615 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | mContext = context; |
| 617 | mHaveInputMethods = haveInputMethods; |
| 618 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 619 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | mPowerManager = pm; |
| 622 | mPowerManager.setPolicy(mPolicy); |
| 623 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 624 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 625 | "SCREEN_FROZEN"); |
| 626 | mScreenFrozenLock.setReferenceCounted(false); |
| 627 | |
| 628 | mActivityManager = ActivityManagerNative.getDefault(); |
| 629 | mBatteryStats = BatteryStatsService.getService(); |
| 630 | |
| 631 | // Get persisted window scale setting |
| 632 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 633 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 634 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 635 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 636 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 637 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 638 | IntentFilter filter = new IntentFilter(); |
| 639 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 640 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 641 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 642 | int max_events_per_sec = 35; |
| 643 | try { |
| 644 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 645 | .get("windowsmgr.max_events_per_sec")); |
| 646 | if (max_events_per_sec < 1) { |
| 647 | max_events_per_sec = 35; |
| 648 | } |
| 649 | } catch (NumberFormatException e) { |
| 650 | } |
| 651 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 652 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | mQueue = new KeyQ(); |
| 654 | |
| 655 | mInputThread = new InputDispatcherThread(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 656 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 658 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | synchronized (thr) { |
| 661 | while (!thr.mRunning) { |
| 662 | try { |
| 663 | thr.wait(); |
| 664 | } catch (InterruptedException e) { |
| 665 | } |
| 666 | } |
| 667 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 668 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | mInputThread.start(); |
| Christian Petersson | 15f66ce | 2010-06-03 11:16:39 +0200 | [diff] [blame] | 670 | mQueue.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 671 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | // Add ourself to the Watchdog monitors. |
| 673 | Watchdog.getInstance().addMonitor(this); |
| 674 | } |
| 675 | |
| 676 | @Override |
| 677 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 678 | throws RemoteException { |
| 679 | try { |
| 680 | return super.onTransact(code, data, reply, flags); |
| 681 | } catch (RuntimeException e) { |
| 682 | // The window manager only throws security exceptions, so let's |
| 683 | // log all others. |
| 684 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 685 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | } |
| 687 | throw e; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | private void placeWindowAfter(Object pos, WindowState window) { |
| 692 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 693 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | TAG, "Adding window " + window + " at " |
| 695 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 696 | mWindows.add(i+1, window); |
| 697 | } |
| 698 | |
| 699 | private void placeWindowBefore(Object pos, WindowState window) { |
| 700 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 701 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | TAG, "Adding window " + window + " at " |
| 703 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 704 | mWindows.add(i, window); |
| 705 | } |
| 706 | |
| 707 | //This method finds out the index of a window that has the same app token as |
| 708 | //win. used for z ordering the windows in mWindows |
| 709 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 710 | //use a local variable to cache mWindows |
| 711 | ArrayList localmWindows = mWindows; |
| 712 | int jmax = localmWindows.size(); |
| 713 | if(jmax == 0) { |
| 714 | return -1; |
| 715 | } |
| 716 | for(int j = (jmax-1); j >= 0; j--) { |
| 717 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 718 | if(wentry.mAppToken == win.mAppToken) { |
| 719 | return j; |
| 720 | } |
| 721 | } |
| 722 | return -1; |
| 723 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 724 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 726 | final IWindow client = win.mClient; |
| 727 | final WindowToken token = win.mToken; |
| 728 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 729 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | final int N = localmWindows.size(); |
| 731 | final WindowState attached = win.mAttachedWindow; |
| 732 | int i; |
| 733 | if (attached == null) { |
| 734 | int tokenWindowsPos = token.windows.size(); |
| 735 | if (token.appWindowToken != null) { |
| 736 | int index = tokenWindowsPos-1; |
| 737 | if (index >= 0) { |
| 738 | // If this application has existing windows, we |
| 739 | // simply place the new window on top of them... but |
| 740 | // keep the starting window on top. |
| 741 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 742 | // Base windows go behind everything else. |
| 743 | placeWindowBefore(token.windows.get(0), win); |
| 744 | tokenWindowsPos = 0; |
| 745 | } else { |
| 746 | AppWindowToken atoken = win.mAppToken; |
| 747 | if (atoken != null && |
| 748 | token.windows.get(index) == atoken.startingWindow) { |
| 749 | placeWindowBefore(token.windows.get(index), win); |
| 750 | tokenWindowsPos--; |
| 751 | } else { |
| 752 | int newIdx = findIdxBasedOnAppTokens(win); |
| 753 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 754 | //there is a window above this one associated with the same |
| 755 | //apptoken note that the window could be a floating window |
| 756 | //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] | 757 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 758 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 759 | TAG, "Adding window " + win + " at " |
| 760 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | localmWindows.add(newIdx+1, win); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 762 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 766 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | TAG, "Figuring out where to add app window " |
| 768 | + client.asBinder() + " (token=" + token + ")"); |
| 769 | // Figure out where the window should go, based on the |
| 770 | // order of applications. |
| 771 | final int NA = mAppTokens.size(); |
| 772 | Object pos = null; |
| 773 | for (i=NA-1; i>=0; i--) { |
| 774 | AppWindowToken t = mAppTokens.get(i); |
| 775 | if (t == token) { |
| 776 | i--; |
| 777 | break; |
| 778 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 779 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 780 | // We haven't reached the token yet; if this token |
| 781 | // is not going to the bottom and has windows, we can |
| 782 | // use it as an anchor for when we do reach the token. |
| 783 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | pos = t.windows.get(0); |
| 785 | } |
| 786 | } |
| 787 | // We now know the index into the apps. If we found |
| 788 | // an app window above, that gives us the position; else |
| 789 | // we need to look some more. |
| 790 | if (pos != null) { |
| 791 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 792 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 794 | if (atoken != null) { |
| 795 | final int NC = atoken.windows.size(); |
| 796 | if (NC > 0) { |
| 797 | WindowState bottom = atoken.windows.get(0); |
| 798 | if (bottom.mSubLayer < 0) { |
| 799 | pos = bottom; |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | placeWindowBefore(pos, win); |
| 804 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 805 | // Continue looking down until we find the first |
| 806 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | while (i >= 0) { |
| 808 | AppWindowToken t = mAppTokens.get(i); |
| 809 | final int NW = t.windows.size(); |
| 810 | if (NW > 0) { |
| 811 | pos = t.windows.get(NW-1); |
| 812 | break; |
| 813 | } |
| 814 | i--; |
| 815 | } |
| 816 | if (pos != null) { |
| 817 | // Move in front of any windows attached to this |
| 818 | // one. |
| 819 | WindowToken atoken = |
| 820 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 821 | if (atoken != null) { |
| 822 | final int NC = atoken.windows.size(); |
| 823 | if (NC > 0) { |
| 824 | WindowState top = atoken.windows.get(NC-1); |
| 825 | if (top.mSubLayer >= 0) { |
| 826 | pos = top; |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | placeWindowAfter(pos, win); |
| 831 | } else { |
| 832 | // Just search for the start of this layer. |
| 833 | final int myLayer = win.mBaseLayer; |
| 834 | for (i=0; i<N; i++) { |
| 835 | WindowState w = (WindowState)localmWindows.get(i); |
| 836 | if (w.mBaseLayer > myLayer) { |
| 837 | break; |
| 838 | } |
| 839 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 840 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 841 | TAG, "Adding window " + win + " at " |
| 842 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | localmWindows.add(i, win); |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | } else { |
| 848 | // Figure out where window should go, based on layer. |
| 849 | final int myLayer = win.mBaseLayer; |
| 850 | for (i=N-1; i>=0; i--) { |
| 851 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 852 | i++; |
| 853 | break; |
| 854 | } |
| 855 | } |
| 856 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 857 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 858 | TAG, "Adding window " + win + " at " |
| 859 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | localmWindows.add(i, win); |
| 861 | } |
| 862 | if (addToToken) { |
| 863 | token.windows.add(tokenWindowsPos, win); |
| 864 | } |
| 865 | |
| 866 | } else { |
| 867 | // Figure out this window's ordering relative to the window |
| 868 | // it is attached to. |
| 869 | final int NA = token.windows.size(); |
| 870 | final int sublayer = win.mSubLayer; |
| 871 | int largestSublayer = Integer.MIN_VALUE; |
| 872 | WindowState windowWithLargestSublayer = null; |
| 873 | for (i=0; i<NA; i++) { |
| 874 | WindowState w = token.windows.get(i); |
| 875 | final int wSublayer = w.mSubLayer; |
| 876 | if (wSublayer >= largestSublayer) { |
| 877 | largestSublayer = wSublayer; |
| 878 | windowWithLargestSublayer = w; |
| 879 | } |
| 880 | if (sublayer < 0) { |
| 881 | // For negative sublayers, we go below all windows |
| 882 | // in the same sublayer. |
| 883 | if (wSublayer >= sublayer) { |
| 884 | if (addToToken) { |
| 885 | token.windows.add(i, win); |
| 886 | } |
| 887 | placeWindowBefore( |
| 888 | wSublayer >= 0 ? attached : w, win); |
| 889 | break; |
| 890 | } |
| 891 | } else { |
| 892 | // For positive sublayers, we go above all windows |
| 893 | // in the same sublayer. |
| 894 | if (wSublayer > sublayer) { |
| 895 | if (addToToken) { |
| 896 | token.windows.add(i, win); |
| 897 | } |
| 898 | placeWindowBefore(w, win); |
| 899 | break; |
| 900 | } |
| 901 | } |
| 902 | } |
| 903 | if (i >= NA) { |
| 904 | if (addToToken) { |
| 905 | token.windows.add(win); |
| 906 | } |
| 907 | if (sublayer < 0) { |
| 908 | placeWindowBefore(attached, win); |
| 909 | } else { |
| 910 | placeWindowAfter(largestSublayer >= 0 |
| 911 | ? windowWithLargestSublayer |
| 912 | : attached, |
| 913 | win); |
| 914 | } |
| 915 | } |
| 916 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 917 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | if (win.mAppToken != null && addToToken) { |
| 919 | win.mAppToken.allAppWindows.add(win); |
| 920 | } |
| 921 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | static boolean canBeImeTarget(WindowState w) { |
| 924 | final int fl = w.mAttrs.flags |
| 925 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 926 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 927 | return w.isVisibleOrAdding(); |
| 928 | } |
| 929 | return false; |
| 930 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 933 | final ArrayList localmWindows = mWindows; |
| 934 | final int N = localmWindows.size(); |
| 935 | WindowState w = null; |
| 936 | int i = N; |
| 937 | while (i > 0) { |
| 938 | i--; |
| 939 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 940 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 941 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | // + Integer.toHexString(w.mAttrs.flags)); |
| 943 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 944 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 945 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | // Yet more tricksyness! If this window is a "starting" |
| 947 | // window, we do actually want to be on top of it, but |
| 948 | // it is not -really- where input will go. So if the caller |
| 949 | // is not actually looking to move the IME, look down below |
| 950 | // for a real window to target... |
| 951 | if (!willMove |
| 952 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 953 | && i > 0) { |
| 954 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 955 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 956 | i--; |
| 957 | w = wb; |
| 958 | } |
| 959 | } |
| 960 | break; |
| 961 | } |
| 962 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 963 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 965 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 966 | 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] | 967 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | if (willMove && w != null) { |
| 970 | final WindowState curTarget = mInputMethodTarget; |
| 971 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | // Now some fun for dealing with window animations that |
| 974 | // modify the Z order. We need to look at all windows below |
| 975 | // the current target that are in this app, finding the highest |
| 976 | // visible one in layering. |
| 977 | AppWindowToken token = curTarget.mAppToken; |
| 978 | WindowState highestTarget = null; |
| 979 | int highestPos = 0; |
| 980 | if (token.animating || token.animation != null) { |
| 981 | int pos = 0; |
| 982 | pos = localmWindows.indexOf(curTarget); |
| 983 | while (pos >= 0) { |
| 984 | WindowState win = (WindowState)localmWindows.get(pos); |
| 985 | if (win.mAppToken != token) { |
| 986 | break; |
| 987 | } |
| 988 | if (!win.mRemoved) { |
| 989 | if (highestTarget == null || win.mAnimLayer > |
| 990 | highestTarget.mAnimLayer) { |
| 991 | highestTarget = win; |
| 992 | highestPos = pos; |
| 993 | } |
| 994 | } |
| 995 | pos--; |
| 996 | } |
| 997 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 998 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1000 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | + mNextAppTransition + " " + highestTarget |
| 1002 | + " animating=" + highestTarget.isAnimating() |
| 1003 | + " layer=" + highestTarget.mAnimLayer |
| 1004 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1005 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1006 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | // If we are currently setting up for an animation, |
| 1008 | // hold everything until we can find out what will happen. |
| 1009 | mInputMethodTargetWaitingAnim = true; |
| 1010 | mInputMethodTarget = highestTarget; |
| 1011 | return highestPos + 1; |
| 1012 | } else if (highestTarget.isAnimating() && |
| 1013 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1014 | // If the window we are currently targeting is involved |
| 1015 | // with an animation, and it is on top of the next target |
| 1016 | // we will be over, then hold off on moving until |
| 1017 | // that is done. |
| 1018 | mInputMethodTarget = highestTarget; |
| 1019 | return highestPos + 1; |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1024 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1025 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1026 | if (w != null) { |
| 1027 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1028 | if (DEBUG_INPUT_METHOD) { |
| 1029 | RuntimeException e = null; |
| 1030 | if (!HIDE_STACK_CRAWLS) { |
| 1031 | e = new RuntimeException(); |
| 1032 | e.fillInStackTrace(); |
| 1033 | } |
| 1034 | Slog.w(TAG, "Moving IM target from " |
| 1035 | + mInputMethodTarget + " to " + w, e); |
| 1036 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | mInputMethodTarget = w; |
| 1038 | if (w.mAppToken != null) { |
| 1039 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1040 | } else { |
| 1041 | setInputMethodAnimLayerAdjustment(0); |
| 1042 | } |
| 1043 | } |
| 1044 | return i+1; |
| 1045 | } |
| 1046 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1047 | if (DEBUG_INPUT_METHOD) { |
| 1048 | RuntimeException e = null; |
| 1049 | if (!HIDE_STACK_CRAWLS) { |
| 1050 | e = new RuntimeException(); |
| 1051 | e.fillInStackTrace(); |
| 1052 | } |
| 1053 | Slog.w(TAG, "Moving IM target from " |
| 1054 | + mInputMethodTarget + " to null", e); |
| 1055 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | mInputMethodTarget = null; |
| 1057 | setInputMethodAnimLayerAdjustment(0); |
| 1058 | } |
| 1059 | return -1; |
| 1060 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1061 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1063 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1064 | if (pos >= 0) { |
| 1065 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1066 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1067 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | mWindows.add(pos, win); |
| 1069 | moveInputMethodDialogsLocked(pos+1); |
| 1070 | return; |
| 1071 | } |
| 1072 | win.mTargetAppToken = null; |
| 1073 | addWindowToListInOrderLocked(win, true); |
| 1074 | moveInputMethodDialogsLocked(pos); |
| 1075 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1076 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1078 | 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] | 1079 | mInputMethodAnimLayerAdjustment = adj; |
| 1080 | WindowState imw = mInputMethodWindow; |
| 1081 | if (imw != null) { |
| 1082 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1083 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | + " anim layer: " + imw.mAnimLayer); |
| 1085 | int wi = imw.mChildWindows.size(); |
| 1086 | while (wi > 0) { |
| 1087 | wi--; |
| 1088 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1089 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1090 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | + " anim layer: " + cw.mAnimLayer); |
| 1092 | } |
| 1093 | } |
| 1094 | int di = mInputMethodDialogs.size(); |
| 1095 | while (di > 0) { |
| 1096 | di --; |
| 1097 | imw = mInputMethodDialogs.get(di); |
| 1098 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1099 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | + " anim layer: " + imw.mAnimLayer); |
| 1101 | } |
| 1102 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1103 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1105 | int wpos = mWindows.indexOf(win); |
| 1106 | if (wpos >= 0) { |
| 1107 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1108 | 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] | 1109 | mWindows.remove(wpos); |
| 1110 | int NC = win.mChildWindows.size(); |
| 1111 | while (NC > 0) { |
| 1112 | NC--; |
| 1113 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1114 | int cpos = mWindows.indexOf(cw); |
| 1115 | if (cpos >= 0) { |
| 1116 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1117 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1118 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | mWindows.remove(cpos); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | return interestingPos; |
| 1124 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1125 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1127 | addWindowToListInOrderLocked(win, false); |
| 1128 | // This is a hack to get all of the child windows added as well |
| 1129 | // at the right position. Child windows should be rare and |
| 1130 | // this case should be rare, so it shouldn't be that big a deal. |
| 1131 | int wpos = mWindows.indexOf(win); |
| 1132 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1133 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1134 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | mWindows.remove(wpos); |
| 1136 | reAddWindowLocked(wpos, win); |
| 1137 | } |
| 1138 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | void logWindowList(String prefix) { |
| 1141 | int N = mWindows.size(); |
| 1142 | while (N > 0) { |
| 1143 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1144 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | } |
| 1146 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1147 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | void moveInputMethodDialogsLocked(int pos) { |
| 1149 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1150 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1152 | 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] | 1153 | for (int i=0; i<N; i++) { |
| 1154 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1155 | } |
| 1156 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1157 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | logWindowList(" "); |
| 1159 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1160 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | if (pos >= 0) { |
| 1162 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1163 | if (pos < mWindows.size()) { |
| 1164 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1165 | if (wp == mInputMethodWindow) { |
| 1166 | pos++; |
| 1167 | } |
| 1168 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1169 | 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] | 1170 | for (int i=0; i<N; i++) { |
| 1171 | WindowState win = dialogs.get(i); |
| 1172 | win.mTargetAppToken = targetAppToken; |
| 1173 | pos = reAddWindowLocked(pos, win); |
| 1174 | } |
| 1175 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1176 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | logWindowList(" "); |
| 1178 | } |
| 1179 | return; |
| 1180 | } |
| 1181 | for (int i=0; i<N; i++) { |
| 1182 | WindowState win = dialogs.get(i); |
| 1183 | win.mTargetAppToken = null; |
| 1184 | reAddWindowToListInOrderLocked(win); |
| 1185 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1186 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | logWindowList(" "); |
| 1188 | } |
| 1189 | } |
| 1190 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1193 | final WindowState imWin = mInputMethodWindow; |
| 1194 | final int DN = mInputMethodDialogs.size(); |
| 1195 | if (imWin == null && DN == 0) { |
| 1196 | return false; |
| 1197 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1198 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1199 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1200 | if (imPos >= 0) { |
| 1201 | // In this case, the input method windows are to be placed |
| 1202 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1203 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1204 | // First check to see if the input method windows are already |
| 1205 | // located here, and contiguous. |
| 1206 | final int N = mWindows.size(); |
| 1207 | WindowState firstImWin = imPos < N |
| 1208 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | // Figure out the actual input method window that should be |
| 1211 | // at the bottom of their stack. |
| 1212 | WindowState baseImWin = imWin != null |
| 1213 | ? imWin : mInputMethodDialogs.get(0); |
| 1214 | if (baseImWin.mChildWindows.size() > 0) { |
| 1215 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1216 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 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 | if (firstImWin == baseImWin) { |
| 1220 | // The windows haven't moved... but are they still contiguous? |
| 1221 | // First find the top IM window. |
| 1222 | int pos = imPos+1; |
| 1223 | while (pos < N) { |
| 1224 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1225 | break; |
| 1226 | } |
| 1227 | pos++; |
| 1228 | } |
| 1229 | pos++; |
| 1230 | // Now there should be no more input method windows above. |
| 1231 | while (pos < N) { |
| 1232 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1233 | break; |
| 1234 | } |
| 1235 | pos++; |
| 1236 | } |
| 1237 | if (pos >= N) { |
| 1238 | // All is good! |
| 1239 | return false; |
| 1240 | } |
| 1241 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1242 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | if (imWin != null) { |
| 1244 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1245 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | logWindowList(" "); |
| 1247 | } |
| 1248 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1249 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1250 | 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] | 1251 | logWindowList(" "); |
| 1252 | } |
| 1253 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1254 | reAddWindowLocked(imPos, imWin); |
| 1255 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1256 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | logWindowList(" "); |
| 1258 | } |
| 1259 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1260 | } else { |
| 1261 | moveInputMethodDialogsLocked(imPos); |
| 1262 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1263 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | } else { |
| 1265 | // In this case, the input method windows go in a fixed layer, |
| 1266 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1269 | 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] | 1270 | tmpRemoveWindowLocked(0, imWin); |
| 1271 | imWin.mTargetAppToken = null; |
| 1272 | reAddWindowToListInOrderLocked(imWin); |
| 1273 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1274 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | logWindowList(" "); |
| 1276 | } |
| 1277 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1278 | } else { |
| 1279 | moveInputMethodDialogsLocked(-1);; |
| 1280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | if (needAssignLayers) { |
| 1285 | assignLayersLocked(); |
| 1286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | return true; |
| 1289 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1290 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | void adjustInputMethodDialogsLocked() { |
| 1292 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1293 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1294 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1295 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1296 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1297 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1298 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1299 | ? wallpaperTarget.mAppToken.animation : null) |
| 1300 | + " upper=" + mUpperWallpaperTarget |
| 1301 | + " lower=" + mLowerWallpaperTarget); |
| 1302 | return (wallpaperTarget != null |
| 1303 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1304 | && wallpaperTarget.mAppToken.animation != null))) |
| 1305 | || mUpperWallpaperTarget != null |
| 1306 | || mLowerWallpaperTarget != null; |
| 1307 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1308 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1309 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1310 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1311 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1312 | int adjustWallpaperWindowsLocked() { |
| 1313 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1314 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1315 | final int dw = mDisplay.getWidth(); |
| 1316 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1317 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1318 | // First find top-most window that has asked to be on top of the |
| 1319 | // wallpaper; all wallpapers go behind it. |
| 1320 | final ArrayList localmWindows = mWindows; |
| 1321 | int N = localmWindows.size(); |
| 1322 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1323 | WindowState foundW = null; |
| 1324 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1325 | WindowState topCurW = null; |
| 1326 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1327 | int i = N; |
| 1328 | while (i > 0) { |
| 1329 | i--; |
| 1330 | w = (WindowState)localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1331 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1332 | if (topCurW == null) { |
| 1333 | topCurW = w; |
| 1334 | topCurI = i; |
| 1335 | } |
| 1336 | continue; |
| 1337 | } |
| 1338 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1339 | if (w.mAppToken != null) { |
| 1340 | // If this window's app token is hidden and not animating, |
| 1341 | // it is of no interest to us. |
| 1342 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1343 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1344 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1345 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1346 | continue; |
| 1347 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1348 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1349 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1350 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1351 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1352 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1353 | && (mWallpaperTarget == w |
| 1354 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1355 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1356 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1357 | foundW = w; |
| 1358 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1359 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1360 | && w.mAppToken.animation != null) |
| 1361 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1362 | // The current wallpaper target is animating, so we'll |
| 1363 | // look behind it for another possible target and figure |
| 1364 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1365 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1366 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1367 | continue; |
| 1368 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1369 | break; |
| 1370 | } |
| 1371 | } |
| 1372 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1373 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1374 | // If we are currently waiting for an app transition, and either |
| 1375 | // the current target or the next target are involved with it, |
| 1376 | // then hold off on doing anything with the wallpaper. |
| 1377 | // Note that we are checking here for just whether the target |
| 1378 | // is part of an app token... which is potentially overly aggressive |
| 1379 | // (the app token may not be involved in the transition), but good |
| 1380 | // enough (we'll just wait until whatever transition is pending |
| 1381 | // executes). |
| 1382 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1383 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1384 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1385 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1386 | } |
| 1387 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1388 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1389 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1390 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1391 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1392 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1393 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1394 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1395 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1396 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1397 | + " oldTarget: " + mWallpaperTarget); |
| 1398 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1399 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1400 | mLowerWallpaperTarget = null; |
| 1401 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1402 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1403 | WindowState oldW = mWallpaperTarget; |
| 1404 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1405 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1406 | // Now what is happening... if the current and new targets are |
| 1407 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1408 | if (foundW != null && oldW != null) { |
| 1409 | boolean oldAnim = oldW.mAnimation != null |
| 1410 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1411 | boolean foundAnim = foundW.mAnimation != null |
| 1412 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1413 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1414 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1415 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1416 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1417 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1418 | int oldI = localmWindows.indexOf(oldW); |
| 1419 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1420 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1421 | } |
| 1422 | if (oldI >= 0) { |
| 1423 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1424 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1425 | + "=" + oldW + "; new#" + foundI |
| 1426 | + "=" + foundW); |
| 1427 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1428 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1429 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1430 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1431 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1432 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1433 | } |
| 1434 | mWallpaperTarget = oldW; |
| 1435 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1436 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1437 | // Now set the upper and lower wallpaper targets |
| 1438 | // correctly, and make sure that we are positioning |
| 1439 | // the wallpaper below the lower. |
| 1440 | if (foundI > oldI) { |
| 1441 | // The new target is on top of the old one. |
| 1442 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1443 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1444 | } |
| 1445 | mUpperWallpaperTarget = foundW; |
| 1446 | mLowerWallpaperTarget = oldW; |
| 1447 | foundW = oldW; |
| 1448 | foundI = oldI; |
| 1449 | } else { |
| 1450 | // The new target is below the old one. |
| 1451 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1452 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1453 | } |
| 1454 | mUpperWallpaperTarget = oldW; |
| 1455 | mLowerWallpaperTarget = foundW; |
| 1456 | } |
| 1457 | } |
| 1458 | } |
| 1459 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1460 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1461 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1462 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1463 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1464 | || (mLowerWallpaperTarget.mAppToken != null |
| 1465 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1466 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1467 | || (mUpperWallpaperTarget.mAppToken != null |
| 1468 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1469 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1470 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1471 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1472 | } |
| 1473 | mLowerWallpaperTarget = null; |
| 1474 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1475 | } |
| 1476 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1477 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1478 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1479 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1480 | // The window is visible to the compositor... but is it visible |
| 1481 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1482 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1483 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1484 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1485 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1486 | // its layer adjustment. Only do this if we are not transfering |
| 1487 | // between two wallpaper targets. |
| 1488 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1489 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1490 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1491 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1492 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1493 | * TYPE_LAYER_MULTIPLIER |
| 1494 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1495 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1496 | // Now w is the window we are supposed to be behind... but we |
| 1497 | // 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] | 1498 | // AND any starting window associated with it, AND below the |
| 1499 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1500 | while (foundI > 0) { |
| 1501 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1502 | if (wb.mBaseLayer < maxLayer && |
| 1503 | wb.mAttachedWindow != foundW && |
| Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1504 | wb.mAttachedWindow != foundW.mAttachedWindow && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1505 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1506 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1507 | // This window is not related to the previous one in any |
| 1508 | // interesting way, so stop here. |
| 1509 | break; |
| 1510 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1511 | foundW = wb; |
| 1512 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1513 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1514 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1515 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1516 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1517 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1518 | if (foundW == null && topCurW != null) { |
| 1519 | // There is no wallpaper target, so it goes at the bottom. |
| 1520 | // We will assume it is the same place as last time, if known. |
| 1521 | foundW = topCurW; |
| 1522 | foundI = topCurI+1; |
| 1523 | } else { |
| 1524 | // Okay i is the position immediately above the wallpaper. Look at |
| 1525 | // what is below it for later. |
| 1526 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1527 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1528 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1529 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1530 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1531 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1532 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1533 | } |
| 1534 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1535 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1536 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1537 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1538 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1539 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1540 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1541 | // are correctly placed. |
| 1542 | int curTokenIndex = mWallpaperTokens.size(); |
| 1543 | while (curTokenIndex > 0) { |
| 1544 | curTokenIndex--; |
| 1545 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1546 | if (token.hidden == visible) { |
| 1547 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1548 | token.hidden = !visible; |
| 1549 | // Need to do a layout to ensure the wallpaper now has the |
| 1550 | // correct size. |
| 1551 | mLayoutNeeded = true; |
| 1552 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1553 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1554 | int curWallpaperIndex = token.windows.size(); |
| 1555 | while (curWallpaperIndex > 0) { |
| 1556 | curWallpaperIndex--; |
| 1557 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1558 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1559 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1560 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1561 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1562 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1563 | // First, make sure the client has the current visibility |
| 1564 | // state. |
| 1565 | if (wallpaper.mWallpaperVisible != visible) { |
| 1566 | wallpaper.mWallpaperVisible = visible; |
| 1567 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1568 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1569 | "Setting visibility of wallpaper " + wallpaper |
| 1570 | + ": " + visible); |
| 1571 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1572 | } catch (RemoteException e) { |
| 1573 | } |
| 1574 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1575 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1576 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1577 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1578 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1579 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1580 | // First, if this window is at the current index, then all |
| 1581 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1582 | if (wallpaper == foundW) { |
| 1583 | foundI--; |
| 1584 | foundW = foundI > 0 |
| 1585 | ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1586 | continue; |
| 1587 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1588 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1589 | // The window didn't match... the current wallpaper window, |
| 1590 | // wherever it is, is in the wrong place, so make sure it is |
| 1591 | // not in the list. |
| 1592 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1593 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1594 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1595 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1596 | localmWindows.remove(oldIndex); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1597 | if (oldIndex < foundI) { |
| 1598 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1599 | } |
| 1600 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1601 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1602 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1603 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1604 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1605 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1606 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1607 | localmWindows.add(foundI, wallpaper); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1608 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1609 | } |
| 1610 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1611 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1612 | return changed; |
| 1613 | } |
| 1614 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1615 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1616 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1617 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1618 | mWallpaperAnimLayerAdjustment = adj; |
| 1619 | int curTokenIndex = mWallpaperTokens.size(); |
| 1620 | while (curTokenIndex > 0) { |
| 1621 | curTokenIndex--; |
| 1622 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1623 | int curWallpaperIndex = token.windows.size(); |
| 1624 | while (curWallpaperIndex > 0) { |
| 1625 | curWallpaperIndex--; |
| 1626 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1627 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1628 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1629 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | } |
| 1633 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1634 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1635 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1636 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1637 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1638 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1639 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1640 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1641 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1642 | changed = wallpaperWin.mXOffset != offset; |
| 1643 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1644 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1645 | + wallpaperWin + " x: " + offset); |
| 1646 | wallpaperWin.mXOffset = offset; |
| 1647 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1648 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1649 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1650 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1651 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1652 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1653 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1654 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1655 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1656 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1657 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1658 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1659 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1660 | + wallpaperWin + " y: " + offset); |
| 1661 | changed = true; |
| 1662 | wallpaperWin.mYOffset = offset; |
| 1663 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1664 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1665 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1666 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1667 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1668 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1669 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1670 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1671 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1672 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1673 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1674 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1675 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1676 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1677 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1678 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1679 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1680 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1681 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1682 | if (mWaitingOnWallpaper != null) { |
| 1683 | long start = SystemClock.uptimeMillis(); |
| 1684 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1685 | < start) { |
| 1686 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1687 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1688 | "Waiting for offset complete..."); |
| 1689 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1690 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1691 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1692 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1693 | if ((start+WALLPAPER_TIMEOUT) |
| 1694 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1695 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1696 | + wallpaperWin); |
| 1697 | mLastWallpaperTimeoutTime = start; |
| 1698 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1699 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1700 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1701 | } |
| 1702 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1703 | } catch (RemoteException e) { |
| 1704 | } |
| 1705 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1706 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1707 | return changed; |
| 1708 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1709 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1710 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1711 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1712 | if (mWaitingOnWallpaper != null && |
| 1713 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1714 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1715 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1719 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1720 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1721 | final int dw = mDisplay.getWidth(); |
| 1722 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1723 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1724 | boolean changed = false; |
| 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 | WindowState target = mWallpaperTarget; |
| 1727 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1728 | if (target.mWallpaperX >= 0) { |
| 1729 | mLastWallpaperX = target.mWallpaperX; |
| 1730 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1731 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1732 | } |
| 1733 | if (target.mWallpaperY >= 0) { |
| 1734 | mLastWallpaperY = target.mWallpaperY; |
| 1735 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1736 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1737 | } |
| 1738 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1739 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1740 | int curTokenIndex = mWallpaperTokens.size(); |
| 1741 | while (curTokenIndex > 0) { |
| 1742 | curTokenIndex--; |
| 1743 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1744 | int curWallpaperIndex = token.windows.size(); |
| 1745 | while (curWallpaperIndex > 0) { |
| 1746 | curWallpaperIndex--; |
| 1747 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1748 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1749 | wallpaper.computeShownFrameLocked(); |
| 1750 | changed = true; |
| 1751 | // We only want to be synchronous with one wallpaper. |
| 1752 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1753 | } |
| 1754 | } |
| 1755 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1756 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1757 | return changed; |
| 1758 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1759 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1760 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1761 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1762 | final int dw = mDisplay.getWidth(); |
| 1763 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1764 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1765 | int curTokenIndex = mWallpaperTokens.size(); |
| 1766 | while (curTokenIndex > 0) { |
| 1767 | curTokenIndex--; |
| 1768 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1769 | if (token.hidden == visible) { |
| 1770 | token.hidden = !visible; |
| 1771 | // Need to do a layout to ensure the wallpaper now has the |
| 1772 | // correct size. |
| 1773 | mLayoutNeeded = true; |
| 1774 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1775 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1776 | int curWallpaperIndex = token.windows.size(); |
| 1777 | while (curWallpaperIndex > 0) { |
| 1778 | curWallpaperIndex--; |
| 1779 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1780 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1781 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1782 | } |
| 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 | if (wallpaper.mWallpaperVisible != visible) { |
| 1785 | wallpaper.mWallpaperVisible = visible; |
| 1786 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1787 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1788 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1789 | + ": " + visible); |
| 1790 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1791 | } catch (RemoteException e) { |
| 1792 | } |
| 1793 | } |
| 1794 | } |
| 1795 | } |
| 1796 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1797 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1798 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1799 | MotionEvent pointer, long eventTime) { |
| 1800 | int curTokenIndex = mWallpaperTokens.size(); |
| 1801 | while (curTokenIndex > 0) { |
| 1802 | curTokenIndex--; |
| 1803 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1804 | int curWallpaperIndex = token.windows.size(); |
| 1805 | while (curWallpaperIndex > 0) { |
| 1806 | curWallpaperIndex--; |
| 1807 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1808 | if ((wallpaper.mAttrs.flags & |
| 1809 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1810 | continue; |
| 1811 | } |
| 1812 | try { |
| 1813 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1814 | if (srcWin != null) { |
| 1815 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1816 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1817 | } else { |
| 1818 | ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top); |
| 1819 | } |
| 1820 | switch (pointer.getAction()) { |
| 1821 | case MotionEvent.ACTION_DOWN: |
| 1822 | mSendingPointersToWallpaper = true; |
| 1823 | break; |
| 1824 | case MotionEvent.ACTION_UP: |
| 1825 | mSendingPointersToWallpaper = false; |
| 1826 | break; |
| 1827 | } |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1828 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1829 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1830 | Slog.w(TAG, "Failure sending pointer to wallpaper", e); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1831 | } |
| 1832 | } |
| 1833 | } |
| 1834 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1835 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1836 | void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin, |
| 1837 | MotionEvent pointer, long eventTime, boolean skipped) { |
| 1838 | if (relWin != null) { |
| 1839 | mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top); |
| 1840 | } else { |
| 1841 | mPolicy.dispatchedPointerEventLw(pointer, 0, 0); |
| 1842 | } |
| 1843 | |
| 1844 | // If we sent an initial down to the wallpaper, then continue |
| 1845 | // sending events until the final up. |
| 1846 | if (mSendingPointersToWallpaper) { |
| 1847 | if (skipped) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1848 | Slog.i(TAG, "Sending skipped pointer to wallpaper!"); |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1849 | } |
| 1850 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1851 | |
| 1852 | // If we are on top of the wallpaper, then the wallpaper also |
| 1853 | // gets to see this movement. |
| 1854 | } else if (srcWin != null |
| 1855 | && pointer.getAction() == MotionEvent.ACTION_DOWN |
| 1856 | && mWallpaperTarget == srcWin |
| 1857 | && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 1858 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1859 | } |
| 1860 | } |
| 1861 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1862 | public int addWindow(Session session, IWindow client, |
| 1863 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1864 | Rect outContentInsets) { |
| 1865 | int res = mPolicy.checkAddPermission(attrs); |
| 1866 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1867 | return res; |
| 1868 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1869 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1870 | boolean reportNewConfig = false; |
| 1871 | WindowState attachedWindow = null; |
| 1872 | WindowState win = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1874 | synchronized(mWindowMap) { |
| 1875 | // Instantiating a Display requires talking with the simulator, |
| 1876 | // so don't do it until we know the system is mostly up and |
| 1877 | // running. |
| 1878 | if (mDisplay == null) { |
| 1879 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1880 | mDisplay = wm.getDefaultDisplay(); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 1881 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 1882 | mInitialDisplayHeight = mDisplay.getHeight(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | mQueue.setDisplay(mDisplay); |
| 1884 | reportNewConfig = true; |
| 1885 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1886 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1887 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1888 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1889 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1890 | } |
| 1891 | |
| 1892 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1893 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1895 | 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] | 1896 | + attrs.token + ". Aborting."); |
| 1897 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1898 | } |
| 1899 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1900 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1901 | 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] | 1902 | + attrs.token + ". Aborting."); |
| 1903 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | boolean addToken = false; |
| 1908 | WindowToken token = mTokenMap.get(attrs.token); |
| 1909 | if (token == null) { |
| 1910 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1911 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1912 | 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] | 1913 | + attrs.token + ". Aborting."); |
| 1914 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1915 | } |
| 1916 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1917 | 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] | 1918 | + attrs.token + ". Aborting."); |
| 1919 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1920 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1921 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1922 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1923 | + attrs.token + ". Aborting."); |
| 1924 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1925 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | token = new WindowToken(attrs.token, -1, false); |
| 1927 | addToken = true; |
| 1928 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1929 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1930 | AppWindowToken atoken = token.appWindowToken; |
| 1931 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1932 | 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] | 1933 | + token + ". Aborting."); |
| 1934 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1935 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1936 | 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] | 1937 | + token + ". Aborting."); |
| 1938 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1939 | } |
| 1940 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1941 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1942 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1944 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1945 | } |
| 1946 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1947 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1948 | 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] | 1949 | + attrs.token + ". Aborting."); |
| 1950 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1951 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1952 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1953 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1954 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1955 | + attrs.token + ". Aborting."); |
| 1956 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1957 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | win = new WindowState(session, client, token, |
| 1961 | attachedWindow, attrs, viewVisibility); |
| 1962 | if (win.mDeathRecipient == null) { |
| 1963 | // Client has apparently died, so there is no reason to |
| 1964 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1965 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1966 | + " that is dead, aborting."); |
| 1967 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1968 | } |
| 1969 | |
| 1970 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1971 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1972 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1973 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1974 | return res; |
| 1975 | } |
| 1976 | |
| 1977 | // From now on, no exceptions or errors allowed! |
| 1978 | |
| 1979 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1980 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | if (addToken) { |
| 1984 | mTokenMap.put(attrs.token, token); |
| 1985 | mTokenList.add(token); |
| 1986 | } |
| 1987 | win.attach(); |
| 1988 | mWindowMap.put(client.asBinder(), win); |
| 1989 | |
| 1990 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1991 | token.appWindowToken != null) { |
| 1992 | token.appWindowToken.startingWindow = win; |
| 1993 | } |
| 1994 | |
| 1995 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1998 | mInputMethodWindow = win; |
| 1999 | addInputMethodWindowToListLocked(win); |
| 2000 | imMayMove = false; |
| 2001 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2002 | mInputMethodDialogs.add(win); |
| 2003 | addWindowToListInOrderLocked(win, true); |
| 2004 | adjustInputMethodDialogsLocked(); |
| 2005 | imMayMove = false; |
| 2006 | } else { |
| 2007 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2008 | if (attrs.type == TYPE_WALLPAPER) { |
| 2009 | mLastWallpaperTimeoutTime = 0; |
| 2010 | adjustWallpaperWindowsLocked(); |
| 2011 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2012 | adjustWallpaperWindowsLocked(); |
| 2013 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | } |
| 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 | win.mEnterAnimationPending = true; |
| 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 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2020 | if (mInTouchMode) { |
| 2021 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2022 | } |
| 2023 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2024 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2025 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2026 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2027 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | if (win.canReceiveKeys()) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2029 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 2030 | == true) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2031 | imMayMove = false; |
| 2032 | } |
| 2033 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2034 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2035 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2036 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2038 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2039 | assignLayersLocked(); |
| 2040 | // Don't do layout here, the window must call |
| 2041 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2042 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | //dump(); |
| 2044 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2045 | if (focusChanged) { |
| 2046 | if (mCurrentFocus != null) { |
| 2047 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 2048 | } |
| 2049 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2050 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2051 | TAG, "New client " + client.asBinder() |
| 2052 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2053 | |
| 2054 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2055 | reportNewConfig = true; |
| 2056 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 2060 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 2061 | // identity anyway, so it's safe to just clear & restore around this whole |
| 2062 | // block. |
| 2063 | final long origId = Binder.clearCallingIdentity(); |
| 2064 | if (reportNewConfig) { |
| 2065 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | } |
| 2067 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2068 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2069 | return res; |
| 2070 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2071 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | public void removeWindow(Session session, IWindow client) { |
| 2073 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2074 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | if (win == null) { |
| 2076 | return; |
| 2077 | } |
| 2078 | removeWindowLocked(session, win); |
| 2079 | } |
| 2080 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | public void removeWindowLocked(Session session, WindowState win) { |
| 2083 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2084 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2085 | TAG, "Remove " + win + " client=" |
| 2086 | + Integer.toHexString(System.identityHashCode( |
| 2087 | win.mClient.asBinder())) |
| 2088 | + ", surface=" + win.mSurface); |
| 2089 | |
| 2090 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2091 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2092 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2093 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2094 | + " mExiting=" + win.mExiting |
| 2095 | + " isAnimating=" + win.isAnimating() |
| 2096 | + " app-animation=" |
| 2097 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2098 | + " inPendingTransaction=" |
| 2099 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2100 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2101 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2102 | boolean wasVisible = false; |
| 2103 | // First, see if we need to run an animation. If we do, we have |
| 2104 | // to hold off on removing the window until the animation is done. |
| 2105 | // If the display is frozen, just remove immediately, since the |
| 2106 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2107 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2108 | // If we are not currently running the exit animation, we |
| 2109 | // need to see about starting one. |
| 2110 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2113 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2114 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2115 | } |
| 2116 | // Try starting an animation. |
| 2117 | if (applyAnimationLocked(win, transit, false)) { |
| 2118 | win.mExiting = true; |
| 2119 | } |
| 2120 | } |
| 2121 | if (win.mExiting || win.isAnimating()) { |
| 2122 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2123 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | win.mExiting = true; |
| 2125 | win.mRemoveOnExit = true; |
| 2126 | mLayoutNeeded = true; |
| 2127 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2128 | performLayoutAndPlaceSurfacesLocked(); |
| 2129 | if (win.mAppToken != null) { |
| 2130 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2131 | } |
| 2132 | //dump(); |
| 2133 | Binder.restoreCallingIdentity(origId); |
| 2134 | return; |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | removeWindowInnerLocked(session, win); |
| 2139 | // Removing a visible window will effect the computed orientation |
| 2140 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2141 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2142 | != mForcedAppOrientation |
| 2143 | && updateOrientationFromAppTokensLocked()) { |
| 2144 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2145 | } |
| 2146 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2147 | Binder.restoreCallingIdentity(origId); |
| 2148 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2149 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 2151 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 2152 | KeyWaiter.RETURN_NOTHING); |
| Maciej Białka | 26824b7 | 2010-03-05 08:40:09 +0100 | [diff] [blame] | 2153 | mKeyWaiter.releaseMotionTarget(win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 2155 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2156 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2158 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | if (mInputMethodTarget == win) { |
| 2160 | moveInputMethodWindowsIfNeededLocked(false); |
| 2161 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2162 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2163 | if (false) { |
| 2164 | RuntimeException e = new RuntimeException("here"); |
| 2165 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2166 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2167 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2168 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | mPolicy.removeWindowLw(win); |
| 2170 | win.removeLocked(); |
| 2171 | |
| 2172 | mWindowMap.remove(win.mClient.asBinder()); |
| 2173 | mWindows.remove(win); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2174 | 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] | 2175 | |
| 2176 | if (mInputMethodWindow == win) { |
| 2177 | mInputMethodWindow = null; |
| 2178 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2179 | mInputMethodDialogs.remove(win); |
| 2180 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2181 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2182 | final WindowToken token = win.mToken; |
| 2183 | final AppWindowToken atoken = win.mAppToken; |
| 2184 | token.windows.remove(win); |
| 2185 | if (atoken != null) { |
| 2186 | atoken.allAppWindows.remove(win); |
| 2187 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2188 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2189 | TAG, "**** Removing window " + win + ": count=" |
| 2190 | + token.windows.size()); |
| 2191 | if (token.windows.size() == 0) { |
| 2192 | if (!token.explicit) { |
| 2193 | mTokenMap.remove(token.token); |
| 2194 | mTokenList.remove(token); |
| 2195 | } else if (atoken != null) { |
| 2196 | atoken.firstWindowDrawn = false; |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | if (atoken != null) { |
| 2201 | if (atoken.startingWindow == win) { |
| 2202 | atoken.startingWindow = null; |
| 2203 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2204 | // If this is the last window and we had requested a starting |
| 2205 | // transition window, well there is no point now. |
| 2206 | atoken.startingData = null; |
| 2207 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2208 | // If this is the last window except for a starting transition |
| 2209 | // window, we need to get rid of the starting transition. |
| 2210 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2211 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2212 | + ": no more real windows"); |
| 2213 | } |
| 2214 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2215 | mH.sendMessage(m); |
| 2216 | } |
| 2217 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2218 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2219 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2220 | mLastWallpaperTimeoutTime = 0; |
| 2221 | adjustWallpaperWindowsLocked(); |
| 2222 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2223 | adjustWallpaperWindowsLocked(); |
| 2224 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2226 | if (!mInLayout) { |
| 2227 | assignLayersLocked(); |
| 2228 | mLayoutNeeded = true; |
| 2229 | performLayoutAndPlaceSurfacesLocked(); |
| 2230 | if (win.mAppToken != null) { |
| 2231 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2232 | } |
| 2233 | } |
| 2234 | } |
| 2235 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2236 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2237 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2238 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2239 | if (where != null) { |
| 2240 | Slog.i(TAG, str, where); |
| 2241 | } else { |
| 2242 | Slog.i(TAG, str); |
| 2243 | } |
| 2244 | } |
| 2245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2247 | long origId = Binder.clearCallingIdentity(); |
| 2248 | try { |
| 2249 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2250 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2252 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | Surface.openTransaction(); |
| 2254 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2255 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2256 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2257 | w.mSurface.setTransparentRegionHint(region); |
| 2258 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2259 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | Surface.closeTransaction(); |
| 2261 | } |
| 2262 | } |
| 2263 | } |
| 2264 | } finally { |
| 2265 | Binder.restoreCallingIdentity(origId); |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2270 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | Rect visibleInsets) { |
| 2272 | long origId = Binder.clearCallingIdentity(); |
| 2273 | try { |
| 2274 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2275 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2276 | if (w != null) { |
| 2277 | w.mGivenInsetsPending = false; |
| 2278 | w.mGivenContentInsets.set(contentInsets); |
| 2279 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2280 | w.mTouchableInsets = touchableInsets; |
| 2281 | mLayoutNeeded = true; |
| 2282 | performLayoutAndPlaceSurfacesLocked(); |
| 2283 | } |
| 2284 | } |
| 2285 | } finally { |
| 2286 | Binder.restoreCallingIdentity(origId); |
| 2287 | } |
| 2288 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2289 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2291 | Rect outDisplayFrame) { |
| 2292 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2293 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | if (win == null) { |
| 2295 | outDisplayFrame.setEmpty(); |
| 2296 | return; |
| 2297 | } |
| 2298 | outDisplayFrame.set(win.mDisplayFrame); |
| 2299 | } |
| 2300 | } |
| 2301 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2302 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2303 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2304 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2305 | window.mWallpaperX = x; |
| 2306 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2307 | window.mWallpaperXStep = xStep; |
| 2308 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2309 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2310 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2314 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2315 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2316 | synchronized (mWindowMap) { |
| 2317 | if (mWaitingOnWallpaper != null && |
| 2318 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2319 | mWaitingOnWallpaper = null; |
| 2320 | mWindowMap.notifyAll(); |
| 2321 | } |
| 2322 | } |
| 2323 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2324 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2325 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2326 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2327 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2328 | || window == mUpperWallpaperTarget) { |
| 2329 | boolean doWait = sync; |
| 2330 | int curTokenIndex = mWallpaperTokens.size(); |
| 2331 | while (curTokenIndex > 0) { |
| 2332 | curTokenIndex--; |
| 2333 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2334 | int curWallpaperIndex = token.windows.size(); |
| 2335 | while (curWallpaperIndex > 0) { |
| 2336 | curWallpaperIndex--; |
| 2337 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2338 | try { |
| 2339 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2340 | x, y, z, extras, sync); |
| 2341 | // We only want to be synchronous with one wallpaper. |
| 2342 | sync = false; |
| 2343 | } catch (RemoteException e) { |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2347 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2348 | if (doWait) { |
| 2349 | // XXX Need to wait for result. |
| 2350 | } |
| 2351 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2352 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2353 | return null; |
| 2354 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2356 | public int relayoutWindow(Session session, IWindow client, |
| 2357 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2358 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2359 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2360 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | boolean displayed = false; |
| 2362 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2363 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2365 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2367 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | if (win == null) { |
| 2369 | return 0; |
| 2370 | } |
| 2371 | win.mRequestedWidth = requestedWidth; |
| 2372 | win.mRequestedHeight = requestedHeight; |
| 2373 | |
| 2374 | if (attrs != null) { |
| 2375 | mPolicy.adjustWindowParamsLw(attrs); |
| 2376 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2377 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2378 | int attrChanges = 0; |
| 2379 | int flagChanges = 0; |
| 2380 | if (attrs != null) { |
| 2381 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2382 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2383 | } |
| 2384 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2385 | 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] | 2386 | |
| 2387 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2388 | win.mAlpha = attrs.alpha; |
| 2389 | } |
| 2390 | |
| 2391 | final boolean scaledWindow = |
| 2392 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2393 | |
| 2394 | if (scaledWindow) { |
| 2395 | // requested{Width|Height} Surface's physical size |
| 2396 | // attrs.{width|height} Size on screen |
| 2397 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2398 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2399 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2400 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2401 | } else { |
| 2402 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | boolean imMayMove = (flagChanges&( |
| 2406 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2407 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2408 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2409 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2410 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2411 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2412 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2413 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2414 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2415 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | win.mRelayoutCalled = true; |
| 2417 | final int oldVisibility = win.mViewVisibility; |
| 2418 | win.mViewVisibility = viewVisibility; |
| 2419 | if (viewVisibility == View.VISIBLE && |
| 2420 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2421 | displayed = !win.isVisibleLw(); |
| 2422 | if (win.mExiting) { |
| 2423 | win.mExiting = false; |
| 2424 | win.mAnimation = null; |
| 2425 | } |
| 2426 | if (win.mDestroying) { |
| 2427 | win.mDestroying = false; |
| 2428 | mDestroySurface.remove(win); |
| 2429 | } |
| 2430 | if (oldVisibility == View.GONE) { |
| 2431 | win.mEnterAnimationPending = true; |
| 2432 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2433 | if (displayed) { |
| 2434 | if (win.mSurface != null && !win.mDrawPending |
| 2435 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2436 | && mPolicy.isScreenOn()) { |
| 2437 | applyEnterAnimationLocked(win); |
| 2438 | } |
| 2439 | if ((win.mAttrs.flags |
| 2440 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2441 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2442 | "Relayout window turning screen on: " + win); |
| 2443 | win.mTurnOnScreen = true; |
| 2444 | } |
| 2445 | int diff = 0; |
| 2446 | if (win.mConfiguration != mCurConfiguration |
| 2447 | && (win.mConfiguration == null |
| 2448 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2449 | win.mConfiguration = mCurConfiguration; |
| 2450 | if (DEBUG_CONFIGURATION) { |
| 2451 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2452 | + win.mConfiguration + " / 0x" |
| 2453 | + Integer.toHexString(diff)); |
| 2454 | } |
| 2455 | outConfig.setTo(mCurConfiguration); |
| 2456 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2457 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2459 | // To change the format, we need to re-build the surface. |
| 2460 | win.destroySurfaceLocked(); |
| 2461 | displayed = true; |
| 2462 | } |
| 2463 | try { |
| 2464 | Surface surface = win.createSurfaceLocked(); |
| 2465 | if (surface != null) { |
| 2466 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2467 | win.mReportDestroySurface = false; |
| 2468 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2469 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2470 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2471 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2472 | // For some reason there isn't a surface. Clear the |
| 2473 | // caller's object so they see the same state. |
| 2474 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2475 | } |
| 2476 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2477 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2478 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2479 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2480 | Binder.restoreCallingIdentity(origId); |
| 2481 | return 0; |
| 2482 | } |
| 2483 | if (displayed) { |
| 2484 | focusMayChange = true; |
| 2485 | } |
| 2486 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2487 | && mInputMethodWindow == null) { |
| 2488 | mInputMethodWindow = win; |
| 2489 | imMayMove = true; |
| 2490 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2491 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2492 | && win.mAppToken != null |
| 2493 | && win.mAppToken.startingWindow != null) { |
| 2494 | // Special handling of starting window over the base |
| 2495 | // window of the app: propagate lock screen flags to it, |
| 2496 | // to provide the correct semantics while starting. |
| 2497 | final int mask = |
| 2498 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2499 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2500 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2501 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2502 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2503 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | } else { |
| 2505 | win.mEnterAnimationPending = false; |
| 2506 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2507 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2508 | + ": mExiting=" + win.mExiting |
| 2509 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | // If we are not currently running the exit animation, we |
| 2511 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2512 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2513 | // Try starting an animation; if there isn't one, we |
| 2514 | // can destroy the surface right away. |
| 2515 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2516 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2517 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2518 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2519 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2520 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2521 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | win.mExiting = true; |
| 2523 | mKeyWaiter.finishedKey(session, client, true, |
| 2524 | KeyWaiter.RETURN_NOTHING); |
| 2525 | } else if (win.isAnimating()) { |
| 2526 | // Currently in a hide animation... turn this into |
| 2527 | // an exit. |
| 2528 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2529 | } else if (win == mWallpaperTarget) { |
| 2530 | // If the wallpaper is currently behind this |
| 2531 | // window, we need to change both of them inside |
| 2532 | // of a transaction to avoid artifacts. |
| 2533 | win.mExiting = true; |
| 2534 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | } else { |
| 2536 | if (mInputMethodWindow == win) { |
| 2537 | mInputMethodWindow = null; |
| 2538 | } |
| 2539 | win.destroySurfaceLocked(); |
| 2540 | } |
| 2541 | } |
| 2542 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2543 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2544 | if (win.mSurface == null || (win.getAttrs().flags |
| 2545 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2546 | || win.mSurfacePendingDestroy) { |
| 2547 | // We are being called from a local process, which |
| 2548 | // means outSurface holds its current surface. Ensure the |
| 2549 | // surface object is cleared, but we don't want it actually |
| 2550 | // destroyed at this point. |
| 2551 | win.mSurfacePendingDestroy = false; |
| 2552 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2553 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2554 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2555 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2556 | "Keeping surface, will report destroy: " + win); |
| 2557 | win.mReportDestroySurface = true; |
| 2558 | outSurface.copyFrom(win.mSurface); |
| 2559 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2560 | } |
| 2561 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | if (focusMayChange) { |
| 2563 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2564 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2565 | imMayMove = false; |
| 2566 | } |
| 2567 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2568 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2569 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2570 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2571 | // reassign them at this point if the IM window state gets shuffled |
| 2572 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2574 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2575 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2576 | // Little hack here -- we -should- be able to rely on the |
| 2577 | // function to return true if the IME has moved and needs |
| 2578 | // its layer recomputed. However, if the IME was hidden |
| 2579 | // and isn't actually moved in the list, its layer may be |
| 2580 | // 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] | 2581 | assignLayers = true; |
| 2582 | } |
| 2583 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2584 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2585 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2586 | assignLayers = true; |
| 2587 | } |
| 2588 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2589 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2590 | mLayoutNeeded = true; |
| 2591 | win.mGivenInsetsPending = insetsPending; |
| 2592 | if (assignLayers) { |
| 2593 | assignLayersLocked(); |
| 2594 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2595 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2596 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2597 | if (displayed && win.mIsWallpaper) { |
| 2598 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2599 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2600 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | if (win.mAppToken != null) { |
| 2602 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2603 | } |
| 2604 | outFrame.set(win.mFrame); |
| 2605 | outContentInsets.set(win.mContentInsets); |
| 2606 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2607 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2609 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | + ", requestedHeight=" + requestedHeight |
| 2611 | + ", viewVisibility=" + viewVisibility |
| 2612 | + "\nRelayout returning frame=" + outFrame |
| 2613 | + ", surface=" + outSurface); |
| 2614 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2615 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2616 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2617 | |
| 2618 | inTouchMode = mInTouchMode; |
| 2619 | } |
| 2620 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2621 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | sendNewConfiguration(); |
| 2623 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2626 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2628 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2629 | } |
| 2630 | |
| 2631 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2632 | final long origId = Binder.clearCallingIdentity(); |
| 2633 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2634 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2636 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2637 | adjustWallpaperWindowsLocked(); |
| 2638 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2639 | mLayoutNeeded = true; |
| 2640 | performLayoutAndPlaceSurfacesLocked(); |
| 2641 | } |
| 2642 | } |
| 2643 | Binder.restoreCallingIdentity(origId); |
| 2644 | } |
| 2645 | |
| 2646 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2647 | 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] | 2648 | + (lp != null ? lp.packageName : null) |
| 2649 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2650 | if (lp != null && lp.windowAnimations != 0) { |
| 2651 | // If this is a system resource, don't try to load it from the |
| 2652 | // application resources. It is nice to avoid loading application |
| 2653 | // resources if we can. |
| 2654 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2655 | int resId = lp.windowAnimations; |
| 2656 | if ((resId&0xFF000000) == 0x01000000) { |
| 2657 | packageName = "android"; |
| 2658 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2659 | 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] | 2660 | + packageName); |
| 2661 | return AttributeCache.instance().get(packageName, resId, |
| 2662 | com.android.internal.R.styleable.WindowAnimation); |
| 2663 | } |
| 2664 | return null; |
| 2665 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2666 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2667 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2668 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2669 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2670 | if (packageName != null) { |
| 2671 | if ((resId&0xFF000000) == 0x01000000) { |
| 2672 | packageName = "android"; |
| 2673 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2674 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2675 | + packageName); |
| 2676 | return AttributeCache.instance().get(packageName, resId, |
| 2677 | com.android.internal.R.styleable.WindowAnimation); |
| 2678 | } |
| 2679 | return null; |
| 2680 | } |
| 2681 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | private void applyEnterAnimationLocked(WindowState win) { |
| 2683 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2684 | if (win.mEnterAnimationPending) { |
| 2685 | win.mEnterAnimationPending = false; |
| 2686 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2687 | } |
| 2688 | |
| 2689 | applyAnimationLocked(win, transit, true); |
| 2690 | } |
| 2691 | |
| 2692 | private boolean applyAnimationLocked(WindowState win, |
| 2693 | int transit, boolean isEntrance) { |
| 2694 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2695 | // If we are trying to apply an animation, but already running |
| 2696 | // an animation of the same type, then just leave that one alone. |
| 2697 | return true; |
| 2698 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2699 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | // Only apply an animation if the display isn't frozen. If it is |
| 2701 | // frozen, there is no reason to animate and it can cause strange |
| 2702 | // artifacts when we unfreeze the display if some different animation |
| 2703 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2704 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2706 | int attr = -1; |
| 2707 | Animation a = null; |
| 2708 | if (anim != 0) { |
| 2709 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2710 | } else { |
| 2711 | switch (transit) { |
| 2712 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2713 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2714 | break; |
| 2715 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2716 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2717 | break; |
| 2718 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2719 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2720 | break; |
| 2721 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2722 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2723 | break; |
| 2724 | } |
| 2725 | if (attr >= 0) { |
| 2726 | a = loadAnimation(win.mAttrs, attr); |
| 2727 | } |
| 2728 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2729 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2731 | + " mAnimation=" + win.mAnimation |
| 2732 | + " isEntrance=" + isEntrance); |
| 2733 | if (a != null) { |
| 2734 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2735 | RuntimeException e = null; |
| 2736 | if (!HIDE_STACK_CRAWLS) { |
| 2737 | e = new RuntimeException(); |
| 2738 | e.fillInStackTrace(); |
| 2739 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2740 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2741 | } |
| 2742 | win.setAnimation(a); |
| 2743 | win.mAnimationIsEntrance = isEntrance; |
| 2744 | } |
| 2745 | } else { |
| 2746 | win.clearAnimation(); |
| 2747 | } |
| 2748 | |
| 2749 | return win.mAnimation != null; |
| 2750 | } |
| 2751 | |
| 2752 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2753 | int anim = 0; |
| 2754 | Context context = mContext; |
| 2755 | if (animAttr >= 0) { |
| 2756 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2757 | if (ent != null) { |
| 2758 | context = ent.context; |
| 2759 | anim = ent.array.getResourceId(animAttr, 0); |
| 2760 | } |
| 2761 | } |
| 2762 | if (anim != 0) { |
| 2763 | return AnimationUtils.loadAnimation(context, anim); |
| 2764 | } |
| 2765 | return null; |
| 2766 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2767 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2768 | private Animation loadAnimation(String packageName, int resId) { |
| 2769 | int anim = 0; |
| 2770 | Context context = mContext; |
| 2771 | if (resId >= 0) { |
| 2772 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2773 | if (ent != null) { |
| 2774 | context = ent.context; |
| 2775 | anim = resId; |
| 2776 | } |
| 2777 | } |
| 2778 | if (anim != 0) { |
| 2779 | return AnimationUtils.loadAnimation(context, anim); |
| 2780 | } |
| 2781 | return null; |
| 2782 | } |
| 2783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2784 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2785 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2786 | // Only apply an animation if the display isn't frozen. If it is |
| 2787 | // frozen, there is no reason to animate and it can cause strange |
| 2788 | // artifacts when we unfreeze the display if some different animation |
| 2789 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2790 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2791 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2792 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2793 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2794 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2795 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2796 | } else if (mNextAppTransitionPackage != null) { |
| 2797 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2798 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2799 | } else { |
| 2800 | int animAttr = 0; |
| 2801 | switch (transit) { |
| 2802 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2803 | animAttr = enter |
| 2804 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2805 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2806 | break; |
| 2807 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2808 | animAttr = enter |
| 2809 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2810 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2811 | break; |
| 2812 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2813 | animAttr = enter |
| 2814 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2815 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2816 | break; |
| 2817 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2818 | animAttr = enter |
| 2819 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2820 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2821 | break; |
| 2822 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2823 | animAttr = enter |
| 2824 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2825 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2826 | break; |
| 2827 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2828 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2829 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2830 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2831 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2832 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2833 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2834 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2835 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2836 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2837 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2838 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2839 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2840 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2841 | break; |
| 2842 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2843 | animAttr = enter |
| 2844 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2845 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2846 | break; |
| 2847 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2848 | animAttr = enter |
| 2849 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2850 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2851 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2852 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2853 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2854 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2855 | + " anim=" + a |
| 2856 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2857 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | if (a != null) { |
| 2860 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2861 | RuntimeException e = null; |
| 2862 | if (!HIDE_STACK_CRAWLS) { |
| 2863 | e = new RuntimeException(); |
| 2864 | e.fillInStackTrace(); |
| 2865 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2866 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | } |
| 2868 | wtoken.setAnimation(a); |
| 2869 | } |
| 2870 | } else { |
| 2871 | wtoken.clearAnimation(); |
| 2872 | } |
| 2873 | |
| 2874 | return wtoken.animation != null; |
| 2875 | } |
| 2876 | |
| 2877 | // ------------------------------------------------------------- |
| 2878 | // Application Window Tokens |
| 2879 | // ------------------------------------------------------------- |
| 2880 | |
| 2881 | public void validateAppTokens(List tokens) { |
| 2882 | int v = tokens.size()-1; |
| 2883 | int m = mAppTokens.size()-1; |
| 2884 | while (v >= 0 && m >= 0) { |
| 2885 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2886 | if (wtoken.removed) { |
| 2887 | m--; |
| 2888 | continue; |
| 2889 | } |
| 2890 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2891 | 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] | 2892 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2893 | } |
| 2894 | v--; |
| 2895 | m--; |
| 2896 | } |
| 2897 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2898 | 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] | 2899 | v--; |
| 2900 | } |
| 2901 | while (m >= 0) { |
| 2902 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2903 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2904 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | } |
| 2906 | m--; |
| 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | boolean checkCallingPermission(String permission, String func) { |
| 2911 | // Quick check: if the calling permission is me, it's all okay. |
| 2912 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2913 | return true; |
| 2914 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | if (mContext.checkCallingPermission(permission) |
| 2917 | == PackageManager.PERMISSION_GRANTED) { |
| 2918 | return true; |
| 2919 | } |
| 2920 | String msg = "Permission Denial: " + func + " from pid=" |
| 2921 | + Binder.getCallingPid() |
| 2922 | + ", uid=" + Binder.getCallingUid() |
| 2923 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2924 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | return false; |
| 2926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2929 | WindowToken wtoken = mTokenMap.get(token); |
| 2930 | if (wtoken == null) { |
| 2931 | return null; |
| 2932 | } |
| 2933 | return wtoken.appWindowToken; |
| 2934 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2935 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | public void addWindowToken(IBinder token, int type) { |
| 2937 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2938 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2939 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | synchronized(mWindowMap) { |
| 2943 | WindowToken wtoken = mTokenMap.get(token); |
| 2944 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2945 | 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] | 2946 | return; |
| 2947 | } |
| 2948 | wtoken = new WindowToken(token, type, true); |
| 2949 | mTokenMap.put(token, wtoken); |
| 2950 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2951 | if (type == TYPE_WALLPAPER) { |
| 2952 | mWallpaperTokens.add(wtoken); |
| 2953 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2954 | } |
| 2955 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2956 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | public void removeWindowToken(IBinder token) { |
| 2958 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2959 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2960 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | final long origId = Binder.clearCallingIdentity(); |
| 2964 | synchronized(mWindowMap) { |
| 2965 | WindowToken wtoken = mTokenMap.remove(token); |
| 2966 | mTokenList.remove(wtoken); |
| 2967 | if (wtoken != null) { |
| 2968 | boolean delayed = false; |
| 2969 | if (!wtoken.hidden) { |
| 2970 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2971 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | final int N = wtoken.windows.size(); |
| 2973 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | for (int i=0; i<N; i++) { |
| 2976 | WindowState win = wtoken.windows.get(i); |
| 2977 | |
| 2978 | if (win.isAnimating()) { |
| 2979 | delayed = true; |
| 2980 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2981 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | if (win.isVisibleNow()) { |
| 2983 | applyAnimationLocked(win, |
| 2984 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2985 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2986 | KeyWaiter.RETURN_NOTHING); |
| 2987 | changed = true; |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | if (changed) { |
| 2992 | mLayoutNeeded = true; |
| 2993 | performLayoutAndPlaceSurfacesLocked(); |
| 2994 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2995 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2997 | if (delayed) { |
| 2998 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2999 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3000 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | } |
| 3002 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3003 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3005 | 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] | 3006 | } |
| 3007 | } |
| 3008 | Binder.restoreCallingIdentity(origId); |
| 3009 | } |
| 3010 | |
| 3011 | public void addAppToken(int addPos, IApplicationToken token, |
| 3012 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3013 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3014 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3015 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3018 | synchronized(mWindowMap) { |
| 3019 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3020 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3021 | 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] | 3022 | return; |
| 3023 | } |
| 3024 | wtoken = new AppWindowToken(token); |
| 3025 | wtoken.groupId = groupId; |
| 3026 | wtoken.appFullscreen = fullscreen; |
| 3027 | wtoken.requestedOrientation = requestedOrientation; |
| 3028 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3029 | 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] | 3030 | mTokenMap.put(token.asBinder(), wtoken); |
| 3031 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3032 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | // Application tokens start out hidden. |
| 3034 | wtoken.hidden = true; |
| 3035 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3037 | //dump(); |
| 3038 | } |
| 3039 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | public void setAppGroupId(IBinder token, int groupId) { |
| 3042 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3043 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3044 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | synchronized(mWindowMap) { |
| 3048 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3049 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3050 | 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] | 3051 | return; |
| 3052 | } |
| 3053 | wtoken.groupId = groupId; |
| 3054 | } |
| 3055 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | public int getOrientationFromWindowsLocked() { |
| 3058 | int pos = mWindows.size() - 1; |
| 3059 | while (pos >= 0) { |
| 3060 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 3061 | pos--; |
| 3062 | if (wtoken.mAppToken != null) { |
| 3063 | // We hit an application window. so the orientation will be determined by the |
| 3064 | // app window. No point in continuing further. |
| 3065 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3066 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3067 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3068 | continue; |
| 3069 | } |
| 3070 | int req = wtoken.mAttrs.screenOrientation; |
| 3071 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3072 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3073 | continue; |
| 3074 | } else { |
| 3075 | return req; |
| 3076 | } |
| 3077 | } |
| 3078 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3079 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3080 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3082 | int pos = mAppTokens.size() - 1; |
| 3083 | int curGroup = 0; |
| 3084 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3085 | boolean findingBehind = false; |
| 3086 | boolean haveGroup = false; |
| 3087 | boolean lastFullscreen = false; |
| 3088 | while (pos >= 0) { |
| 3089 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3090 | pos--; |
| 3091 | // if we're about to tear down this window and not seek for |
| 3092 | // the behind activity, don't use it for orientation |
| 3093 | if (!findingBehind |
| 3094 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3095 | continue; |
| 3096 | } |
| 3097 | |
| 3098 | if (!haveGroup) { |
| 3099 | // We ignore any hidden applications on the top. |
| 3100 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3101 | continue; |
| 3102 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3103 | haveGroup = true; |
| 3104 | curGroup = wtoken.groupId; |
| 3105 | lastOrientation = wtoken.requestedOrientation; |
| 3106 | } else if (curGroup != wtoken.groupId) { |
| 3107 | // If we have hit a new application group, and the bottom |
| 3108 | // of the previous group didn't explicitly say to use |
| 3109 | // the orientation behind it, and the last app was |
| 3110 | // full screen, then we'll stick with the |
| 3111 | // user's orientation. |
| 3112 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3113 | && lastFullscreen) { |
| 3114 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3116 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3117 | int or = wtoken.requestedOrientation; |
| 3118 | // If this application is fullscreen, and didn't explicitly say |
| 3119 | // to use the orientation behind it, then just take whatever |
| 3120 | // orientation it has and ignores whatever is under it. |
| 3121 | lastFullscreen = wtoken.appFullscreen; |
| 3122 | if (lastFullscreen |
| 3123 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3124 | return or; |
| 3125 | } |
| 3126 | // If this application has requested an explicit orientation, |
| 3127 | // then use it. |
| 3128 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3129 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3130 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3131 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3132 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3133 | return or; |
| 3134 | } |
| 3135 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3136 | } |
| 3137 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3141 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3142 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3143 | "updateOrientationFromAppTokens()")) { |
| 3144 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3145 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3146 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3147 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3149 | |
| 3150 | synchronized(mWindowMap) { |
| 3151 | if (updateOrientationFromAppTokensLocked()) { |
| 3152 | if (freezeThisOneIfNeeded != null) { |
| 3153 | AppWindowToken wtoken = findAppWindowToken( |
| 3154 | freezeThisOneIfNeeded); |
| 3155 | if (wtoken != null) { |
| 3156 | startAppFreezingScreenLocked(wtoken, |
| 3157 | ActivityInfo.CONFIG_ORIENTATION); |
| 3158 | } |
| 3159 | } |
| 3160 | config = computeNewConfigurationLocked(); |
| 3161 | |
| 3162 | } else if (currentConfig != null) { |
| 3163 | // No obvious action we need to take, but if our current |
| 3164 | // state mismatches the activity maanager's, update it |
| 3165 | mTempConfiguration.setToDefaults(); |
| 3166 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3167 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3168 | mWaitingForConfig = true; |
| 3169 | mLayoutNeeded = true; |
| 3170 | startFreezingDisplayLocked(); |
| 3171 | config = new Configuration(mTempConfiguration); |
| 3172 | } |
| 3173 | } |
| 3174 | } |
| 3175 | } |
| 3176 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3177 | Binder.restoreCallingIdentity(ident); |
| 3178 | return config; |
| 3179 | } |
| 3180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3181 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3182 | * Determine the new desired orientation of the display, returning |
| 3183 | * a non-null new Configuration if it has changed from the current |
| 3184 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3185 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3186 | * SCREEN. This will typically be done for you if you call |
| 3187 | * sendNewConfiguration(). |
| 3188 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3189 | * The orientation is computed from non-application windows first. If none of |
| 3190 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3191 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3192 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3193 | * android.os.IBinder) |
| 3194 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3195 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3196 | if (mDisplayFrozen) { |
| 3197 | // If the display is frozen, some activities may be in the middle |
| 3198 | // of restarting, and thus have removed their old window. If the |
| 3199 | // window has the flag to hide the lock screen, then the lock screen |
| 3200 | // can re-appear and inflict its own orientation on us. Keep the |
| 3201 | // orientation stable until this all settles down. |
| 3202 | return false; |
| 3203 | } |
| 3204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3205 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | long ident = Binder.clearCallingIdentity(); |
| 3207 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3208 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | mForcedAppOrientation = req; |
| 3212 | //send a message to Policy indicating orientation change to take |
| 3213 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3214 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3215 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3216 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3217 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | } |
| 3219 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3220 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3221 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | } finally { |
| 3223 | Binder.restoreCallingIdentity(ident); |
| 3224 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3226 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3227 | int computeForcedAppOrientationLocked() { |
| 3228 | int req = getOrientationFromWindowsLocked(); |
| 3229 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3230 | req = getOrientationFromAppTokensLocked(); |
| 3231 | } |
| 3232 | return req; |
| 3233 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3234 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3235 | public void setNewConfiguration(Configuration config) { |
| 3236 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3237 | "setNewConfiguration()")) { |
| 3238 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3239 | } |
| 3240 | |
| 3241 | synchronized(mWindowMap) { |
| 3242 | mCurConfiguration = new Configuration(config); |
| 3243 | mWaitingForConfig = false; |
| 3244 | performLayoutAndPlaceSurfacesLocked(); |
| 3245 | } |
| 3246 | } |
| 3247 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3248 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3249 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3250 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3251 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | synchronized(mWindowMap) { |
| 3255 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3256 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3257 | 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] | 3258 | return; |
| 3259 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3260 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | wtoken.requestedOrientation = requestedOrientation; |
| 3262 | } |
| 3263 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3264 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | public int getAppOrientation(IApplicationToken token) { |
| 3266 | synchronized(mWindowMap) { |
| 3267 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3268 | if (wtoken == null) { |
| 3269 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3270 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3271 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3272 | return wtoken.requestedOrientation; |
| 3273 | } |
| 3274 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3277 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3278 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3279 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | synchronized(mWindowMap) { |
| 3283 | boolean changed = false; |
| 3284 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3285 | 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] | 3286 | changed = mFocusedApp != null; |
| 3287 | mFocusedApp = null; |
| 3288 | mKeyWaiter.tickle(); |
| 3289 | } else { |
| 3290 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3291 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3292 | 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] | 3293 | return; |
| 3294 | } |
| 3295 | changed = mFocusedApp != newFocus; |
| 3296 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3297 | 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] | 3298 | mKeyWaiter.tickle(); |
| 3299 | } |
| 3300 | |
| 3301 | if (moveFocusNow && changed) { |
| 3302 | final long origId = Binder.clearCallingIdentity(); |
| 3303 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3304 | Binder.restoreCallingIdentity(origId); |
| 3305 | } |
| 3306 | } |
| 3307 | } |
| 3308 | |
| 3309 | public void prepareAppTransition(int transit) { |
| 3310 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3311 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3312 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3313 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3314 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3316 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3317 | TAG, "Prepare app transition: transit=" + transit |
| 3318 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3319 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3320 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3321 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3323 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3324 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3325 | // Opening a new task always supersedes a close for the anim. |
| 3326 | mNextAppTransition = transit; |
| 3327 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3328 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3329 | // Opening a new activity always supersedes a close for the anim. |
| 3330 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3331 | } |
| 3332 | mAppTransitionReady = false; |
| 3333 | mAppTransitionTimeout = false; |
| 3334 | mStartingIconInTransition = false; |
| 3335 | mSkipAppTransitionAnimation = false; |
| 3336 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3337 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3338 | 5000); |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | public int getPendingAppTransition() { |
| 3344 | return mNextAppTransition; |
| 3345 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3346 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3347 | public void overridePendingAppTransition(String packageName, |
| 3348 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3349 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3350 | mNextAppTransitionPackage = packageName; |
| 3351 | mNextAppTransitionEnter = enterAnim; |
| 3352 | mNextAppTransitionExit = exitAnim; |
| 3353 | } |
| 3354 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | public void executeAppTransition() { |
| 3357 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3358 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3359 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3361 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3362 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3363 | if (DEBUG_APP_TRANSITIONS) { |
| 3364 | RuntimeException e = new RuntimeException("here"); |
| 3365 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3366 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3367 | + mNextAppTransition, e); |
| 3368 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3369 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | mAppTransitionReady = true; |
| 3371 | final long origId = Binder.clearCallingIdentity(); |
| 3372 | performLayoutAndPlaceSurfacesLocked(); |
| 3373 | Binder.restoreCallingIdentity(origId); |
| 3374 | } |
| 3375 | } |
| 3376 | } |
| 3377 | |
| 3378 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3379 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3380 | IBinder transferFrom, boolean createIfNeeded) { |
| 3381 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3382 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3383 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3387 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3388 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3389 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3390 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3391 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3392 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3393 | 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] | 3394 | return; |
| 3395 | } |
| 3396 | |
| 3397 | // If the display is frozen, we won't do anything until the |
| 3398 | // actual window is displayed so there is no reason to put in |
| 3399 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3400 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3401 | return; |
| 3402 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | if (wtoken.startingData != null) { |
| 3405 | return; |
| 3406 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3407 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | if (transferFrom != null) { |
| 3409 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3410 | if (ttoken != null) { |
| 3411 | WindowState startingWindow = ttoken.startingWindow; |
| 3412 | if (startingWindow != null) { |
| 3413 | if (mStartingIconInTransition) { |
| 3414 | // In this case, the starting icon has already |
| 3415 | // been displayed, so start letting windows get |
| 3416 | // shown immediately without any more transitions. |
| 3417 | mSkipAppTransitionAnimation = true; |
| 3418 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3419 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3420 | "Moving existing starting from " + ttoken |
| 3421 | + " to " + wtoken); |
| 3422 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3423 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3424 | // Transfer the starting window over to the new |
| 3425 | // token. |
| 3426 | wtoken.startingData = ttoken.startingData; |
| 3427 | wtoken.startingView = ttoken.startingView; |
| 3428 | wtoken.startingWindow = startingWindow; |
| 3429 | ttoken.startingData = null; |
| 3430 | ttoken.startingView = null; |
| 3431 | ttoken.startingWindow = null; |
| 3432 | ttoken.startingMoved = true; |
| 3433 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3434 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3436 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3437 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3438 | mWindows.remove(startingWindow); |
| 3439 | ttoken.windows.remove(startingWindow); |
| 3440 | ttoken.allAppWindows.remove(startingWindow); |
| 3441 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3443 | // Propagate other interesting state between the |
| 3444 | // tokens. If the old token is displayed, we should |
| 3445 | // immediately force the new one to be displayed. If |
| 3446 | // it is animating, we need to move that animation to |
| 3447 | // the new one. |
| 3448 | if (ttoken.allDrawn) { |
| 3449 | wtoken.allDrawn = true; |
| 3450 | } |
| 3451 | if (ttoken.firstWindowDrawn) { |
| 3452 | wtoken.firstWindowDrawn = true; |
| 3453 | } |
| 3454 | if (!ttoken.hidden) { |
| 3455 | wtoken.hidden = false; |
| 3456 | wtoken.hiddenRequested = false; |
| 3457 | wtoken.willBeHidden = false; |
| 3458 | } |
| 3459 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3460 | wtoken.clientHidden = ttoken.clientHidden; |
| 3461 | wtoken.sendAppVisibilityToClients(); |
| 3462 | } |
| 3463 | if (ttoken.animation != null) { |
| 3464 | wtoken.animation = ttoken.animation; |
| 3465 | wtoken.animating = ttoken.animating; |
| 3466 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3467 | ttoken.animation = null; |
| 3468 | ttoken.animLayerAdjustment = 0; |
| 3469 | wtoken.updateLayers(); |
| 3470 | ttoken.updateLayers(); |
| 3471 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3474 | mLayoutNeeded = true; |
| 3475 | performLayoutAndPlaceSurfacesLocked(); |
| 3476 | Binder.restoreCallingIdentity(origId); |
| 3477 | return; |
| 3478 | } else if (ttoken.startingData != null) { |
| 3479 | // The previous app was getting ready to show a |
| 3480 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3481 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3482 | "Moving pending starting from " + ttoken |
| 3483 | + " to " + wtoken); |
| 3484 | wtoken.startingData = ttoken.startingData; |
| 3485 | ttoken.startingData = null; |
| 3486 | ttoken.startingMoved = true; |
| 3487 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3488 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3489 | // want to process the message ASAP, before any other queued |
| 3490 | // messages. |
| 3491 | mH.sendMessageAtFrontOfQueue(m); |
| 3492 | return; |
| 3493 | } |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | // There is no existing starting window, and the caller doesn't |
| 3498 | // want us to create one, so that's it! |
| 3499 | if (!createIfNeeded) { |
| 3500 | return; |
| 3501 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3502 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3503 | // If this is a translucent or wallpaper window, then don't |
| 3504 | // show a starting window -- the current effect (a full-screen |
| 3505 | // opaque starting window that fades away to the real contents |
| 3506 | // when it is ready) does not work for this. |
| 3507 | if (theme != 0) { |
| 3508 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3509 | com.android.internal.R.styleable.Window); |
| 3510 | if (ent.array.getBoolean( |
| 3511 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3512 | return; |
| 3513 | } |
| 3514 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3515 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3516 | return; |
| 3517 | } |
| 3518 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3519 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3520 | return; |
| 3521 | } |
| 3522 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3523 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3524 | mStartingIconInTransition = true; |
| 3525 | wtoken.startingData = new StartingData( |
| 3526 | pkg, theme, nonLocalizedLabel, |
| 3527 | labelRes, icon); |
| 3528 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3529 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3530 | // want to process the message ASAP, before any other queued |
| 3531 | // messages. |
| 3532 | mH.sendMessageAtFrontOfQueue(m); |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | public void setAppWillBeHidden(IBinder token) { |
| 3537 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3538 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3539 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | AppWindowToken wtoken; |
| 3543 | |
| 3544 | synchronized(mWindowMap) { |
| 3545 | wtoken = findAppWindowToken(token); |
| 3546 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3547 | 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] | 3548 | return; |
| 3549 | } |
| 3550 | wtoken.willBeHidden = true; |
| 3551 | } |
| 3552 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3555 | boolean visible, int transit, boolean performLayout) { |
| 3556 | boolean delayed = false; |
| 3557 | |
| 3558 | if (wtoken.clientHidden == visible) { |
| 3559 | wtoken.clientHidden = !visible; |
| 3560 | wtoken.sendAppVisibilityToClients(); |
| 3561 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3562 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3563 | wtoken.willBeHidden = false; |
| 3564 | if (wtoken.hidden == visible) { |
| 3565 | final int N = wtoken.allAppWindows.size(); |
| 3566 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3567 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3569 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3571 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3572 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3573 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3574 | if (wtoken.animation == sDummyAnimation) { |
| 3575 | wtoken.animation = null; |
| 3576 | } |
| 3577 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3578 | changed = true; |
| 3579 | if (wtoken.animation != null) { |
| 3580 | delayed = runningAppAnimation = true; |
| 3581 | } |
| 3582 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3583 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3584 | for (int i=0; i<N; i++) { |
| 3585 | WindowState win = wtoken.allAppWindows.get(i); |
| 3586 | if (win == wtoken.startingWindow) { |
| 3587 | continue; |
| 3588 | } |
| 3589 | |
| 3590 | if (win.isAnimating()) { |
| 3591 | delayed = true; |
| 3592 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3593 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3594 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3595 | //win.dump(" "); |
| 3596 | if (visible) { |
| 3597 | if (!win.isVisibleNow()) { |
| 3598 | if (!runningAppAnimation) { |
| 3599 | applyAnimationLocked(win, |
| 3600 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3601 | } |
| 3602 | changed = true; |
| 3603 | } |
| 3604 | } else if (win.isVisibleNow()) { |
| 3605 | if (!runningAppAnimation) { |
| 3606 | applyAnimationLocked(win, |
| 3607 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3608 | } |
| 3609 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3610 | KeyWaiter.RETURN_NOTHING); |
| 3611 | changed = true; |
| 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3616 | if (!visible) { |
| 3617 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3618 | } else { |
| 3619 | // If we are being set visible, and the starting window is |
| 3620 | // not yet displayed, then make sure it doesn't get displayed. |
| 3621 | WindowState swin = wtoken.startingWindow; |
| 3622 | if (swin != null && (swin.mDrawPending |
| 3623 | || swin.mCommitDrawPending)) { |
| 3624 | swin.mPolicyVisibility = false; |
| 3625 | swin.mPolicyVisibilityAfterAnim = false; |
| 3626 | } |
| 3627 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3628 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3629 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3631 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3632 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3633 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3634 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3635 | if (performLayout) { |
| 3636 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3637 | performLayoutAndPlaceSurfacesLocked(); |
| 3638 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | if (wtoken.animation != null) { |
| 3643 | delayed = true; |
| 3644 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3646 | return delayed; |
| 3647 | } |
| 3648 | |
| 3649 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3650 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3651 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3652 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | AppWindowToken wtoken; |
| 3656 | |
| 3657 | synchronized(mWindowMap) { |
| 3658 | wtoken = findAppWindowToken(token); |
| 3659 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3660 | 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] | 3661 | return; |
| 3662 | } |
| 3663 | |
| 3664 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3665 | RuntimeException e = null; |
| 3666 | if (!HIDE_STACK_CRAWLS) { |
| 3667 | e = new RuntimeException(); |
| 3668 | e.fillInStackTrace(); |
| 3669 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3670 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | + "): mNextAppTransition=" + mNextAppTransition |
| 3672 | + " hidden=" + wtoken.hidden |
| 3673 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3674 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3675 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | // If we are preparing an app transition, then delay changing |
| 3677 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3678 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3679 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | // Already in requested state, don't do anything more. |
| 3681 | if (wtoken.hiddenRequested != visible) { |
| 3682 | return; |
| 3683 | } |
| 3684 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3685 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3686 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | TAG, "Setting dummy animation on: " + wtoken); |
| 3688 | wtoken.setDummyAnimation(); |
| 3689 | mOpeningApps.remove(wtoken); |
| 3690 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3691 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3692 | wtoken.inPendingTransaction = true; |
| 3693 | if (visible) { |
| 3694 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | wtoken.startingDisplayed = false; |
| 3696 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3697 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3698 | // If the token is currently hidden (should be the |
| 3699 | // common case), then we need to set up to wait for |
| 3700 | // its windows to be ready. |
| 3701 | if (wtoken.hidden) { |
| 3702 | wtoken.allDrawn = false; |
| 3703 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3704 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3705 | if (wtoken.clientHidden) { |
| 3706 | // In the case where we are making an app visible |
| 3707 | // but holding off for a transition, we still need |
| 3708 | // to tell the client to make its windows visible so |
| 3709 | // they get drawn. Otherwise, we will wait on |
| 3710 | // performing the transition until all windows have |
| 3711 | // been drawn, they never will be, and we are sad. |
| 3712 | wtoken.clientHidden = false; |
| 3713 | wtoken.sendAppVisibilityToClients(); |
| 3714 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | } |
| 3716 | } else { |
| 3717 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3718 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3719 | // If the token is currently visible (should be the |
| 3720 | // common case), then set up to wait for it to be hidden. |
| 3721 | if (!wtoken.hidden) { |
| 3722 | wtoken.waitingToHide = true; |
| 3723 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3724 | } |
| 3725 | return; |
| 3726 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3727 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3729 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | wtoken.updateReportedVisibilityLocked(); |
| 3731 | Binder.restoreCallingIdentity(origId); |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3736 | boolean unfreezeSurfaceNow, boolean force) { |
| 3737 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3738 | 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] | 3739 | + " force=" + force); |
| 3740 | final int N = wtoken.allAppWindows.size(); |
| 3741 | boolean unfrozeWindows = false; |
| 3742 | for (int i=0; i<N; i++) { |
| 3743 | WindowState w = wtoken.allAppWindows.get(i); |
| 3744 | if (w.mAppFreezing) { |
| 3745 | w.mAppFreezing = false; |
| 3746 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3747 | w.mOrientationChanging = true; |
| 3748 | } |
| 3749 | unfrozeWindows = true; |
| 3750 | } |
| 3751 | } |
| 3752 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3753 | 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] | 3754 | wtoken.freezingScreen = false; |
| 3755 | mAppsFreezingScreen--; |
| 3756 | } |
| 3757 | if (unfreezeSurfaceNow) { |
| 3758 | if (unfrozeWindows) { |
| 3759 | mLayoutNeeded = true; |
| 3760 | performLayoutAndPlaceSurfacesLocked(); |
| 3761 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3762 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3763 | } |
| 3764 | } |
| 3765 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3768 | int configChanges) { |
| 3769 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3770 | RuntimeException e = null; |
| 3771 | if (!HIDE_STACK_CRAWLS) { |
| 3772 | e = new RuntimeException(); |
| 3773 | e.fillInStackTrace(); |
| 3774 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3775 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3777 | + wtoken.freezingScreen, e); |
| 3778 | } |
| 3779 | if (!wtoken.hiddenRequested) { |
| 3780 | if (!wtoken.freezingScreen) { |
| 3781 | wtoken.freezingScreen = true; |
| 3782 | mAppsFreezingScreen++; |
| 3783 | if (mAppsFreezingScreen == 1) { |
| 3784 | startFreezingDisplayLocked(); |
| 3785 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3786 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3787 | 5000); |
| 3788 | } |
| 3789 | } |
| 3790 | final int N = wtoken.allAppWindows.size(); |
| 3791 | for (int i=0; i<N; i++) { |
| 3792 | WindowState w = wtoken.allAppWindows.get(i); |
| 3793 | w.mAppFreezing = true; |
| 3794 | } |
| 3795 | } |
| 3796 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3797 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3798 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3799 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3800 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3801 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3805 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3806 | 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] | 3807 | return; |
| 3808 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3809 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3811 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3812 | 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] | 3813 | return; |
| 3814 | } |
| 3815 | final long origId = Binder.clearCallingIdentity(); |
| 3816 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3817 | Binder.restoreCallingIdentity(origId); |
| 3818 | } |
| 3819 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3820 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3822 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3823 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3824 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | synchronized(mWindowMap) { |
| 3828 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3829 | if (wtoken == null || wtoken.appToken == null) { |
| 3830 | return; |
| 3831 | } |
| 3832 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3833 | 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] | 3834 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3835 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3836 | Binder.restoreCallingIdentity(origId); |
| 3837 | } |
| 3838 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3840 | public void removeAppToken(IBinder token) { |
| 3841 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3842 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3843 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | } |
| 3845 | |
| 3846 | AppWindowToken wtoken = null; |
| 3847 | AppWindowToken startingToken = null; |
| 3848 | boolean delayed = false; |
| 3849 | |
| 3850 | final long origId = Binder.clearCallingIdentity(); |
| 3851 | synchronized(mWindowMap) { |
| 3852 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3853 | mTokenList.remove(basewtoken); |
| 3854 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3855 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3856 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3857 | wtoken.inPendingTransaction = false; |
| 3858 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3859 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3860 | if (mClosingApps.contains(wtoken)) { |
| 3861 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3862 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3863 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3864 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | delayed = true; |
| 3866 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3867 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3868 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3869 | + " animation=" + wtoken.animation |
| 3870 | + " animating=" + wtoken.animating); |
| 3871 | if (delayed) { |
| 3872 | // set the token aside because it has an active animation to be finished |
| 3873 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3874 | } else { |
| 3875 | // Make sure there is no animation running on this token, |
| 3876 | // so any windows associated with it will be removed as |
| 3877 | // soon as their animations are complete |
| 3878 | wtoken.animation = null; |
| 3879 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | } |
| 3881 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3882 | if (mLastEnterAnimToken == wtoken) { |
| 3883 | mLastEnterAnimToken = null; |
| 3884 | mLastEnterAnimParams = null; |
| 3885 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | wtoken.removed = true; |
| 3887 | if (wtoken.startingData != null) { |
| 3888 | startingToken = wtoken; |
| 3889 | } |
| 3890 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3891 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3892 | 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] | 3893 | mFocusedApp = null; |
| 3894 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3895 | mKeyWaiter.tickle(); |
| 3896 | } |
| 3897 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3898 | 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] | 3899 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3900 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | if (!delayed && wtoken != null) { |
| 3902 | wtoken.updateReportedVisibilityLocked(); |
| 3903 | } |
| 3904 | } |
| 3905 | Binder.restoreCallingIdentity(origId); |
| 3906 | |
| 3907 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3908 | 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] | 3909 | + startingToken + ": app token removed"); |
| 3910 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3911 | mH.sendMessage(m); |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3916 | final int NW = token.windows.size(); |
| 3917 | for (int i=0; i<NW; i++) { |
| 3918 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3919 | 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] | 3920 | mWindows.remove(win); |
| 3921 | int j = win.mChildWindows.size(); |
| 3922 | while (j > 0) { |
| 3923 | j--; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3924 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3925 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3926 | "Tmp removing child window " + cwin); |
| 3927 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | } |
| 3929 | } |
| 3930 | return NW > 0; |
| 3931 | } |
| 3932 | |
| 3933 | void dumpAppTokensLocked() { |
| 3934 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3935 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | } |
| 3937 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3938 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | void dumpWindowsLocked() { |
| 3940 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3941 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3942 | } |
| 3943 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3944 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | private int findWindowOffsetLocked(int tokenPos) { |
| 3946 | final int NW = mWindows.size(); |
| 3947 | |
| 3948 | if (tokenPos >= mAppTokens.size()) { |
| 3949 | int i = NW; |
| 3950 | while (i > 0) { |
| 3951 | i--; |
| 3952 | WindowState win = (WindowState)mWindows.get(i); |
| 3953 | if (win.getAppToken() != null) { |
| 3954 | return i+1; |
| 3955 | } |
| 3956 | } |
| 3957 | } |
| 3958 | |
| 3959 | while (tokenPos > 0) { |
| 3960 | // Find the first app token below the new position that has |
| 3961 | // a window displayed. |
| 3962 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3963 | 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] | 3964 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3965 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3966 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3967 | "Skipping token -- currently sending to bottom"); |
| 3968 | tokenPos--; |
| 3969 | continue; |
| 3970 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | int i = wtoken.windows.size(); |
| 3972 | while (i > 0) { |
| 3973 | i--; |
| 3974 | WindowState win = wtoken.windows.get(i); |
| 3975 | int j = win.mChildWindows.size(); |
| 3976 | while (j > 0) { |
| 3977 | j--; |
| 3978 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3979 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | for (int pos=NW-1; pos>=0; pos--) { |
| 3981 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3982 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3983 | "Found child win @" + (pos+1)); |
| 3984 | return pos+1; |
| 3985 | } |
| 3986 | } |
| 3987 | } |
| 3988 | } |
| 3989 | for (int pos=NW-1; pos>=0; pos--) { |
| 3990 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3991 | 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] | 3992 | return pos+1; |
| 3993 | } |
| 3994 | } |
| 3995 | } |
| 3996 | tokenPos--; |
| 3997 | } |
| 3998 | |
| 3999 | return 0; |
| 4000 | } |
| 4001 | |
| 4002 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4003 | final int NCW = win.mChildWindows.size(); |
| 4004 | boolean added = false; |
| 4005 | for (int j=0; j<NCW; j++) { |
| 4006 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 4007 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4008 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4009 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4010 | mWindows.add(index, win); |
| 4011 | index++; |
| 4012 | added = true; |
| 4013 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4014 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4015 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | mWindows.add(index, cwin); |
| 4017 | index++; |
| 4018 | } |
| 4019 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4020 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4021 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4022 | mWindows.add(index, win); |
| 4023 | index++; |
| 4024 | } |
| 4025 | return index; |
| 4026 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4027 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4029 | final int NW = token.windows.size(); |
| 4030 | for (int i=0; i<NW; i++) { |
| 4031 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4032 | } |
| 4033 | return index; |
| 4034 | } |
| 4035 | |
| 4036 | public void moveAppToken(int index, IBinder token) { |
| 4037 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4038 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4039 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4043 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4044 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4045 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4046 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4047 | 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] | 4048 | + token + " (" + wtoken + ")"); |
| 4049 | return; |
| 4050 | } |
| 4051 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4052 | 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] | 4053 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4054 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4056 | 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] | 4057 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4058 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4059 | 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] | 4060 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4061 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4062 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4064 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4065 | mLayoutNeeded = true; |
| 4066 | performLayoutAndPlaceSurfacesLocked(); |
| 4067 | } |
| 4068 | Binder.restoreCallingIdentity(origId); |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4073 | // XXX This should be done more efficiently! |
| 4074 | // (take advantage of the fact that both lists should be |
| 4075 | // ordered in the same way.) |
| 4076 | int N = tokens.size(); |
| 4077 | for (int i=0; i<N; i++) { |
| 4078 | IBinder token = tokens.get(i); |
| 4079 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4080 | if (!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 | i--; |
| 4084 | N--; |
| 4085 | } |
| 4086 | } |
| 4087 | } |
| 4088 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4089 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4090 | boolean updateFocusAndLayout) { |
| 4091 | // First remove all of the windows from the list. |
| 4092 | tmpRemoveAppWindowsLocked(wtoken); |
| 4093 | |
| 4094 | // Where to start adding? |
| 4095 | int pos = findWindowOffsetLocked(tokenPos); |
| 4096 | |
| 4097 | // And now add them back at the correct place. |
| 4098 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4099 | |
| 4100 | if (updateFocusAndLayout) { |
| 4101 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4102 | assignLayersLocked(); |
| 4103 | } |
| 4104 | mLayoutNeeded = true; |
| 4105 | performLayoutAndPlaceSurfacesLocked(); |
| 4106 | } |
| 4107 | } |
| 4108 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4110 | // First remove all of the windows from the list. |
| 4111 | final int N = tokens.size(); |
| 4112 | int i; |
| 4113 | for (i=0; i<N; i++) { |
| 4114 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4115 | if (token != null) { |
| 4116 | tmpRemoveAppWindowsLocked(token); |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | // Where to start adding? |
| 4121 | int pos = findWindowOffsetLocked(tokenPos); |
| 4122 | |
| 4123 | // And now add them back at the correct place. |
| 4124 | for (i=0; i<N; i++) { |
| 4125 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4126 | if (token != null) { |
| 4127 | pos = reAddAppWindowsLocked(pos, token); |
| 4128 | } |
| 4129 | } |
| 4130 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4131 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4132 | assignLayersLocked(); |
| 4133 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4134 | mLayoutNeeded = true; |
| 4135 | performLayoutAndPlaceSurfacesLocked(); |
| 4136 | |
| 4137 | //dump(); |
| 4138 | } |
| 4139 | |
| 4140 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4141 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4142 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4143 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | } |
| 4145 | |
| 4146 | final long origId = Binder.clearCallingIdentity(); |
| 4147 | synchronized(mWindowMap) { |
| 4148 | removeAppTokensLocked(tokens); |
| 4149 | final int N = tokens.size(); |
| 4150 | for (int i=0; i<N; i++) { |
| 4151 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4152 | if (wt != null) { |
| 4153 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4154 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4155 | mToTopApps.remove(wt); |
| 4156 | mToBottomApps.remove(wt); |
| 4157 | mToTopApps.add(wt); |
| 4158 | wt.sendingToBottom = false; |
| 4159 | wt.sendingToTop = true; |
| 4160 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4161 | } |
| 4162 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4163 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4164 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4165 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4166 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4167 | } |
| 4168 | Binder.restoreCallingIdentity(origId); |
| 4169 | } |
| 4170 | |
| 4171 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4172 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4173 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4174 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | final long origId = Binder.clearCallingIdentity(); |
| 4178 | synchronized(mWindowMap) { |
| 4179 | removeAppTokensLocked(tokens); |
| 4180 | final int N = tokens.size(); |
| 4181 | int pos = 0; |
| 4182 | for (int i=0; i<N; i++) { |
| 4183 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4184 | if (wt != null) { |
| 4185 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4186 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4187 | mToTopApps.remove(wt); |
| 4188 | mToBottomApps.remove(wt); |
| 4189 | mToBottomApps.add(i, wt); |
| 4190 | wt.sendingToTop = false; |
| 4191 | wt.sendingToBottom = true; |
| 4192 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | pos++; |
| 4194 | } |
| 4195 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4196 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4197 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4198 | moveAppWindowsLocked(tokens, 0); |
| 4199 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | } |
| 4201 | Binder.restoreCallingIdentity(origId); |
| 4202 | } |
| 4203 | |
| 4204 | // ------------------------------------------------------------- |
| 4205 | // Misc IWindowSession methods |
| 4206 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4207 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4208 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4209 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4210 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4211 | // called before DevicePolicyManagerService has started. |
| 4212 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4213 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4214 | Context.DEVICE_POLICY_SERVICE); |
| 4215 | if (dpm != null) { |
| 4216 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4217 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4218 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4219 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4220 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4221 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4222 | } |
| 4223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4224 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4225 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | != PackageManager.PERMISSION_GRANTED) { |
| 4227 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4228 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4229 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4230 | synchronized (mKeyguardTokenWatcher) { |
| 4231 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4232 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4236 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4237 | != PackageManager.PERMISSION_GRANTED) { |
| 4238 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4239 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4241 | synchronized (mKeyguardTokenWatcher) { |
| 4242 | mKeyguardTokenWatcher.release(token); |
| 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 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4245 | // If we are the last one to reenable the keyguard wait until |
| 4246 | // we have actually finished reenabling until returning. |
| 4247 | // It is possible that reenableKeyguard() can be called before |
| 4248 | // the previous disableKeyguard() is handled, in which case |
| 4249 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4250 | // be called. In that case mKeyguardDisabled will be false here |
| 4251 | // and we have nothing to wait for. |
| 4252 | while (mKeyguardDisabled) { |
| 4253 | try { |
| 4254 | mKeyguardTokenWatcher.wait(); |
| 4255 | } catch (InterruptedException e) { |
| 4256 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4257 | } |
| 4258 | } |
| 4259 | } |
| 4260 | } |
| 4261 | } |
| 4262 | |
| 4263 | /** |
| 4264 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4265 | */ |
| 4266 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4267 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | != PackageManager.PERMISSION_GRANTED) { |
| 4269 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4270 | } |
| 4271 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4272 | public void onKeyguardExitResult(boolean success) { |
| 4273 | try { |
| 4274 | callback.onKeyguardExitResult(success); |
| 4275 | } catch (RemoteException e) { |
| 4276 | // Client has died, we don't care. |
| 4277 | } |
| 4278 | } |
| 4279 | }); |
| 4280 | } |
| 4281 | |
| 4282 | public boolean inKeyguardRestrictedInputMode() { |
| 4283 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4284 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4285 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4286 | public void closeSystemDialogs(String reason) { |
| 4287 | synchronized(mWindowMap) { |
| 4288 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4289 | WindowState w = (WindowState)mWindows.get(i); |
| 4290 | if (w.mSurface != null) { |
| 4291 | try { |
| 4292 | w.mClient.closeSystemDialogs(reason); |
| 4293 | } catch (RemoteException e) { |
| 4294 | } |
| 4295 | } |
| 4296 | } |
| 4297 | } |
| 4298 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | static float fixScale(float scale) { |
| 4301 | if (scale < 0) scale = 0; |
| 4302 | else if (scale > 20) scale = 20; |
| 4303 | return Math.abs(scale); |
| 4304 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | public void setAnimationScale(int which, float scale) { |
| 4307 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4308 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4309 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | if (scale < 0) scale = 0; |
| 4313 | else if (scale > 20) scale = 20; |
| 4314 | scale = Math.abs(scale); |
| 4315 | switch (which) { |
| 4316 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4317 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4318 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4319 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4320 | // Persist setting |
| 4321 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4322 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | public void setAnimationScales(float[] scales) { |
| 4325 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4326 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4327 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | if (scales != null) { |
| 4331 | if (scales.length >= 1) { |
| 4332 | mWindowAnimationScale = fixScale(scales[0]); |
| 4333 | } |
| 4334 | if (scales.length >= 2) { |
| 4335 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4336 | } |
| 4337 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | // Persist setting |
| 4340 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4341 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4342 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4343 | public float getAnimationScale(int which) { |
| 4344 | switch (which) { |
| 4345 | case 0: return mWindowAnimationScale; |
| 4346 | case 1: return mTransitionAnimationScale; |
| 4347 | } |
| 4348 | return 0; |
| 4349 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4350 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4351 | public float[] getAnimationScales() { |
| 4352 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4353 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4354 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | public int getSwitchState(int sw) { |
| 4356 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4357 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4358 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4359 | } |
| 4360 | return KeyInputQueue.getSwitchState(sw); |
| 4361 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4363 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4364 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4365 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4366 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | } |
| 4368 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4369 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4370 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | public int getScancodeState(int sw) { |
| 4372 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4373 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4374 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4375 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4376 | return mQueue.getScancodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4378 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4379 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4380 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4381 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4382 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4384 | return mQueue.getScancodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4386 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4387 | public int getTrackballScancodeState(int sw) { |
| 4388 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4389 | "getTrackballScancodeState()")) { |
| 4390 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4391 | } |
| 4392 | return mQueue.getTrackballScancodeState(sw); |
| 4393 | } |
| 4394 | |
| 4395 | public int getDPadScancodeState(int sw) { |
| 4396 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4397 | "getDPadScancodeState()")) { |
| 4398 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4399 | } |
| 4400 | return mQueue.getDPadScancodeState(sw); |
| 4401 | } |
| 4402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | public int getKeycodeState(int sw) { |
| 4404 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4405 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4406 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4408 | return mQueue.getKeycodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4409 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4410 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4412 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4413 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4414 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4416 | return mQueue.getKeycodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4418 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4419 | public int getTrackballKeycodeState(int sw) { |
| 4420 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4421 | "getTrackballKeycodeState()")) { |
| 4422 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4423 | } |
| 4424 | return mQueue.getTrackballKeycodeState(sw); |
| 4425 | } |
| 4426 | |
| 4427 | public int getDPadKeycodeState(int sw) { |
| 4428 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4429 | "getDPadKeycodeState()")) { |
| 4430 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4431 | } |
| 4432 | return mQueue.getDPadKeycodeState(sw); |
| 4433 | } |
| 4434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 4436 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4437 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4438 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | public void enableScreenAfterBoot() { |
| 4440 | synchronized(mWindowMap) { |
| 4441 | if (mSystemBooted) { |
| 4442 | return; |
| 4443 | } |
| 4444 | mSystemBooted = true; |
| 4445 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4446 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | performEnableScreen(); |
| 4448 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4450 | public void enableScreenIfNeededLocked() { |
| 4451 | if (mDisplayEnabled) { |
| 4452 | return; |
| 4453 | } |
| 4454 | if (!mSystemBooted) { |
| 4455 | return; |
| 4456 | } |
| 4457 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4458 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4460 | public void performEnableScreen() { |
| 4461 | synchronized(mWindowMap) { |
| 4462 | if (mDisplayEnabled) { |
| 4463 | return; |
| 4464 | } |
| 4465 | if (!mSystemBooted) { |
| 4466 | return; |
| 4467 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4468 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | // Don't enable the screen until all existing windows |
| 4470 | // have been drawn. |
| 4471 | final int N = mWindows.size(); |
| 4472 | for (int i=0; i<N; i++) { |
| 4473 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 4474 | if (w.isVisibleLw() && !w.mObscured |
| 4475 | && (w.mOrientationChanging || !w.isDrawnLw())) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | return; |
| 4477 | } |
| 4478 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | mDisplayEnabled = true; |
| 4481 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4482 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4483 | StringWriter sw = new StringWriter(); |
| 4484 | PrintWriter pw = new PrintWriter(sw); |
| 4485 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4486 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | } |
| 4488 | try { |
| 4489 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4490 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4491 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4492 | Parcel data = Parcel.obtain(); |
| 4493 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4494 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4495 | data, null, 0); |
| 4496 | data.recycle(); |
| 4497 | } |
| 4498 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4499 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4500 | } |
| 4501 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4506 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4507 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4508 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4510 | public void setInTouchMode(boolean mode) { |
| 4511 | synchronized(mWindowMap) { |
| 4512 | mInTouchMode = mode; |
| 4513 | } |
| 4514 | } |
| 4515 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4516 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4517 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4518 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4519 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4520 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | } |
| 4522 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4523 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4525 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4526 | public void setRotationUnchecked(int rotation, |
| 4527 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4528 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4531 | long origId = Binder.clearCallingIdentity(); |
| 4532 | boolean changed; |
| 4533 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4534 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4536 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4537 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | sendNewConfiguration(); |
| 4539 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4540 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4541 | Binder.restoreCallingIdentity(origId); |
| 4542 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4543 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4544 | /** |
| 4545 | * Apply a new rotation to the screen, respecting the requests of |
| 4546 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4547 | * re-evaluate the desired rotation. |
| 4548 | * |
| 4549 | * Returns null if the rotation has been changed. In this case YOU |
| 4550 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4551 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4552 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4553 | boolean changed; |
| 4554 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4555 | rotation = mRequestedRotation; |
| 4556 | } else { |
| 4557 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4558 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4559 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4560 | 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] | 4561 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4562 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4563 | 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] | 4564 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4565 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4566 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4567 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4568 | "Rotation changed to " + rotation |
| 4569 | + " from " + mRotation |
| 4570 | + " (forceApp=" + mForcedAppOrientation |
| 4571 | + ", req=" + mRequestedRotation + ")"); |
| 4572 | mRotation = rotation; |
| 4573 | mWindowsFreezingScreen = true; |
| 4574 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4575 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4576 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4577 | mWaitingForConfig = true; |
| 4578 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4580 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | mQueue.setOrientation(rotation); |
| 4582 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4583 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | } |
| 4585 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4586 | WindowState w = (WindowState)mWindows.get(i); |
| 4587 | if (w.mSurface != null) { |
| 4588 | w.mOrientationChanging = true; |
| 4589 | } |
| 4590 | } |
| 4591 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4592 | try { |
| 4593 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4594 | } catch (RemoteException e) { |
| 4595 | } |
| 4596 | } |
| 4597 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4599 | return changed; |
| 4600 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | public int getRotation() { |
| 4603 | return mRotation; |
| 4604 | } |
| 4605 | |
| 4606 | public int watchRotation(IRotationWatcher watcher) { |
| 4607 | final IBinder watcherBinder = watcher.asBinder(); |
| 4608 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4609 | public void binderDied() { |
| 4610 | synchronized (mWindowMap) { |
| 4611 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4612 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4613 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4614 | if (removed != null) { |
| 4615 | removed.asBinder().unlinkToDeath(this, 0); |
| 4616 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4617 | i--; |
| 4618 | } |
| 4619 | } |
| 4620 | } |
| 4621 | } |
| 4622 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | synchronized (mWindowMap) { |
| 4625 | try { |
| 4626 | watcher.asBinder().linkToDeath(dr, 0); |
| 4627 | mRotationWatchers.add(watcher); |
| 4628 | } catch (RemoteException e) { |
| 4629 | // Client died, no cleanup needed. |
| 4630 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4631 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4632 | return mRotation; |
| 4633 | } |
| 4634 | } |
| 4635 | |
| 4636 | /** |
| 4637 | * Starts the view server on the specified port. |
| 4638 | * |
| 4639 | * @param port The port to listener to. |
| 4640 | * |
| 4641 | * @return True if the server was successfully started, false otherwise. |
| 4642 | * |
| 4643 | * @see com.android.server.ViewServer |
| 4644 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4645 | */ |
| 4646 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4647 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | return false; |
| 4649 | } |
| 4650 | |
| 4651 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4652 | return false; |
| 4653 | } |
| 4654 | |
| 4655 | if (port < 1024) { |
| 4656 | return false; |
| 4657 | } |
| 4658 | |
| 4659 | if (mViewServer != null) { |
| 4660 | if (!mViewServer.isRunning()) { |
| 4661 | try { |
| 4662 | return mViewServer.start(); |
| 4663 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4664 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4665 | } |
| 4666 | } |
| 4667 | return false; |
| 4668 | } |
| 4669 | |
| 4670 | try { |
| 4671 | mViewServer = new ViewServer(this, port); |
| 4672 | return mViewServer.start(); |
| 4673 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4674 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4675 | } |
| 4676 | return false; |
| 4677 | } |
| 4678 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4679 | private boolean isSystemSecure() { |
| 4680 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4681 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4682 | } |
| 4683 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | /** |
| 4685 | * Stops the view server if it exists. |
| 4686 | * |
| 4687 | * @return True if the server stopped, false if it wasn't started or |
| 4688 | * couldn't be stopped. |
| 4689 | * |
| 4690 | * @see com.android.server.ViewServer |
| 4691 | */ |
| 4692 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4693 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | return false; |
| 4695 | } |
| 4696 | |
| 4697 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4698 | return false; |
| 4699 | } |
| 4700 | |
| 4701 | if (mViewServer != null) { |
| 4702 | return mViewServer.stop(); |
| 4703 | } |
| 4704 | return false; |
| 4705 | } |
| 4706 | |
| 4707 | /** |
| 4708 | * Indicates whether the view server is running. |
| 4709 | * |
| 4710 | * @return True if the server is running, false otherwise. |
| 4711 | * |
| 4712 | * @see com.android.server.ViewServer |
| 4713 | */ |
| 4714 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4715 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4716 | return false; |
| 4717 | } |
| 4718 | |
| 4719 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4720 | return false; |
| 4721 | } |
| 4722 | |
| 4723 | return mViewServer != null && mViewServer.isRunning(); |
| 4724 | } |
| 4725 | |
| 4726 | /** |
| 4727 | * Lists all availble windows in the system. The listing is written in the |
| 4728 | * specified Socket's output stream with the following syntax: |
| 4729 | * windowHashCodeInHexadecimal windowName |
| 4730 | * Each line of the ouput represents a different window. |
| 4731 | * |
| 4732 | * @param client The remote client to send the listing to. |
| 4733 | * @return False if an error occured, true otherwise. |
| 4734 | */ |
| 4735 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4736 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | return false; |
| 4738 | } |
| 4739 | |
| 4740 | boolean result = true; |
| 4741 | |
| 4742 | Object[] windows; |
| 4743 | synchronized (mWindowMap) { |
| 4744 | windows = new Object[mWindows.size()]; |
| 4745 | //noinspection unchecked |
| 4746 | windows = mWindows.toArray(windows); |
| 4747 | } |
| 4748 | |
| 4749 | BufferedWriter out = null; |
| 4750 | |
| 4751 | // Any uncaught exception will crash the system process |
| 4752 | try { |
| 4753 | OutputStream clientStream = client.getOutputStream(); |
| 4754 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4755 | |
| 4756 | final int count = windows.length; |
| 4757 | for (int i = 0; i < count; i++) { |
| 4758 | final WindowState w = (WindowState) windows[i]; |
| 4759 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4760 | out.write(' '); |
| 4761 | out.append(w.mAttrs.getTitle()); |
| 4762 | out.write('\n'); |
| 4763 | } |
| 4764 | |
| 4765 | out.write("DONE.\n"); |
| 4766 | out.flush(); |
| 4767 | } catch (Exception e) { |
| 4768 | result = false; |
| 4769 | } finally { |
| 4770 | if (out != null) { |
| 4771 | try { |
| 4772 | out.close(); |
| 4773 | } catch (IOException e) { |
| 4774 | result = false; |
| 4775 | } |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | return result; |
| 4780 | } |
| 4781 | |
| 4782 | /** |
| 4783 | * Sends a command to a target window. The result of the command, if any, will be |
| 4784 | * written in the output stream of the specified socket. |
| 4785 | * |
| 4786 | * The parameters must follow this syntax: |
| 4787 | * windowHashcode extra |
| 4788 | * |
| 4789 | * Where XX is the length in characeters of the windowTitle. |
| 4790 | * |
| 4791 | * The first parameter is the target window. The window with the specified hashcode |
| 4792 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4793 | * will be delivered to the target window and as parameters to the command itself. |
| 4794 | * |
| 4795 | * @param client The remote client to sent the result, if any, to. |
| 4796 | * @param command The command to execute. |
| 4797 | * @param parameters The command parameters. |
| 4798 | * |
| 4799 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4800 | * not indicate whether the command itself was successful. |
| 4801 | */ |
| 4802 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4803 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | return false; |
| 4805 | } |
| 4806 | |
| 4807 | boolean success = true; |
| 4808 | Parcel data = null; |
| 4809 | Parcel reply = null; |
| 4810 | |
| 4811 | // Any uncaught exception will crash the system process |
| 4812 | try { |
| 4813 | // Find the hashcode of the window |
| 4814 | int index = parameters.indexOf(' '); |
| 4815 | if (index == -1) { |
| 4816 | index = parameters.length(); |
| 4817 | } |
| 4818 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4819 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | |
| 4821 | // Extract the command's parameter after the window description |
| 4822 | if (index < parameters.length()) { |
| 4823 | parameters = parameters.substring(index + 1); |
| 4824 | } else { |
| 4825 | parameters = ""; |
| 4826 | } |
| 4827 | |
| 4828 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4829 | if (window == null) { |
| 4830 | return false; |
| 4831 | } |
| 4832 | |
| 4833 | data = Parcel.obtain(); |
| 4834 | data.writeInterfaceToken("android.view.IWindow"); |
| 4835 | data.writeString(command); |
| 4836 | data.writeString(parameters); |
| 4837 | data.writeInt(1); |
| 4838 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4839 | |
| 4840 | reply = Parcel.obtain(); |
| 4841 | |
| 4842 | final IBinder binder = window.mClient.asBinder(); |
| 4843 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4844 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4845 | |
| 4846 | reply.readException(); |
| 4847 | |
| 4848 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4849 | 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] | 4850 | success = false; |
| 4851 | } finally { |
| 4852 | if (data != null) { |
| 4853 | data.recycle(); |
| 4854 | } |
| 4855 | if (reply != null) { |
| 4856 | reply.recycle(); |
| 4857 | } |
| 4858 | } |
| 4859 | |
| 4860 | return success; |
| 4861 | } |
| 4862 | |
| 4863 | private WindowState findWindow(int hashCode) { |
| 4864 | if (hashCode == -1) { |
| 4865 | return getFocusedWindow(); |
| 4866 | } |
| 4867 | |
| 4868 | synchronized (mWindowMap) { |
| 4869 | final ArrayList windows = mWindows; |
| 4870 | final int count = windows.size(); |
| 4871 | |
| 4872 | for (int i = 0; i < count; i++) { |
| 4873 | WindowState w = (WindowState) windows.get(i); |
| 4874 | if (System.identityHashCode(w) == hashCode) { |
| 4875 | return w; |
| 4876 | } |
| 4877 | } |
| 4878 | } |
| 4879 | |
| 4880 | return null; |
| 4881 | } |
| 4882 | |
| 4883 | /* |
| 4884 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4885 | * that to config-changed listeners if appropriate. |
| 4886 | */ |
| 4887 | void sendNewConfiguration() { |
| 4888 | try { |
| 4889 | mActivityManager.updateConfiguration(null); |
| 4890 | } catch (RemoteException e) { |
| 4891 | } |
| 4892 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4893 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4894 | public Configuration computeNewConfiguration() { |
| 4895 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4896 | return computeNewConfigurationLocked(); |
| 4897 | } |
| 4898 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4899 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4900 | Configuration computeNewConfigurationLocked() { |
| 4901 | Configuration config = new Configuration(); |
| 4902 | if (!computeNewConfigurationLocked(config)) { |
| 4903 | return null; |
| 4904 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4905 | return config; |
| 4906 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4907 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4908 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4909 | if (mDisplay == null) { |
| 4910 | return false; |
| 4911 | } |
| 4912 | mQueue.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 4913 | |
| 4914 | // Use the effective "visual" dimensions based on current rotation |
| 4915 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 4916 | || mRotation == Surface.ROTATION_270); |
| 4917 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 4918 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 4919 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4920 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4921 | if (dw < dh) { |
| 4922 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4923 | } else if (dw > dh) { |
| 4924 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4925 | } |
| 4926 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4927 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4928 | DisplayMetrics dm = new DisplayMetrics(); |
| 4929 | mDisplay.getMetrics(dm); |
| 4930 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4931 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4932 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4933 | // Note we only do this once because at this point we don't |
| 4934 | // expect the screen to change in this way at runtime, and want |
| 4935 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4936 | int longSize = dw; |
| 4937 | int shortSize = dh; |
| 4938 | if (longSize < shortSize) { |
| 4939 | int tmp = longSize; |
| 4940 | longSize = shortSize; |
| 4941 | shortSize = tmp; |
| 4942 | } |
| 4943 | longSize = (int)(longSize/dm.density); |
| 4944 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4945 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4946 | // These semi-magic numbers define our compatibility modes for |
| 4947 | // applications with different screens. Don't change unless you |
| 4948 | // make sure to test lots and lots of apps! |
| 4949 | if (longSize < 470) { |
| 4950 | // This is shorter than an HVGA normal density screen (which |
| 4951 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4952 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4953 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4954 | } else { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4955 | // Is this a large screen? |
| 4956 | if (longSize > 640 && shortSize >= 480) { |
| 4957 | // VGA or larger screens at medium density are the point |
| 4958 | // at which we consider it to be a large screen. |
| 4959 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4960 | } else { |
| 4961 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4962 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4963 | // If this screen is wider than normal HVGA, or taller |
| 4964 | // than FWVGA, then for old apps we want to run in size |
| 4965 | // compatibility mode. |
| 4966 | if (shortSize > 321 || longSize > 570) { |
| 4967 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4968 | } |
| 4969 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4970 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4971 | // Is this a long screen? |
| 4972 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4973 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4974 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4975 | } else { |
| 4976 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4977 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4978 | } |
| 4979 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4980 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4981 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4982 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4983 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4984 | mPolicy.adjustConfigurationLw(config); |
| 4985 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4986 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4987 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4988 | // ------------------------------------------------------------- |
| 4989 | // Input Events and Focus Management |
| 4990 | // ------------------------------------------------------------- |
| 4991 | |
| 4992 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4993 | long curTime = SystemClock.uptimeMillis(); |
| 4994 | |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4995 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4996 | if (mLastTouchEventType == eventType && |
| 4997 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4998 | return; |
| 4999 | } |
| 5000 | mLastUserActivityCallTime = curTime; |
| 5001 | mLastTouchEventType = eventType; |
| 5002 | } |
| 5003 | |
| 5004 | if (targetWin == null |
| 5005 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 5006 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5007 | } |
| 5008 | } |
| 5009 | |
| 5010 | // tells if it's a cheek event or not -- this function is stateful |
| 5011 | private static final int EVENT_NONE = 0; |
| 5012 | private static final int EVENT_UNKNOWN = 0; |
| 5013 | private static final int EVENT_CHEEK = 0; |
| 5014 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 5015 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 5016 | private int mEventState = EVENT_NONE; |
| 5017 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5018 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5019 | private int eventType(MotionEvent ev) { |
| 5020 | float size = ev.getSize(); |
| 5021 | switch (ev.getAction()) { |
| 5022 | case MotionEvent.ACTION_DOWN: |
| 5023 | mEventSize = size; |
| 5024 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 5025 | case MotionEvent.ACTION_UP: |
| 5026 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5027 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5028 | case MotionEvent.ACTION_MOVE: |
| 5029 | final int N = ev.getHistorySize(); |
| 5030 | if (size > mEventSize) mEventSize = size; |
| 5031 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 5032 | for (int i=0; i<N; i++) { |
| 5033 | size = ev.getHistoricalSize(i); |
| 5034 | if (size > mEventSize) mEventSize = size; |
| 5035 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 5036 | } |
| 5037 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 5038 | return TOUCH_EVENT; |
| 5039 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 5040 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5041 | } |
| 5042 | default: |
| 5043 | // not good |
| 5044 | return OTHER_EVENT; |
| 5045 | } |
| 5046 | } |
| 5047 | |
| 5048 | /** |
| 5049 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5050 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5051 | private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5052 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5053 | "dispatchPointer " + ev); |
| 5054 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5055 | if (MEASURE_LATENCY) { |
| 5056 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 5057 | } |
| 5058 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5059 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5060 | ev, true, false, pid, uid); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5061 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5062 | if (MEASURE_LATENCY) { |
| 5063 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 5064 | } |
| 5065 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5066 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5067 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5068 | if (action == MotionEvent.ACTION_UP) { |
| 5069 | // let go of our target |
| 5070 | mKeyWaiter.mMotionTarget = null; |
| 5071 | mPowerManager.logPointerUpEvent(); |
| 5072 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 5073 | mPowerManager.logPointerDownEvent(); |
| 5074 | } |
| 5075 | |
| 5076 | if (targetObj == null) { |
| 5077 | // In this case we are either dropping the event, or have received |
| 5078 | // a move or up without a down. It is common to receive move |
| 5079 | // events in such a way, since this means the user is moving the |
| 5080 | // pointer without actually pressing down. All other cases should |
| 5081 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5082 | if (action != MotionEvent.ACTION_MOVE) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5083 | 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] | 5084 | } |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5085 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5086 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5087 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5088 | if (qev != null) { |
| 5089 | mQueue.recycleEvent(qev); |
| 5090 | } |
| 5091 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5092 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5093 | } |
| 5094 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5095 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5096 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5097 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5098 | if (qev != null) { |
| 5099 | mQueue.recycleEvent(qev); |
| 5100 | } |
| 5101 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5102 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5103 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5104 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5105 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5107 | final long eventTime = ev.getEventTime(); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5108 | final long eventTimeNano = ev.getEventTimeNano(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5109 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5110 | //Slog.i(TAG, "Sending " + ev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5111 | |
| 5112 | if (uid != 0 && uid != target.mSession.mUid) { |
| 5113 | if (mContext.checkPermission( |
| 5114 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5115 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5116 | 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] | 5117 | + pid + " uid " + uid + " to window " + target |
| 5118 | + " owned by uid " + target.mSession.mUid); |
| 5119 | if (qev != null) { |
| 5120 | mQueue.recycleEvent(qev); |
| 5121 | } |
| 5122 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5123 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | } |
| 5125 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5126 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5127 | if (MEASURE_LATENCY) { |
| 5128 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5129 | } |
| 5130 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5131 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5132 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 5133 | //target wants to ignore fat touch events |
| 5134 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 5135 | //explicit flag to return without processing event further |
| 5136 | boolean returnFlag = false; |
| 5137 | if((action == MotionEvent.ACTION_DOWN)) { |
| 5138 | mFatTouch = false; |
| 5139 | if(cheekPress) { |
| 5140 | mFatTouch = true; |
| 5141 | returnFlag = true; |
| 5142 | } |
| 5143 | } else { |
| 5144 | if(action == MotionEvent.ACTION_UP) { |
| 5145 | if(mFatTouch) { |
| 5146 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 5147 | mFatTouch = false; |
| 5148 | returnFlag = true; |
| 5149 | } else if(cheekPress) { |
| 5150 | //cancel the earlier event |
| 5151 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5152 | action = MotionEvent.ACTION_CANCEL; |
| 5153 | } |
| 5154 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 5155 | if(mFatTouch) { |
| 5156 | //two cases here |
| 5157 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5158 | //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] | 5159 | returnFlag = true; |
| 5160 | } else if(cheekPress) { |
| 5161 | //valid down followed by invalid moves |
| 5162 | //an invalid move have to cancel earlier action |
| 5163 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5164 | action = MotionEvent.ACTION_CANCEL; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5165 | 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] | 5166 | //note that the subsequent invalid moves will not get here |
| 5167 | mFatTouch = true; |
| 5168 | } |
| 5169 | } |
| 5170 | } //else if action |
| 5171 | if(returnFlag) { |
| 5172 | //recycle que, ev |
| 5173 | if (qev != null) { |
| 5174 | mQueue.recycleEvent(qev); |
| 5175 | } |
| 5176 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5177 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5178 | } |
| 5179 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5180 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 5181 | // Enable this for testing the "right" value |
| 5182 | if (false && action == MotionEvent.ACTION_DOWN) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5183 | int max_events_per_sec = 35; |
| 5184 | try { |
| 5185 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 5186 | .get("windowsmgr.max_events_per_sec")); |
| 5187 | if (max_events_per_sec < 1) { |
| 5188 | max_events_per_sec = 35; |
| 5189 | } |
| 5190 | } catch (NumberFormatException e) { |
| 5191 | } |
| 5192 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 5193 | } |
| 5194 | |
| 5195 | /* |
| 5196 | * Throttle events to minimize CPU usage when there's a flood of events |
| 5197 | * e.g. constant contact with the screen |
| 5198 | */ |
| 5199 | if (action == MotionEvent.ACTION_MOVE) { |
| 5200 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 5201 | long now = SystemClock.uptimeMillis(); |
| 5202 | if (now < nextEventTime) { |
| 5203 | try { |
| 5204 | Thread.sleep(nextEventTime - now); |
| 5205 | } catch (InterruptedException e) { |
| 5206 | } |
| 5207 | mLastTouchEventTime = nextEventTime; |
| 5208 | } else { |
| 5209 | mLastTouchEventTime = now; |
| 5210 | } |
| 5211 | } |
| 5212 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5213 | if (MEASURE_LATENCY) { |
| 5214 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5215 | } |
| 5216 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5217 | synchronized(mWindowMap) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5218 | if (!target.isVisibleLw()) { |
| 5219 | // During this motion dispatch, the target window has become |
| 5220 | // invisible. |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5221 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5222 | if (qev != null) { |
| 5223 | mQueue.recycleEvent(qev); |
| 5224 | } |
| 5225 | ev.recycle(); |
| 5226 | return INJECT_SUCCEEDED; |
| 5227 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5228 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 5230 | mKeyWaiter.bindTargetWindowLocked(target, |
| 5231 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 5232 | ev = null; |
| 5233 | } else { |
| 5234 | if (action == MotionEvent.ACTION_DOWN) { |
| 5235 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 5236 | if (out != null) { |
| 5237 | MotionEvent oev = MotionEvent.obtain(ev); |
| 5238 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 5239 | do { |
| 5240 | final Rect frame = out.mFrame; |
| 5241 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5242 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5243 | out.mClient.dispatchPointer(oev, eventTime, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5244 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5245 | 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] | 5246 | } |
| 5247 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 5248 | out = out.mNextOutsideTouch; |
| 5249 | } while (out != null); |
| 5250 | mKeyWaiter.mOutsideTouchTargets = null; |
| 5251 | } |
| 5252 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5253 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5254 | dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5255 | |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5256 | final Rect frame = target.mFrame; |
| 5257 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5258 | mKeyWaiter.bindTargetWindowLocked(target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5259 | } |
| 5260 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | // finally offset the event to the target's coordinate system and |
| 5263 | // dispatch the event. |
| 5264 | try { |
| 5265 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5266 | Slog.v(TAG, "Delivering pointer " + qev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5267 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5268 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5269 | if (MEASURE_LATENCY) { |
| 5270 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5271 | } |
| 5272 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5273 | target.mClient.dispatchPointer(ev, eventTime, true); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5274 | |
| 5275 | if (MEASURE_LATENCY) { |
| 5276 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5277 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5278 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5280 | Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | mKeyWaiter.mMotionTarget = null; |
| 5282 | try { |
| 5283 | removeWindow(target.mSession, target.mClient); |
| 5284 | } catch (java.util.NoSuchElementException ex) { |
| 5285 | // This will happen if the window has already been |
| 5286 | // removed. |
| 5287 | } |
| 5288 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5289 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5290 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5292 | /** |
| 5293 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5294 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5295 | private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5296 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5297 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5299 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5300 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5301 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5302 | Slog.w(TAG, "No focus window, dropping trackball: " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5303 | if (qev != null) { |
| 5304 | mQueue.recycleEvent(qev); |
| 5305 | } |
| 5306 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5307 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5308 | } |
| 5309 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 5310 | if (qev != null) { |
| 5311 | mQueue.recycleEvent(qev); |
| 5312 | } |
| 5313 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5314 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5315 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5316 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5317 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5320 | if (mContext.checkPermission( |
| 5321 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5322 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5323 | 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] | 5324 | + pid + " uid " + uid + " to window " + focus |
| 5325 | + " owned by uid " + focus.mSession.mUid); |
| 5326 | if (qev != null) { |
| 5327 | mQueue.recycleEvent(qev); |
| 5328 | } |
| 5329 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5330 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | } |
| 5332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5334 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5335 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5336 | synchronized(mWindowMap) { |
| 5337 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5338 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5339 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5340 | // We don't deliver movement events to the client, we hold |
| 5341 | // them and wait for them to call back. |
| 5342 | ev = null; |
| 5343 | } else { |
| 5344 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5345 | } |
| 5346 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5347 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5348 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5349 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5350 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5352 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5353 | try { |
| 5354 | removeWindow(focus.mSession, focus.mClient); |
| 5355 | } catch (java.util.NoSuchElementException ex) { |
| 5356 | // This will happen if the window has already been |
| 5357 | // removed. |
| 5358 | } |
| 5359 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5360 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5361 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5362 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5363 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5364 | /** |
| 5365 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5366 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5367 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5368 | if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | |
| 5370 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5371 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5372 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5373 | Slog.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5374 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5375 | } |
| 5376 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5377 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5378 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5379 | |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5380 | // Okay we have finished waiting for the last event to be processed. |
| 5381 | // First off, if this is a repeat event, check to see if there is |
| 5382 | // a corresponding up event in the queue. If there is, we will |
| 5383 | // just drop the repeat, because it makes no sense to repeat after |
| 5384 | // the user has released a key. (This is especially important for |
| 5385 | // long presses.) |
| 5386 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5387 | return INJECT_SUCCEEDED; |
| 5388 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5390 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5391 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5392 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | TAG, "Dispatching to " + focus + ": " + event); |
| 5394 | |
| 5395 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5396 | if (mContext.checkPermission( |
| 5397 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5398 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5399 | 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] | 5400 | + pid + " uid " + uid + " to window " + focus |
| 5401 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5402 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5403 | } |
| 5404 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5405 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5406 | synchronized(mWindowMap) { |
| 5407 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5408 | } |
| 5409 | |
| 5410 | // NOSHIP extra state logging |
| 5411 | mKeyWaiter.recordDispatchState(event, focus); |
| 5412 | // END NOSHIP |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5413 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | try { |
| 5415 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5416 | Slog.v(TAG, "Delivering key " + event.getKeyCode() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5417 | + " to " + focus); |
| 5418 | } |
| 5419 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5420 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5421 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5422 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5423 | try { |
| 5424 | removeWindow(focus.mSession, focus.mClient); |
| 5425 | } catch (java.util.NoSuchElementException ex) { |
| 5426 | // This will happen if the window has already been |
| 5427 | // removed. |
| 5428 | } |
| 5429 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5430 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5431 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5434 | public void pauseKeyDispatching(IBinder _token) { |
| 5435 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5436 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5437 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | synchronized (mWindowMap) { |
| 5441 | WindowToken token = mTokenMap.get(_token); |
| 5442 | if (token != null) { |
| 5443 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5444 | } |
| 5445 | } |
| 5446 | } |
| 5447 | |
| 5448 | public void resumeKeyDispatching(IBinder _token) { |
| 5449 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5450 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5451 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | synchronized (mWindowMap) { |
| 5455 | WindowToken token = mTokenMap.get(_token); |
| 5456 | if (token != null) { |
| 5457 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5458 | } |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | public void setEventDispatching(boolean enabled) { |
| 5463 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5464 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5465 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5466 | } |
| 5467 | |
| 5468 | synchronized (mWindowMap) { |
| 5469 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5470 | } |
| 5471 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5473 | /** |
| 5474 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5475 | * |
| 5476 | * @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] | 5477 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5478 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5479 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5480 | */ |
| 5481 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5482 | long downTime = ev.getDownTime(); |
| 5483 | long eventTime = ev.getEventTime(); |
| 5484 | |
| 5485 | int action = ev.getAction(); |
| 5486 | int code = ev.getKeyCode(); |
| 5487 | int repeatCount = ev.getRepeatCount(); |
| 5488 | int metaState = ev.getMetaState(); |
| 5489 | int deviceId = ev.getDeviceId(); |
| 5490 | int scancode = ev.getScanCode(); |
| Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame^] | 5491 | int flags = ev.getFlags(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5492 | |
| 5493 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5494 | if (downTime == 0) downTime = eventTime; |
| 5495 | |
| 5496 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame^] | 5497 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5498 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5499 | final int pid = Binder.getCallingPid(); |
| 5500 | final int uid = Binder.getCallingUid(); |
| 5501 | final long ident = Binder.clearCallingIdentity(); |
| 5502 | final int result = dispatchKey(newEvent, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5503 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5504 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5506 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5507 | switch (result) { |
| 5508 | case INJECT_NO_PERMISSION: |
| 5509 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5510 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5511 | case INJECT_SUCCEEDED: |
| 5512 | return true; |
| 5513 | } |
| 5514 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | /** |
| 5518 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5519 | * |
| 5520 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5521 | * {@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] | 5522 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5523 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5524 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5525 | */ |
| 5526 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5527 | final int pid = Binder.getCallingPid(); |
| 5528 | final int uid = Binder.getCallingUid(); |
| 5529 | final long ident = Binder.clearCallingIdentity(); |
| 5530 | final int result = dispatchPointer(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5531 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5532 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5533 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5534 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5535 | switch (result) { |
| 5536 | case INJECT_NO_PERMISSION: |
| 5537 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5538 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5539 | case INJECT_SUCCEEDED: |
| 5540 | return true; |
| 5541 | } |
| 5542 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | /** |
| 5546 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5547 | * |
| 5548 | * @param ev A motion event describing the trackball action. (As noted in |
| 5549 | * {@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] | 5550 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5551 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5552 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5553 | */ |
| 5554 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5555 | final int pid = Binder.getCallingPid(); |
| 5556 | final int uid = Binder.getCallingUid(); |
| 5557 | final long ident = Binder.clearCallingIdentity(); |
| 5558 | final int result = dispatchTrackball(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5559 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5560 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5561 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5562 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5563 | switch (result) { |
| 5564 | case INJECT_NO_PERMISSION: |
| 5565 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5566 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5567 | case INJECT_SUCCEEDED: |
| 5568 | return true; |
| 5569 | } |
| 5570 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5571 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5572 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5573 | private WindowState getFocusedWindow() { |
| 5574 | synchronized (mWindowMap) { |
| 5575 | return getFocusedWindowLocked(); |
| 5576 | } |
| 5577 | } |
| 5578 | |
| 5579 | private WindowState getFocusedWindowLocked() { |
| 5580 | return mCurrentFocus; |
| 5581 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5582 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5583 | /** |
| 5584 | * This class holds the state for dispatching key events. This state |
| 5585 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 5586 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 5587 | * but not the other way around. |
| 5588 | */ |
| 5589 | final class KeyWaiter { |
| 5590 | // NOSHIP debugging |
| 5591 | public class DispatchState { |
| 5592 | private KeyEvent event; |
| 5593 | private WindowState focus; |
| 5594 | private long time; |
| 5595 | private WindowState lastWin; |
| 5596 | private IBinder lastBinder; |
| 5597 | private boolean finished; |
| 5598 | private boolean gotFirstWindow; |
| 5599 | private boolean eventDispatching; |
| 5600 | private long timeToSwitch; |
| 5601 | private boolean wasFrozen; |
| 5602 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5603 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5604 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5605 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5606 | focus = theFocus; |
| 5607 | event = theEvent; |
| 5608 | time = System.currentTimeMillis(); |
| 5609 | // snapshot KeyWaiter state |
| 5610 | lastWin = mLastWin; |
| 5611 | lastBinder = mLastBinder; |
| 5612 | finished = mFinished; |
| 5613 | gotFirstWindow = mGotFirstWindow; |
| 5614 | eventDispatching = mEventDispatching; |
| 5615 | timeToSwitch = mTimeToSwitch; |
| 5616 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5617 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5618 | // cache the paused state at ctor time as well |
| 5619 | if (theFocus == null || theFocus.mToken == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5620 | focusPaused = false; |
| 5621 | } else { |
| 5622 | focusPaused = theFocus.mToken.paused; |
| 5623 | } |
| 5624 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5625 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | public String toString() { |
| 5627 | return "{{" + event + " to " + focus + " @ " + time |
| 5628 | + " lw=" + lastWin + " lb=" + lastBinder |
| 5629 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 5630 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5631 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| Christopher Tate | 46d4525 | 2010-02-09 15:48:57 -0800 | [diff] [blame] | 5632 | + " mcf=" + curFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | } |
| 5634 | }; |
| 5635 | private DispatchState mDispatchState = null; |
| 5636 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5637 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 5638 | } |
| 5639 | // END NOSHIP |
| 5640 | |
| 5641 | public static final int RETURN_NOTHING = 0; |
| 5642 | public static final int RETURN_PENDING_POINTER = 1; |
| 5643 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| 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 Object SKIP_TARGET_TOKEN = new Object(); |
| 5646 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5647 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5648 | private WindowState mLastWin = null; |
| 5649 | private IBinder mLastBinder = null; |
| 5650 | private boolean mFinished = true; |
| 5651 | private boolean mGotFirstWindow = false; |
| 5652 | private boolean mEventDispatching = true; |
| 5653 | private long mTimeToSwitch = 0; |
| 5654 | /* package */ boolean mWasFrozen = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5655 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5656 | // Target of Motion events |
| 5657 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5658 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5659 | // Windows above the target who would like to receive an "outside" |
| 5660 | // touch event for any down events outside of them. |
| 5661 | WindowState mOutsideTouchTargets; |
| 5662 | |
| 5663 | /** |
| 5664 | * Wait for the last event dispatch to complete, then find the next |
| 5665 | * target that should receive the given event and wait for that one |
| 5666 | * to be ready to receive it. |
| 5667 | */ |
| 5668 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5669 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5670 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5671 | long startTime = SystemClock.uptimeMillis(); |
| 5672 | long keyDispatchingTimeout = 5 * 1000; |
| 5673 | long waitedFor = 0; |
| 5674 | |
| 5675 | while (true) { |
| 5676 | // Figure out which window we care about. It is either the |
| 5677 | // last window we are waiting to have process the event or, |
| 5678 | // if none, then the next window we think the event should go |
| 5679 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5680 | // it may change before we lock. Thus we must check it again. |
| 5681 | WindowState targetWin = mLastWin; |
| 5682 | boolean targetIsNew = targetWin == null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5683 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5684 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5685 | ", mLastWin=" + mLastWin); |
| 5686 | if (targetIsNew) { |
| 5687 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5688 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5689 | if (target == SKIP_TARGET_TOKEN) { |
| 5690 | // The user has pressed a special key, and we are |
| 5691 | // dropping all pending events before it. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5692 | if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5693 | + " " + nextMotion); |
| 5694 | return null; |
| 5695 | } |
| 5696 | if (target == CONSUMED_EVENT_TOKEN) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5697 | if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5698 | + " " + nextMotion); |
| 5699 | return target; |
| 5700 | } |
| 5701 | targetWin = (WindowState)target; |
| 5702 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5703 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5704 | AppWindowToken targetApp = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5705 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5706 | // Now: is it okay to send the next event to this window? |
| 5707 | synchronized (this) { |
| 5708 | // First: did we come here based on the last window not |
| 5709 | // being null, but it changed by the time we got here? |
| 5710 | // If so, try again. |
| 5711 | if (!targetIsNew && mLastWin == null) { |
| 5712 | continue; |
| 5713 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | // We never dispatch events if not finished with the |
| 5716 | // last one, or the display is frozen. |
| 5717 | if (mFinished && !mDisplayFrozen) { |
| 5718 | // If event dispatching is disabled, then we |
| 5719 | // just consume the events. |
| 5720 | if (!mEventDispatching) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5721 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5722 | "Skipping event; dispatching disabled: " |
| 5723 | + nextKey + " " + nextMotion); |
| 5724 | return null; |
| 5725 | } |
| 5726 | if (targetWin != null) { |
| 5727 | // If this is a new target, and that target is not |
| 5728 | // paused or unresponsive, then all looks good to |
| 5729 | // handle the event. |
| 5730 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5731 | return targetWin; |
| 5732 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5733 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5734 | // If we didn't find a target window, and there is no |
| 5735 | // focused app window, then just eat the events. |
| 5736 | } else if (mFocusedApp == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5737 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | "Skipping event; no focused app: " |
| 5739 | + nextKey + " " + nextMotion); |
| 5740 | return null; |
| 5741 | } |
| 5742 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5743 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5744 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5745 | TAG, "Waiting for last key in " + mLastBinder |
| 5746 | + " target=" + targetWin |
| 5747 | + " mFinished=" + mFinished |
| 5748 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5749 | + " targetIsNew=" + targetIsNew |
| 5750 | + " paused=" |
| 5751 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5752 | + " mFocusedApp=" + mFocusedApp |
| 5753 | + " mCurrentFocus=" + mCurrentFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5754 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5755 | targetApp = targetWin != null |
| 5756 | ? targetWin.mAppToken : mFocusedApp; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5757 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | long curTimeout = keyDispatchingTimeout; |
| 5759 | if (mTimeToSwitch != 0) { |
| 5760 | long now = SystemClock.uptimeMillis(); |
| 5761 | if (mTimeToSwitch <= now) { |
| 5762 | // If an app switch key has been pressed, and we have |
| 5763 | // waited too long for the current app to finish |
| 5764 | // processing keys, then wait no more! |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 5765 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5766 | continue; |
| 5767 | } |
| 5768 | long switchTimeout = mTimeToSwitch - now; |
| 5769 | if (curTimeout > switchTimeout) { |
| 5770 | curTimeout = switchTimeout; |
| 5771 | } |
| 5772 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5773 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5774 | try { |
| 5775 | // after that continue |
| 5776 | // processing keys, so we don't get stuck. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5777 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5778 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5779 | wait(curTimeout); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5780 | if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5781 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5782 | + startTime + " switchTime=" + mTimeToSwitch |
| 5783 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5784 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5785 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5786 | } catch (InterruptedException e) { |
| 5787 | } |
| 5788 | } |
| 5789 | |
| 5790 | // If we were frozen during configuration change, restart the |
| 5791 | // timeout checks from now; otherwise look at whether we timed |
| 5792 | // out before awakening. |
| 5793 | if (mWasFrozen) { |
| 5794 | waitedFor = 0; |
| 5795 | mWasFrozen = false; |
| 5796 | } else { |
| 5797 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5798 | } |
| 5799 | |
| 5800 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5801 | IApplicationToken at = null; |
| 5802 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5803 | Slog.w(TAG, "Key dispatching timed out sending to " + |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5804 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 5805 | : "<null>: no window ready for key dispatch")); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5806 | // NOSHIP debugging |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5807 | Slog.w(TAG, "Previous dispatch state: " + mDispatchState); |
| 5808 | Slog.w(TAG, "Current dispatch state: " + |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 5809 | new DispatchState(nextKey, targetWin)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5810 | // END NOSHIP |
| 5811 | //dump(); |
| 5812 | if (targetWin != null) { |
| 5813 | at = targetWin.getAppToken(); |
| 5814 | } else if (targetApp != null) { |
| 5815 | at = targetApp.appToken; |
| 5816 | } |
| 5817 | } |
| 5818 | |
| 5819 | boolean abort = true; |
| 5820 | if (at != null) { |
| 5821 | try { |
| 5822 | long timeout = at.getKeyDispatchingTimeout(); |
| 5823 | if (timeout > waitedFor) { |
| 5824 | // we did not wait the proper amount of time for this application. |
| 5825 | // set the timeout to be the real timeout and wait again. |
| 5826 | keyDispatchingTimeout = timeout - waitedFor; |
| 5827 | continue; |
| 5828 | } else { |
| 5829 | abort = at.keyDispatchingTimedOut(); |
| 5830 | } |
| 5831 | } catch (RemoteException ex) { |
| 5832 | } |
| 5833 | } |
| 5834 | |
| 5835 | synchronized (this) { |
| 5836 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5837 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5838 | if (mLastWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5839 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5840 | "Window " + mLastWin + |
| 5841 | " timed out on key input"); |
| 5842 | if (mLastWin.mToken.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5843 | Slog.w(TAG, "Un-pausing dispatching to this window"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5844 | mLastWin.mToken.paused = false; |
| 5845 | } |
| 5846 | } |
| 5847 | if (mMotionTarget == targetWin) { |
| 5848 | mMotionTarget = null; |
| 5849 | } |
| 5850 | mLastWin = null; |
| 5851 | mLastBinder = null; |
| 5852 | if (failIfTimeout || targetWin == null) { |
| 5853 | return null; |
| 5854 | } |
| 5855 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5856 | 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] | 5857 | startTime = SystemClock.uptimeMillis(); |
| 5858 | } |
| 5859 | } |
| 5860 | } |
| 5861 | } |
| 5862 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5864 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5865 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5866 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5867 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5868 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | if (nextKey != null) { |
| 5870 | // Find the target window for a normal key event. |
| 5871 | final int keycode = nextKey.getKeyCode(); |
| 5872 | final int repeatCount = nextKey.getRepeatCount(); |
| 5873 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5874 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5875 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5876 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5877 | if (callingUid == 0 || |
| 5878 | mContext.checkPermission( |
| 5879 | android.Manifest.permission.INJECT_EVENTS, |
| 5880 | callingPid, callingUid) |
| 5881 | == PackageManager.PERMISSION_GRANTED) { |
| 5882 | mPolicy.interceptKeyTi(null, keycode, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5883 | nextKey.getMetaState(), down, repeatCount, |
| 5884 | nextKey.getFlags()); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5885 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5886 | Slog.w(TAG, "Event timeout during app switch: dropping " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5887 | + nextKey); |
| 5888 | return SKIP_TARGET_TOKEN; |
| 5889 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5890 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5891 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5893 | WindowState focus = null; |
| 5894 | synchronized(mWindowMap) { |
| 5895 | focus = getFocusedWindowLocked(); |
| 5896 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5897 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5898 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5899 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5900 | if (callingUid == 0 || |
| 5901 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5902 | mContext.checkPermission( |
| 5903 | android.Manifest.permission.INJECT_EVENTS, |
| 5904 | callingPid, callingUid) |
| 5905 | == PackageManager.PERMISSION_GRANTED) { |
| 5906 | if (mPolicy.interceptKeyTi(focus, |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5907 | keycode, nextKey.getMetaState(), down, repeatCount, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5908 | nextKey.getFlags())) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5909 | return CONSUMED_EVENT_TOKEN; |
| 5910 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5911 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5913 | return focus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5915 | } else if (!isPointerEvent) { |
| 5916 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5917 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5918 | 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] | 5919 | + nextMotion); |
| 5920 | return SKIP_TARGET_TOKEN; |
| 5921 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5923 | WindowState focus = null; |
| 5924 | synchronized(mWindowMap) { |
| 5925 | focus = getFocusedWindowLocked(); |
| 5926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5928 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5929 | return focus; |
| 5930 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | if (nextMotion == null) { |
| 5933 | return SKIP_TARGET_TOKEN; |
| 5934 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5935 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5936 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5937 | KeyEvent.KEYCODE_UNKNOWN); |
| 5938 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5939 | 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] | 5940 | + nextMotion); |
| 5941 | return SKIP_TARGET_TOKEN; |
| 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 | // Find the target window for a pointer event. |
| 5945 | int action = nextMotion.getAction(); |
| 5946 | final float xf = nextMotion.getX(); |
| 5947 | final float yf = nextMotion.getY(); |
| 5948 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5950 | final boolean screenWasOff = qev != null |
| 5951 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5952 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5953 | WindowState target = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5955 | synchronized(mWindowMap) { |
| 5956 | synchronized (this) { |
| 5957 | if (action == MotionEvent.ACTION_DOWN) { |
| 5958 | if (mMotionTarget != null) { |
| 5959 | // this is weird, we got a pen down, but we thought it was |
| 5960 | // already down! |
| 5961 | // XXX: We should probably send an ACTION_UP to the current |
| 5962 | // target. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5963 | 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] | 5964 | + mMotionTarget); |
| 5965 | mMotionTarget = null; |
| 5966 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5967 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5968 | // ACTION_DOWN is special, because we need to lock next events to |
| 5969 | // the window we'll land onto. |
| 5970 | final int x = (int)xf; |
| 5971 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5973 | final ArrayList windows = mWindows; |
| 5974 | final int N = windows.size(); |
| 5975 | WindowState topErrWindow = null; |
| 5976 | final Rect tmpRect = mTempRect; |
| 5977 | for (int i=N-1; i>=0; i--) { |
| 5978 | WindowState child = (WindowState)windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5979 | //Slog.i(TAG, "Checking dispatch to: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5980 | final int flags = child.mAttrs.flags; |
| 5981 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5982 | if (topErrWindow == null) { |
| 5983 | topErrWindow = child; |
| 5984 | } |
| 5985 | } |
| 5986 | if (!child.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5987 | //Slog.i(TAG, "Not visible!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5988 | continue; |
| 5989 | } |
| 5990 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5991 | //Slog.i(TAG, "Not touchable!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | if ((flags & WindowManager.LayoutParams |
| 5993 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5994 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5995 | mOutsideTouchTargets = child; |
| 5996 | } |
| 5997 | continue; |
| 5998 | } |
| 5999 | tmpRect.set(child.mFrame); |
| 6000 | if (child.mTouchableInsets == ViewTreeObserver |
| 6001 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 6002 | // The touch is inside of the window if it is |
| 6003 | // inside the frame, AND the content part of that |
| 6004 | // frame that was given by the application. |
| 6005 | tmpRect.left += child.mGivenContentInsets.left; |
| 6006 | tmpRect.top += child.mGivenContentInsets.top; |
| 6007 | tmpRect.right -= child.mGivenContentInsets.right; |
| 6008 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 6009 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 6010 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 6011 | // The touch is inside of the window if it is |
| 6012 | // inside the frame, AND the visible part of that |
| 6013 | // frame that was given by the application. |
| 6014 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 6015 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 6016 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 6017 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 6018 | } |
| 6019 | final int touchFlags = flags & |
| 6020 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 6021 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 6022 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6023 | //Slog.i(TAG, "Using this target!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6024 | if (!screenWasOff || (flags & |
| 6025 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 6026 | mMotionTarget = child; |
| 6027 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6028 | //Slog.i(TAG, "Waking, skip!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6029 | mMotionTarget = null; |
| 6030 | } |
| 6031 | break; |
| 6032 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6033 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6034 | if ((flags & WindowManager.LayoutParams |
| 6035 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 6036 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 6037 | mOutsideTouchTargets = child; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6038 | //Slog.i(TAG, "Adding to outside target list: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | } |
| 6040 | } |
| 6041 | |
| 6042 | // if there's an error window but it's not accepting |
| 6043 | // focus (typically because it is not yet visible) just |
| 6044 | // wait for it -- any other focused window may in fact |
| 6045 | // be in ANR state. |
| 6046 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 6047 | mMotionTarget = null; |
| 6048 | } |
| 6049 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6050 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6051 | target = mMotionTarget; |
| 6052 | } |
| 6053 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6054 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6055 | wakeupIfNeeded(target, eventType(nextMotion)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6057 | // Pointer events are a little different -- if there isn't a |
| 6058 | // target found for any event, then just drop it. |
| 6059 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 6060 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6061 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6062 | boolean checkShouldDispatchKey(int keycode) { |
| 6063 | synchronized (this) { |
| 6064 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 6065 | mTimeToSwitch = 0; |
| 6066 | return true; |
| 6067 | } |
| 6068 | if (mTimeToSwitch != 0 |
| 6069 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 6070 | return false; |
| 6071 | } |
| 6072 | return true; |
| 6073 | } |
| 6074 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6075 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6076 | void bindTargetWindowLocked(WindowState win, |
| 6077 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6078 | synchronized (this) { |
| 6079 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 6080 | } |
| 6081 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6082 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | void bindTargetWindowLocked(WindowState win) { |
| 6084 | synchronized (this) { |
| 6085 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 6086 | } |
| 6087 | } |
| 6088 | |
| 6089 | void bindTargetWindowLockedLocked(WindowState win, |
| 6090 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6091 | mLastWin = win; |
| 6092 | mLastBinder = win.mClient.asBinder(); |
| 6093 | mFinished = false; |
| 6094 | if (pendingMotion != null) { |
| 6095 | final Session s = win.mSession; |
| 6096 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 6097 | releasePendingPointerLocked(s); |
| 6098 | s.mPendingPointerMove = pendingMotion; |
| 6099 | s.mPendingPointerWindow = win; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6100 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 6102 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 6103 | releasePendingTrackballLocked(s); |
| 6104 | s.mPendingTrackballMove = pendingMotion; |
| 6105 | s.mPendingTrackballWindow = win; |
| 6106 | } |
| 6107 | } |
| 6108 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6110 | void releasePendingPointerLocked(Session s) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6111 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6112 | "releasePendingPointer " + s.mPendingPointerMove); |
| 6113 | if (s.mPendingPointerMove != null) { |
| 6114 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 6115 | s.mPendingPointerMove = null; |
| 6116 | } |
| 6117 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6118 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6119 | void releasePendingTrackballLocked(Session s) { |
| 6120 | if (s.mPendingTrackballMove != null) { |
| 6121 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 6122 | s.mPendingTrackballMove = null; |
| 6123 | } |
| 6124 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6125 | |
| Maciej Białka | 26824b7 | 2010-03-05 08:40:09 +0100 | [diff] [blame] | 6126 | void releaseMotionTarget(WindowState win) { |
| 6127 | if (mMotionTarget == win) { |
| 6128 | mMotionTarget = null; |
| 6129 | } |
| 6130 | } |
| 6131 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6132 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 6133 | int returnWhat) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6134 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6135 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 6136 | |
| 6137 | if (client == null) { |
| 6138 | return null; |
| 6139 | } |
| 6140 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6141 | MotionEvent res = null; |
| 6142 | QueuedEvent qev = null; |
| 6143 | WindowState win = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6144 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6145 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6146 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6147 | TAG, "finishedKey: client=" + client.asBinder() |
| 6148 | + ", force=" + force + ", last=" + mLastBinder |
| 6149 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 6150 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6151 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 6152 | qev = session.mPendingPointerMove; |
| 6153 | win = session.mPendingPointerWindow; |
| 6154 | session.mPendingPointerMove = null; |
| 6155 | session.mPendingPointerWindow = null; |
| 6156 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 6157 | qev = session.mPendingTrackballMove; |
| 6158 | win = session.mPendingTrackballWindow; |
| 6159 | session.mPendingTrackballMove = null; |
| 6160 | session.mPendingTrackballWindow = null; |
| 6161 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6162 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6163 | if (mLastBinder == client.asBinder()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6164 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6165 | TAG, "finishedKey: last paused=" |
| 6166 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 6167 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 6168 | || !mEventDispatching)) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6169 | doFinishedKeyLocked(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | } else { |
| 6171 | // Make sure to wake up anyone currently waiting to |
| 6172 | // dispatch a key, so they can re-evaluate their |
| 6173 | // current situation. |
| 6174 | mFinished = true; |
| 6175 | notifyAll(); |
| 6176 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6177 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6178 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6179 | if (qev != null) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6180 | res = (MotionEvent)qev.event; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6181 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6182 | "Returning pending motion: " + res); |
| 6183 | mQueue.recycleEvent(qev); |
| 6184 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6185 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 6186 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6187 | } |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6188 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6189 | |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6190 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6191 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 6192 | dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6193 | } |
| 6194 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6195 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6196 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | void tickle() { |
| 6200 | synchronized (this) { |
| 6201 | notifyAll(); |
| 6202 | } |
| 6203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6205 | void handleNewWindowLocked(WindowState newWindow) { |
| 6206 | if (!newWindow.canReceiveKeys()) { |
| 6207 | return; |
| 6208 | } |
| 6209 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6210 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6211 | TAG, "New key dispatch window: win=" |
| 6212 | + newWindow.mClient.asBinder() |
| 6213 | + ", last=" + mLastBinder |
| 6214 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6215 | + "), finished=" + mFinished + ", paused=" |
| 6216 | + newWindow.mToken.paused); |
| 6217 | |
| 6218 | // Displaying a window implicitly causes dispatching to |
| 6219 | // be unpaused. (This is to protect against bugs if someone |
| 6220 | // pauses dispatching but forgets to resume.) |
| 6221 | newWindow.mToken.paused = false; |
| 6222 | |
| 6223 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | |
| 6225 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6226 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6227 | "New SYSTEM_ERROR window; resetting state"); |
| 6228 | mLastWin = null; |
| 6229 | mLastBinder = null; |
| 6230 | mMotionTarget = null; |
| 6231 | mFinished = true; |
| 6232 | } else if (mLastWin != null) { |
| 6233 | // If the new window is above the window we are |
| 6234 | // waiting on, then stop waiting and let key dispatching |
| 6235 | // start on the new guy. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6236 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6237 | TAG, "Last win layer=" + mLastWin.mLayer |
| 6238 | + ", new win layer=" + newWindow.mLayer); |
| 6239 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6240 | // The new window is above the old; finish pending input to the last |
| 6241 | // window and start directing it to the new one. |
| 6242 | mLastWin.mToken.paused = false; |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6243 | doFinishedKeyLocked(false); // does a notifyAll() |
| 6244 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6245 | } |
| 6246 | } |
| 6247 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6248 | // Now that we've put a new window state in place, make the event waiter |
| 6249 | // take notice and retarget its attentions. |
| 6250 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | } |
| 6252 | } |
| 6253 | |
| 6254 | void pauseDispatchingLocked(WindowToken token) { |
| 6255 | synchronized (this) |
| 6256 | { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6257 | if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | token.paused = true; |
| 6259 | |
| 6260 | /* |
| 6261 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 6262 | mPaused = true; |
| 6263 | } else { |
| 6264 | if (mLastWin == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6265 | 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] | 6266 | } else if (mFinished) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6267 | 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] | 6268 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6269 | 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] | 6270 | } |
| 6271 | } |
| 6272 | */ |
| 6273 | } |
| 6274 | } |
| 6275 | |
| 6276 | void resumeDispatchingLocked(WindowToken token) { |
| 6277 | synchronized (this) { |
| 6278 | if (token.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6279 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6280 | TAG, "Resuming WindowToken " + token |
| 6281 | + ", last=" + mLastBinder |
| 6282 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6283 | + "), finished=" + mFinished + ", paused=" |
| 6284 | + token.paused); |
| 6285 | token.paused = false; |
| 6286 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6287 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6288 | } else { |
| 6289 | notifyAll(); |
| 6290 | } |
| 6291 | } |
| 6292 | } |
| 6293 | } |
| 6294 | |
| 6295 | void setEventDispatchingLocked(boolean enabled) { |
| 6296 | synchronized (this) { |
| 6297 | mEventDispatching = enabled; |
| 6298 | notifyAll(); |
| 6299 | } |
| 6300 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6302 | void appSwitchComing() { |
| 6303 | synchronized (this) { |
| 6304 | // Don't wait for more than .5 seconds for app to finish |
| 6305 | // processing the pending events. |
| 6306 | long now = SystemClock.uptimeMillis() + 500; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6307 | if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 6309 | mTimeToSwitch = now; |
| 6310 | } |
| 6311 | notifyAll(); |
| 6312 | } |
| 6313 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6314 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6315 | private final void doFinishedKeyLocked(boolean force) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6316 | if (mLastWin != null) { |
| 6317 | releasePendingPointerLocked(mLastWin.mSession); |
| 6318 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6319 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6320 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6321 | if (force || mLastWin == null || !mLastWin.mToken.paused |
| 6322 | || !mLastWin.isVisibleLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6323 | // If the current window has been paused, we aren't -really- |
| 6324 | // finished... so let the waiters still wait. |
| 6325 | mLastWin = null; |
| 6326 | mLastBinder = null; |
| 6327 | } |
| 6328 | mFinished = true; |
| 6329 | notifyAll(); |
| 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | private class KeyQ extends KeyInputQueue |
| 6334 | implements KeyInputQueue.FilterCallback { |
| 6335 | PowerManager.WakeLock mHoldingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6336 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6337 | KeyQ() { |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6338 | super(mContext, WindowManagerService.this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6339 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 6340 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 6341 | "KEEP_SCREEN_ON_FLAG"); |
| 6342 | mHoldingScreen.setReferenceCounted(false); |
| 6343 | } |
| 6344 | |
| 6345 | @Override |
| 6346 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6347 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6348 | return true; |
| 6349 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6350 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | switch (event.type) { |
| 6352 | case RawInputEvent.EV_KEY: { |
| 6353 | // XXX begin hack |
| 6354 | if (DEBUG) { |
| 6355 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6356 | if (event.value != 0) { |
| 6357 | // G down |
| 6358 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6359 | } |
| 6360 | return false; |
| 6361 | } |
| 6362 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6363 | if (event.value != 0) { |
| 6364 | //dump(); |
| 6365 | } |
| 6366 | return false; |
| 6367 | } |
| 6368 | } |
| 6369 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6370 | |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6371 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6372 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6373 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6374 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6375 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6376 | mPowerManager.goToSleep(event.when); |
| 6377 | } |
| 6378 | |
| 6379 | if (screenIsOff) { |
| 6380 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6381 | } |
| 6382 | if (screenIsDim) { |
| 6383 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6384 | } |
| 6385 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6386 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6387 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6388 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6390 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6391 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6392 | filterQueue(this); |
| 6393 | mKeyWaiter.appSwitchComing(); |
| 6394 | } |
| 6395 | return true; |
| 6396 | } else { |
| 6397 | return false; |
| 6398 | } |
| 6399 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | case RawInputEvent.EV_REL: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6402 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6403 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6404 | if (screenIsOff) { |
| 6405 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6406 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6407 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6408 | return false; |
| 6409 | } |
| 6410 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6411 | } |
| 6412 | if (screenIsDim) { |
| 6413 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6414 | } |
| 6415 | return true; |
| 6416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6418 | case RawInputEvent.EV_ABS: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6419 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6420 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6421 | if (screenIsOff) { |
| 6422 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6423 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6424 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6425 | return false; |
| 6426 | } |
| 6427 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6428 | } |
| 6429 | if (screenIsDim) { |
| 6430 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6431 | } |
| 6432 | return true; |
| 6433 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6435 | default: |
| 6436 | return true; |
| 6437 | } |
| 6438 | } |
| 6439 | |
| 6440 | public int filterEvent(QueuedEvent ev) { |
| 6441 | switch (ev.classType) { |
| 6442 | case RawInputEvent.CLASS_KEYBOARD: |
| 6443 | KeyEvent ke = (KeyEvent)ev.event; |
| 6444 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6445 | Slog.w(TAG, "Dropping movement key during app switch: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6446 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6447 | return FILTER_REMOVE; |
| 6448 | } |
| 6449 | return FILTER_ABORT; |
| 6450 | default: |
| 6451 | return FILTER_KEEP; |
| 6452 | } |
| 6453 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6454 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6455 | /** |
| 6456 | * Must be called with the main window manager lock held. |
| 6457 | */ |
| 6458 | void setHoldScreenLocked(boolean holding) { |
| 6459 | boolean state = mHoldingScreen.isHeld(); |
| 6460 | if (holding != state) { |
| 6461 | if (holding) { |
| 6462 | mHoldingScreen.acquire(); |
| 6463 | } else { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6464 | mPolicy.screenOnStoppedLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6465 | mHoldingScreen.release(); |
| 6466 | } |
| 6467 | } |
| 6468 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6469 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | |
| 6471 | public boolean detectSafeMode() { |
| 6472 | mSafeMode = mPolicy.detectSafeMode(); |
| 6473 | return mSafeMode; |
| 6474 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6475 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6476 | public void systemReady() { |
| 6477 | mPolicy.systemReady(); |
| 6478 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6480 | private final class InputDispatcherThread extends Thread { |
| 6481 | // Time to wait when there is nothing to do: 9999 seconds. |
| 6482 | static final int LONG_WAIT=9999*1000; |
| 6483 | |
| 6484 | public InputDispatcherThread() { |
| 6485 | super("InputDispatcher"); |
| 6486 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6487 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6488 | @Override |
| 6489 | public void run() { |
| 6490 | while (true) { |
| 6491 | try { |
| 6492 | process(); |
| 6493 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6494 | Slog.e(TAG, "Exception in input dispatcher", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6495 | } |
| 6496 | } |
| 6497 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6498 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6499 | private void process() { |
| 6500 | android.os.Process.setThreadPriority( |
| 6501 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6503 | // The last key event we saw |
| 6504 | KeyEvent lastKey = null; |
| 6505 | |
| 6506 | // Last keydown time for auto-repeating keys |
| 6507 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 6508 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6509 | long downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6511 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6512 | int keyRepeatCount = 0; |
| 6513 | |
| 6514 | // Need to report that configuration has changed? |
| 6515 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6516 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6517 | while (true) { |
| 6518 | long curTime = SystemClock.uptimeMillis(); |
| 6519 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6520 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | TAG, "Waiting for next key: now=" + curTime |
| 6522 | + ", repeat @ " + nextKeyTime); |
| 6523 | |
| 6524 | // Retrieve next event, waiting only as long as the next |
| 6525 | // repeat timeout. If the configuration has changed, then |
| 6526 | // don't wait at all -- we'll report the change as soon as |
| 6527 | // we have processed all events. |
| 6528 | QueuedEvent ev = mQueue.getEvent( |
| 6529 | (int)((!configChanged && curTime < nextKeyTime) |
| 6530 | ? (nextKeyTime-curTime) : 0)); |
| 6531 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6532 | if (DEBUG_INPUT && ev != null) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 6534 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6535 | if (MEASURE_LATENCY) { |
| 6536 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 6537 | } |
| 6538 | |
| Mike Lockwood | 3d0ea72 | 2009-10-21 22:58:29 -0400 | [diff] [blame] | 6539 | if (lastKey != null && !mPolicy.allowKeyRepeat()) { |
| 6540 | // cancel key repeat at the request of the policy. |
| 6541 | lastKey = null; |
| 6542 | downTime = 0; |
| 6543 | lastKeyTime = curTime; |
| 6544 | nextKeyTime = curTime + LONG_WAIT; |
| 6545 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6546 | try { |
| 6547 | if (ev != null) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6548 | curTime = SystemClock.uptimeMillis(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6549 | int eventType; |
| 6550 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 6551 | eventType = eventType((MotionEvent)ev.event); |
| 6552 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 6553 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 6554 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 6555 | } else { |
| 6556 | eventType = LocalPowerManager.OTHER_EVENT; |
| 6557 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6558 | try { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6559 | if ((curTime - mLastBatteryStatsCallTime) |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6560 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6561 | mLastBatteryStatsCallTime = curTime; |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6562 | mBatteryStats.noteInputEvent(); |
| 6563 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6564 | } catch (RemoteException e) { |
| 6565 | // Ignore |
| 6566 | } |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6567 | |
| Mike Lockwood | 5db4240 | 2009-11-30 14:51:51 -0500 | [diff] [blame] | 6568 | if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) { |
| 6569 | // do not wake screen in this case |
| 6570 | } else if (eventType != TOUCH_EVENT |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6571 | && eventType != LONG_TOUCH_EVENT |
| 6572 | && eventType != CHEEK_EVENT) { |
| 6573 | mPowerManager.userActivity(curTime, false, |
| 6574 | eventType, false); |
| 6575 | } else if (mLastTouchEventType != eventType |
| 6576 | || (curTime - mLastUserActivityCallTime) |
| 6577 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 6578 | mLastUserActivityCallTime = curTime; |
| 6579 | mLastTouchEventType = eventType; |
| 6580 | mPowerManager.userActivity(curTime, false, |
| 6581 | eventType, false); |
| 6582 | } |
| 6583 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6584 | switch (ev.classType) { |
| 6585 | case RawInputEvent.CLASS_KEYBOARD: |
| 6586 | KeyEvent ke = (KeyEvent)ev.event; |
| 6587 | if (ke.isDown()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6588 | lastKeyTime = curTime; |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6589 | if (lastKey != null && |
| 6590 | ke.getKeyCode() == lastKey.getKeyCode()) { |
| 6591 | keyRepeatCount++; |
| 6592 | // Arbitrary long timeout to block |
| 6593 | // repeating here since we know that |
| 6594 | // the device driver takes care of it. |
| 6595 | nextKeyTime = lastKeyTime + LONG_WAIT; |
| The Android Open Source Project | 2a9ae01 | 2010-05-12 12:33:35 -0700 | [diff] [blame] | 6596 | if (DEBUG_INPUT) Slog.v( |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6597 | TAG, "Received repeated key down"); |
| 6598 | } else { |
| 6599 | downTime = curTime; |
| 6600 | keyRepeatCount = 0; |
| 6601 | nextKeyTime = lastKeyTime |
| 6602 | + ViewConfiguration.getLongPressTimeout(); |
| The Android Open Source Project | 2a9ae01 | 2010-05-12 12:33:35 -0700 | [diff] [blame] | 6603 | if (DEBUG_INPUT) Slog.v( |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6604 | TAG, "Received key down: first repeat @ " |
| 6605 | + nextKeyTime); |
| 6606 | } |
| 6607 | lastKey = ke; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6608 | } else { |
| 6609 | lastKey = null; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6610 | downTime = 0; |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6611 | keyRepeatCount = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6612 | // Arbitrary long timeout. |
| 6613 | lastKeyTime = curTime; |
| 6614 | nextKeyTime = curTime + LONG_WAIT; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6615 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6616 | TAG, "Received key up: ignore repeat @ " |
| 6617 | + nextKeyTime); |
| 6618 | } |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6619 | if (keyRepeatCount > 0) { |
| 6620 | dispatchKey(KeyEvent.changeTimeRepeat(ke, |
| 6621 | ke.getEventTime(), keyRepeatCount), 0, 0); |
| 6622 | } else { |
| 6623 | dispatchKey(ke, 0, 0); |
| 6624 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6625 | mQueue.recycleEvent(ev); |
| 6626 | break; |
| 6627 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6628 | //Slog.i(TAG, "Read next event " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6629 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 6630 | break; |
| 6631 | case RawInputEvent.CLASS_TRACKBALL: |
| 6632 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 6633 | break; |
| 6634 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 6635 | configChanged = true; |
| 6636 | break; |
| 6637 | default: |
| 6638 | mQueue.recycleEvent(ev); |
| 6639 | break; |
| 6640 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6641 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6642 | } else if (configChanged) { |
| 6643 | configChanged = false; |
| 6644 | sendNewConfiguration(); |
| 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 | } else if (lastKey != null) { |
| 6647 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6648 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6649 | // Timeout occurred while key was down. If it is at or |
| 6650 | // past the key repeat time, dispatch the repeat. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6651 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 6653 | + ", now=" + curTime); |
| 6654 | if (curTime < nextKeyTime) { |
| 6655 | continue; |
| 6656 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6657 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6658 | lastKeyTime = nextKeyTime; |
| 6659 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 6660 | keyRepeatCount++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6661 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6662 | TAG, "Key repeat: count=" + keyRepeatCount |
| 6663 | + ", next @ " + nextKeyTime); |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6664 | KeyEvent newEvent; |
| 6665 | if (downTime != 0 && (downTime |
| 6666 | + ViewConfiguration.getLongPressTimeout()) |
| 6667 | <= curTime) { |
| 6668 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6669 | curTime, keyRepeatCount, |
| 6670 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6671 | downTime = 0; |
| 6672 | } else { |
| 6673 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6674 | curTime, keyRepeatCount); |
| 6675 | } |
| 6676 | dispatchKey(newEvent, 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6677 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6678 | } else { |
| 6679 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6681 | lastKeyTime = curTime; |
| 6682 | nextKeyTime = curTime + LONG_WAIT; |
| 6683 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6685 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6686 | Slog.e(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6687 | "Input thread received uncaught exception: " + e, e); |
| 6688 | } |
| 6689 | } |
| 6690 | } |
| 6691 | } |
| 6692 | |
| 6693 | // ------------------------------------------------------------- |
| 6694 | // Client Session State |
| 6695 | // ------------------------------------------------------------- |
| 6696 | |
| 6697 | private final class Session extends IWindowSession.Stub |
| 6698 | implements IBinder.DeathRecipient { |
| 6699 | final IInputMethodClient mClient; |
| 6700 | final IInputContext mInputContext; |
| 6701 | final int mUid; |
| 6702 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6703 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6704 | SurfaceSession mSurfaceSession; |
| 6705 | int mNumWindow = 0; |
| 6706 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6707 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | /** |
| 6709 | * Current pointer move event being dispatched to client window... must |
| 6710 | * hold key lock to access. |
| 6711 | */ |
| 6712 | QueuedEvent mPendingPointerMove; |
| 6713 | WindowState mPendingPointerWindow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | /** |
| 6716 | * Current trackball move event being dispatched to client window... must |
| 6717 | * hold key lock to access. |
| 6718 | */ |
| 6719 | QueuedEvent mPendingTrackballMove; |
| 6720 | WindowState mPendingTrackballWindow; |
| 6721 | |
| 6722 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6723 | mClient = client; |
| 6724 | mInputContext = inputContext; |
| 6725 | mUid = Binder.getCallingUid(); |
| 6726 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6727 | StringBuilder sb = new StringBuilder(); |
| 6728 | sb.append("Session{"); |
| 6729 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6730 | sb.append(" uid "); |
| 6731 | sb.append(mUid); |
| 6732 | sb.append("}"); |
| 6733 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6734 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6735 | synchronized (mWindowMap) { |
| 6736 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6737 | IBinder b = ServiceManager.getService( |
| 6738 | Context.INPUT_METHOD_SERVICE); |
| 6739 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6740 | } |
| 6741 | } |
| 6742 | long ident = Binder.clearCallingIdentity(); |
| 6743 | try { |
| 6744 | // Note: it is safe to call in to the input method manager |
| 6745 | // here because we are not holding our lock. |
| 6746 | if (mInputMethodManager != null) { |
| 6747 | mInputMethodManager.addClient(client, inputContext, |
| 6748 | mUid, mPid); |
| 6749 | } else { |
| 6750 | client.setUsingInputMethod(false); |
| 6751 | } |
| 6752 | client.asBinder().linkToDeath(this, 0); |
| 6753 | } catch (RemoteException e) { |
| 6754 | // The caller has died, so we can just forget about this. |
| 6755 | try { |
| 6756 | if (mInputMethodManager != null) { |
| 6757 | mInputMethodManager.removeClient(client); |
| 6758 | } |
| 6759 | } catch (RemoteException ee) { |
| 6760 | } |
| 6761 | } finally { |
| 6762 | Binder.restoreCallingIdentity(ident); |
| 6763 | } |
| 6764 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6765 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | @Override |
| 6767 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6768 | throws RemoteException { |
| 6769 | try { |
| 6770 | return super.onTransact(code, data, reply, flags); |
| 6771 | } catch (RuntimeException e) { |
| 6772 | // Log all 'real' exceptions thrown to the caller |
| 6773 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6774 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6775 | } |
| 6776 | throw e; |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | public void binderDied() { |
| 6781 | // Note: it is safe to call in to the input method manager |
| 6782 | // here because we are not holding our lock. |
| 6783 | try { |
| 6784 | if (mInputMethodManager != null) { |
| 6785 | mInputMethodManager.removeClient(mClient); |
| 6786 | } |
| 6787 | } catch (RemoteException e) { |
| 6788 | } |
| 6789 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6790 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | mClientDead = true; |
| 6792 | killSessionLocked(); |
| 6793 | } |
| 6794 | } |
| 6795 | |
| 6796 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6797 | int viewVisibility, Rect outContentInsets) { |
| 6798 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6799 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6800 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6801 | public void remove(IWindow window) { |
| 6802 | removeWindow(this, window); |
| 6803 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6805 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6806 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6807 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6808 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6809 | return relayoutWindow(this, window, attrs, |
| 6810 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6811 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6812 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6814 | public void setTransparentRegion(IWindow window, Region region) { |
| 6815 | setTransparentRegionWindow(this, window, region); |
| 6816 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6818 | public void setInsets(IWindow window, int touchableInsets, |
| 6819 | Rect contentInsets, Rect visibleInsets) { |
| 6820 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6821 | visibleInsets); |
| 6822 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6823 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6824 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6825 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6826 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6827 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6828 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6829 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6830 | TAG, "IWindow finishDrawing called for " + window); |
| 6831 | finishDrawingWindow(this, window); |
| 6832 | } |
| 6833 | |
| 6834 | public void finishKey(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6835 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | TAG, "IWindow finishKey called for " + window); |
| 6837 | mKeyWaiter.finishedKey(this, window, false, |
| 6838 | KeyWaiter.RETURN_NOTHING); |
| 6839 | } |
| 6840 | |
| 6841 | public MotionEvent getPendingPointerMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6842 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6843 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6844 | return mKeyWaiter.finishedKey(this, window, false, |
| 6845 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6846 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6847 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6849 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6851 | return mKeyWaiter.finishedKey(this, window, false, |
| 6852 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6853 | } |
| 6854 | |
| 6855 | public void setInTouchMode(boolean mode) { |
| 6856 | synchronized(mWindowMap) { |
| 6857 | mInTouchMode = mode; |
| 6858 | } |
| 6859 | } |
| 6860 | |
| 6861 | public boolean getInTouchMode() { |
| 6862 | synchronized(mWindowMap) { |
| 6863 | return mInTouchMode; |
| 6864 | } |
| 6865 | } |
| 6866 | |
| 6867 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6868 | boolean always) { |
| 6869 | synchronized(mWindowMap) { |
| 6870 | long ident = Binder.clearCallingIdentity(); |
| 6871 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6872 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6873 | windowForClientLocked(this, window, true), |
| 6874 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | } finally { |
| 6876 | Binder.restoreCallingIdentity(ident); |
| 6877 | } |
| 6878 | } |
| 6879 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6880 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6881 | 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] | 6882 | synchronized(mWindowMap) { |
| 6883 | long ident = Binder.clearCallingIdentity(); |
| 6884 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6885 | setWindowWallpaperPositionLocked( |
| 6886 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6887 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6888 | } finally { |
| 6889 | Binder.restoreCallingIdentity(ident); |
| 6890 | } |
| 6891 | } |
| 6892 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6893 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6894 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6895 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6896 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6897 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6898 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6899 | int z, Bundle extras, boolean sync) { |
| 6900 | synchronized(mWindowMap) { |
| 6901 | long ident = Binder.clearCallingIdentity(); |
| 6902 | try { |
| 6903 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6904 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6905 | action, x, y, z, extras, sync); |
| 6906 | } finally { |
| 6907 | Binder.restoreCallingIdentity(ident); |
| 6908 | } |
| 6909 | } |
| 6910 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6911 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6912 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6913 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6914 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6916 | void windowAddedLocked() { |
| 6917 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6918 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6919 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6920 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6921 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6922 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6923 | mSessions.add(this); |
| 6924 | } |
| 6925 | mNumWindow++; |
| 6926 | } |
| 6927 | |
| 6928 | void windowRemovedLocked() { |
| 6929 | mNumWindow--; |
| 6930 | killSessionLocked(); |
| 6931 | } |
| 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 | void killSessionLocked() { |
| 6934 | if (mNumWindow <= 0 && mClientDead) { |
| 6935 | mSessions.remove(this); |
| 6936 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6937 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6938 | TAG, "Last window removed from " + this |
| 6939 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6940 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6941 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6942 | try { |
| 6943 | mSurfaceSession.kill(); |
| 6944 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6945 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | + mSurfaceSession + " in session " + this |
| 6947 | + ": " + e.toString()); |
| 6948 | } |
| 6949 | mSurfaceSession = null; |
| 6950 | } |
| 6951 | } |
| 6952 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6953 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6954 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6955 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6956 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6957 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6958 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6959 | pw.print(prefix); |
| 6960 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6961 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6962 | } |
| 6963 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6964 | pw.print(prefix); |
| 6965 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6966 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6967 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | @Override |
| 6971 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6972 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6973 | } |
| 6974 | } |
| 6975 | |
| 6976 | // ------------------------------------------------------------- |
| 6977 | // Client Window State |
| 6978 | // ------------------------------------------------------------- |
| 6979 | |
| 6980 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6981 | final Session mSession; |
| 6982 | final IWindow mClient; |
| 6983 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6984 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6985 | AppWindowToken mAppToken; |
| 6986 | AppWindowToken mTargetAppToken; |
| 6987 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6988 | final DeathRecipient mDeathRecipient; |
| 6989 | final WindowState mAttachedWindow; |
| 6990 | final ArrayList mChildWindows = new ArrayList(); |
| 6991 | final int mBaseLayer; |
| 6992 | final int mSubLayer; |
| 6993 | final boolean mLayoutAttached; |
| 6994 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6995 | final boolean mIsWallpaper; |
| 6996 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6997 | int mViewVisibility; |
| 6998 | boolean mPolicyVisibility = true; |
| 6999 | boolean mPolicyVisibilityAfterAnim = true; |
| 7000 | boolean mAppFreezing; |
| 7001 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7002 | boolean mReportDestroySurface; |
| 7003 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7004 | boolean mAttachedHidden; // is our parent window hidden? |
| 7005 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7006 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7007 | int mRequestedWidth; |
| 7008 | int mRequestedHeight; |
| 7009 | int mLastRequestedWidth; |
| 7010 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7011 | int mLayer; |
| 7012 | int mAnimLayer; |
| 7013 | int mLastLayer; |
| 7014 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7015 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7016 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7017 | |
| 7018 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7019 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7020 | int mLayoutSeq = -1; |
| 7021 | |
| 7022 | Configuration mConfiguration = null; |
| 7023 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7024 | // Actual frame shown on-screen (may be modified by animation) |
| 7025 | final Rect mShownFrame = new Rect(); |
| 7026 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7027 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7028 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7029 | * Set when we have changed the size of the surface, to know that |
| 7030 | * we must tell them application to resize (and thus redraw itself). |
| 7031 | */ |
| 7032 | boolean mSurfaceResized; |
| 7033 | |
| 7034 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7035 | * Insets that determine the actually visible area |
| 7036 | */ |
| 7037 | final Rect mVisibleInsets = new Rect(); |
| 7038 | final Rect mLastVisibleInsets = new Rect(); |
| 7039 | boolean mVisibleInsetsChanged; |
| 7040 | |
| 7041 | /** |
| 7042 | * Insets that are covered by system windows |
| 7043 | */ |
| 7044 | final Rect mContentInsets = new Rect(); |
| 7045 | final Rect mLastContentInsets = new Rect(); |
| 7046 | boolean mContentInsetsChanged; |
| 7047 | |
| 7048 | /** |
| 7049 | * Set to true if we are waiting for this window to receive its |
| 7050 | * given internal insets before laying out other windows based on it. |
| 7051 | */ |
| 7052 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7053 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7054 | /** |
| 7055 | * These are the content insets that were given during layout for |
| 7056 | * this window, to be applied to windows behind it. |
| 7057 | */ |
| 7058 | final Rect mGivenContentInsets = new Rect(); |
| 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 | /** |
| 7061 | * These are the visible insets that were given during layout for |
| 7062 | * this window, to be applied to windows behind it. |
| 7063 | */ |
| 7064 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7065 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7066 | /** |
| 7067 | * Flag indicating whether the touchable region should be adjusted by |
| 7068 | * the visible insets; if false the area outside the visible insets is |
| 7069 | * NOT touchable, so we must use those to adjust the frame during hit |
| 7070 | * tests. |
| 7071 | */ |
| 7072 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7073 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | // Current transformation being applied. |
| 7075 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 7076 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 7077 | float mHScale=1, mVScale=1; |
| 7078 | float mLastHScale=1, mLastVScale=1; |
| 7079 | final Matrix mTmpMatrix = new Matrix(); |
| 7080 | |
| 7081 | // "Real" frame that the application sees. |
| 7082 | final Rect mFrame = new Rect(); |
| 7083 | final Rect mLastFrame = new Rect(); |
| 7084 | |
| 7085 | final Rect mContainingFrame = new Rect(); |
| 7086 | final Rect mDisplayFrame = new Rect(); |
| 7087 | final Rect mContentFrame = new Rect(); |
| 7088 | final Rect mVisibleFrame = new Rect(); |
| 7089 | |
| 7090 | float mShownAlpha = 1; |
| 7091 | float mAlpha = 1; |
| 7092 | float mLastAlpha = 1; |
| 7093 | |
| 7094 | // Set to true if, when the window gets displayed, it should perform |
| 7095 | // an enter animation. |
| 7096 | boolean mEnterAnimationPending; |
| 7097 | |
| 7098 | // Currently running animation. |
| 7099 | boolean mAnimating; |
| 7100 | boolean mLocalAnimating; |
| 7101 | Animation mAnimation; |
| 7102 | boolean mAnimationIsEntrance; |
| 7103 | boolean mHasTransformation; |
| 7104 | boolean mHasLocalTransformation; |
| 7105 | final Transformation mTransformation = new Transformation(); |
| 7106 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7107 | // If a window showing a wallpaper: the requested offset for the |
| 7108 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 7109 | float mWallpaperX = -1; |
| 7110 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7111 | |
| 7112 | // If a window showing a wallpaper: what fraction of the offset |
| 7113 | // range corresponds to a full virtual screen. |
| 7114 | float mWallpaperXStep = -1; |
| 7115 | float mWallpaperYStep = -1; |
| 7116 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7117 | // Wallpaper windows: pixels offset based on above variables. |
| 7118 | int mXOffset; |
| 7119 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7120 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7121 | // This is set after IWindowSession.relayout() has been called at |
| 7122 | // least once for the window. It allows us to detect the situation |
| 7123 | // where we don't yet have a surface, but should have one soon, so |
| 7124 | // we can give the window focus before waiting for the relayout. |
| 7125 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7126 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7127 | // This is set after the Surface has been created but before the |
| 7128 | // window has been drawn. During this time the surface is hidden. |
| 7129 | boolean mDrawPending; |
| 7130 | |
| 7131 | // This is set after the window has finished drawing for the first |
| 7132 | // time but before its surface is shown. The surface will be |
| 7133 | // displayed when the next layout is run. |
| 7134 | boolean mCommitDrawPending; |
| 7135 | |
| 7136 | // This is set during the time after the window's drawing has been |
| 7137 | // committed, and before its surface is actually shown. It is used |
| 7138 | // to delay showing the surface until all windows in a token are ready |
| 7139 | // to be shown. |
| 7140 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7141 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7142 | // Set when the window has been shown in the screen the first time. |
| 7143 | boolean mHasDrawn; |
| 7144 | |
| 7145 | // Currently running an exit animation? |
| 7146 | boolean mExiting; |
| 7147 | |
| 7148 | // Currently on the mDestroySurface list? |
| 7149 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7150 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7151 | // Completely remove from window manager after exit animation? |
| 7152 | boolean mRemoveOnExit; |
| 7153 | |
| 7154 | // Set when the orientation is changing and this window has not yet |
| 7155 | // been updated for the new orientation. |
| 7156 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7157 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7158 | // Is this window now (or just being) removed? |
| 7159 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7160 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7161 | // For debugging, this is the last information given to the surface flinger. |
| 7162 | boolean mSurfaceShown; |
| 7163 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 7164 | int mSurfaceLayer; |
| 7165 | float mSurfaceAlpha; |
| 7166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7167 | WindowState(Session s, IWindow c, WindowToken token, |
| 7168 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 7169 | int viewVisibility) { |
| 7170 | mSession = s; |
| 7171 | mClient = c; |
| 7172 | mToken = token; |
| 7173 | mAttrs.copyFrom(a); |
| 7174 | mViewVisibility = viewVisibility; |
| 7175 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 7176 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7177 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7178 | TAG, "Window " + this + " client=" + c.asBinder() |
| 7179 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 7180 | try { |
| 7181 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 7182 | } catch (RemoteException e) { |
| 7183 | mDeathRecipient = null; |
| 7184 | mAttachedWindow = null; |
| 7185 | mLayoutAttached = false; |
| 7186 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7187 | mIsWallpaper = false; |
| 7188 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7189 | mBaseLayer = 0; |
| 7190 | mSubLayer = 0; |
| 7191 | return; |
| 7192 | } |
| 7193 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7194 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7196 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7197 | // The multiplier here is to reserve space for multiple |
| 7198 | // windows in the same type layer. |
| 7199 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7200 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7201 | + TYPE_LAYER_OFFSET; |
| 7202 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7203 | mAttachedWindow = attachedWindow; |
| 7204 | mAttachedWindow.mChildWindows.add(this); |
| 7205 | mLayoutAttached = mAttrs.type != |
| 7206 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7207 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7208 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7209 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7210 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7211 | } else { |
| 7212 | // The multiplier here is to reserve space for multiple |
| 7213 | // windows in the same type layer. |
| 7214 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7215 | * TYPE_LAYER_MULTIPLIER |
| 7216 | + TYPE_LAYER_OFFSET; |
| 7217 | mSubLayer = 0; |
| 7218 | mAttachedWindow = null; |
| 7219 | mLayoutAttached = false; |
| 7220 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7221 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7222 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7223 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7224 | } |
| 7225 | |
| 7226 | WindowState appWin = this; |
| 7227 | while (appWin.mAttachedWindow != null) { |
| 7228 | appWin = mAttachedWindow; |
| 7229 | } |
| 7230 | WindowToken appToken = appWin.mToken; |
| 7231 | while (appToken.appWindowToken == null) { |
| 7232 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7233 | if (parent == null || appToken == parent) { |
| 7234 | break; |
| 7235 | } |
| 7236 | appToken = parent; |
| 7237 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7238 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | mAppToken = appToken.appWindowToken; |
| 7240 | |
| 7241 | mSurface = null; |
| 7242 | mRequestedWidth = 0; |
| 7243 | mRequestedHeight = 0; |
| 7244 | mLastRequestedWidth = 0; |
| 7245 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7246 | mXOffset = 0; |
| 7247 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7248 | mLayer = 0; |
| 7249 | mAnimLayer = 0; |
| 7250 | mLastLayer = 0; |
| 7251 | } |
| 7252 | |
| 7253 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7254 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7255 | TAG, "Attaching " + this + " token=" + mToken |
| 7256 | + ", list=" + mToken.windows); |
| 7257 | mSession.windowAddedLocked(); |
| 7258 | } |
| 7259 | |
| 7260 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7261 | mHaveFrame = true; |
| 7262 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7263 | final Rect container = mContainingFrame; |
| 7264 | container.set(pf); |
| 7265 | |
| 7266 | final Rect display = mDisplayFrame; |
| 7267 | display.set(df); |
| 7268 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7269 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7270 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7271 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7272 | display.intersect(mCompatibleScreenFrame); |
| 7273 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7274 | } |
| 7275 | |
| 7276 | final int pw = container.right - container.left; |
| 7277 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7278 | |
| 7279 | int w,h; |
| 7280 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7281 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7282 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7283 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7284 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7285 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7288 | final Rect content = mContentFrame; |
| 7289 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7290 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7291 | final Rect visible = mVisibleFrame; |
| 7292 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7294 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7295 | final int fw = frame.width(); |
| 7296 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7297 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7298 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7299 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7300 | |
| 7301 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7302 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7303 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7304 | |
| 7305 | //System.out.println("Out: " + mFrame); |
| 7306 | |
| 7307 | // Now make sure the window fits in the overall display. |
| 7308 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7310 | // Make sure the content and visible frames are inside of the |
| 7311 | // final window frame. |
| 7312 | if (content.left < frame.left) content.left = frame.left; |
| 7313 | if (content.top < frame.top) content.top = frame.top; |
| 7314 | if (content.right > frame.right) content.right = frame.right; |
| 7315 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7316 | if (visible.left < frame.left) visible.left = frame.left; |
| 7317 | if (visible.top < frame.top) visible.top = frame.top; |
| 7318 | if (visible.right > frame.right) visible.right = frame.right; |
| 7319 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7321 | final Rect contentInsets = mContentInsets; |
| 7322 | contentInsets.left = content.left-frame.left; |
| 7323 | contentInsets.top = content.top-frame.top; |
| 7324 | contentInsets.right = frame.right-content.right; |
| 7325 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7327 | final Rect visibleInsets = mVisibleInsets; |
| 7328 | visibleInsets.left = visible.left-frame.left; |
| 7329 | visibleInsets.top = visible.top-frame.top; |
| 7330 | visibleInsets.right = frame.right-visible.right; |
| 7331 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7332 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7333 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7334 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7335 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7336 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7337 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7338 | if (localLOGV) { |
| 7339 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7340 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7341 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | + mRequestedWidth + ", mRequestedheight=" |
| 7343 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7344 | + "): frame=" + mFrame.toShortString() |
| 7345 | + " ci=" + contentInsets.toShortString() |
| 7346 | + " vi=" + visibleInsets.toShortString()); |
| 7347 | //} |
| 7348 | } |
| 7349 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7350 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7351 | public Rect getFrameLw() { |
| 7352 | return mFrame; |
| 7353 | } |
| 7354 | |
| 7355 | public Rect getShownFrameLw() { |
| 7356 | return mShownFrame; |
| 7357 | } |
| 7358 | |
| 7359 | public Rect getDisplayFrameLw() { |
| 7360 | return mDisplayFrame; |
| 7361 | } |
| 7362 | |
| 7363 | public Rect getContentFrameLw() { |
| 7364 | return mContentFrame; |
| 7365 | } |
| 7366 | |
| 7367 | public Rect getVisibleFrameLw() { |
| 7368 | return mVisibleFrame; |
| 7369 | } |
| 7370 | |
| 7371 | public boolean getGivenInsetsPendingLw() { |
| 7372 | return mGivenInsetsPending; |
| 7373 | } |
| 7374 | |
| 7375 | public Rect getGivenContentInsetsLw() { |
| 7376 | return mGivenContentInsets; |
| 7377 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7378 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | public Rect getGivenVisibleInsetsLw() { |
| 7380 | return mGivenVisibleInsets; |
| 7381 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7382 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | public WindowManager.LayoutParams getAttrs() { |
| 7384 | return mAttrs; |
| 7385 | } |
| 7386 | |
| 7387 | public int getSurfaceLayer() { |
| 7388 | return mLayer; |
| 7389 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7390 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7391 | public IApplicationToken getAppToken() { |
| 7392 | return mAppToken != null ? mAppToken.appToken : null; |
| 7393 | } |
| 7394 | |
| 7395 | public boolean hasAppShownWindows() { |
| 7396 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7397 | } |
| 7398 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7399 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7400 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7401 | TAG, "Setting animation in " + this + ": " + anim); |
| 7402 | mAnimating = false; |
| 7403 | mLocalAnimating = false; |
| 7404 | mAnimation = anim; |
| 7405 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7406 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7407 | } |
| 7408 | |
| 7409 | public void clearAnimation() { |
| 7410 | if (mAnimation != null) { |
| 7411 | mAnimating = true; |
| 7412 | mLocalAnimating = false; |
| 7413 | mAnimation = null; |
| 7414 | } |
| 7415 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7417 | Surface createSurfaceLocked() { |
| 7418 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7419 | mReportDestroySurface = false; |
| 7420 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7421 | mDrawPending = true; |
| 7422 | mCommitDrawPending = false; |
| 7423 | mReadyToShow = false; |
| 7424 | if (mAppToken != null) { |
| 7425 | mAppToken.allDrawn = false; |
| 7426 | } |
| 7427 | |
| 7428 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7429 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7430 | flags |= Surface.PUSH_BUFFERS; |
| 7431 | } |
| 7432 | |
| 7433 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7434 | flags |= Surface.SECURE; |
| 7435 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7436 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7437 | TAG, "Creating surface in session " |
| 7438 | + mSession.mSurfaceSession + " window " + this |
| 7439 | + " w=" + mFrame.width() |
| 7440 | + " h=" + mFrame.height() + " format=" |
| 7441 | + mAttrs.format + " flags=" + flags); |
| 7442 | |
| 7443 | int w = mFrame.width(); |
| 7444 | int h = mFrame.height(); |
| 7445 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7446 | // for a scaled surface, we always want the requested |
| 7447 | // size. |
| 7448 | w = mRequestedWidth; |
| 7449 | h = mRequestedHeight; |
| 7450 | } |
| 7451 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7452 | // Something is wrong and SurfaceFlinger will not like this, |
| 7453 | // try to revert to sane values |
| 7454 | if (w <= 0) w = 1; |
| 7455 | if (h <= 0) h = 1; |
| 7456 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7457 | mSurfaceShown = false; |
| 7458 | mSurfaceLayer = 0; |
| 7459 | mSurfaceAlpha = 1; |
| 7460 | mSurfaceX = 0; |
| 7461 | mSurfaceY = 0; |
| 7462 | mSurfaceW = w; |
| 7463 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | try { |
| 7465 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7466 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7467 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7468 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7469 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7470 | + mSurface + " IN SESSION " |
| 7471 | + mSession.mSurfaceSession |
| 7472 | + ": pid=" + mSession.mPid + " format=" |
| 7473 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7474 | + Integer.toHexString(flags) |
| 7475 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7476 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7477 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7478 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7479 | return null; |
| 7480 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7481 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7482 | return null; |
| 7483 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7484 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7485 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7486 | TAG, "Got surface: " + mSurface |
| 7487 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7488 | + ", animLayer=" + mAnimLayer); |
| 7489 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7490 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7491 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 7492 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 7493 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7494 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | } |
| 7496 | Surface.openTransaction(); |
| 7497 | try { |
| 7498 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7499 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7500 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7501 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7502 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7504 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7505 | mSurface.hide(); |
| 7506 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7507 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7508 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7509 | Surface.SURFACE_DITHER); |
| 7510 | } |
| 7511 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7512 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7513 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7514 | } |
| 7515 | mLastHidden = true; |
| 7516 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7517 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | Surface.closeTransaction(); |
| 7519 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7520 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7521 | TAG, "Created surface " + this); |
| 7522 | } |
| 7523 | return mSurface; |
| 7524 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | void destroySurfaceLocked() { |
| 7527 | // Window is no longer on-screen, so can no longer receive |
| 7528 | // key events... if we were waiting for it to finish |
| 7529 | // handling a key event, the wait is over! |
| 7530 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 7531 | KeyWaiter.RETURN_NOTHING); |
| 7532 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7533 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 7534 | |
| 7535 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7536 | mAppToken.startingDisplayed = false; |
| 7537 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7539 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7540 | mDrawPending = false; |
| 7541 | mCommitDrawPending = false; |
| 7542 | mReadyToShow = false; |
| 7543 | |
| 7544 | int i = mChildWindows.size(); |
| 7545 | while (i > 0) { |
| 7546 | i--; |
| 7547 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7548 | c.mAttachedHidden = true; |
| 7549 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7550 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7551 | if (mReportDestroySurface) { |
| 7552 | mReportDestroySurface = false; |
| 7553 | mSurfacePendingDestroy = true; |
| 7554 | try { |
| 7555 | mClient.dispatchGetNewSurface(); |
| 7556 | // We'll really destroy on the next time around. |
| 7557 | return; |
| 7558 | } catch (RemoteException e) { |
| 7559 | } |
| 7560 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7561 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7563 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7564 | RuntimeException e = null; |
| 7565 | if (!HIDE_STACK_CRAWLS) { |
| 7566 | e = new RuntimeException(); |
| 7567 | e.fillInStackTrace(); |
| 7568 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7569 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7570 | + mSurface + ", session " + mSession, e); |
| 7571 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7572 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7573 | RuntimeException e = null; |
| 7574 | if (!HIDE_STACK_CRAWLS) { |
| 7575 | e = new RuntimeException(); |
| 7576 | e.fillInStackTrace(); |
| 7577 | } |
| 7578 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7579 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7580 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7581 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7582 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | + " surface " + mSurface + " session " + mSession |
| 7584 | + ": " + e.toString()); |
| 7585 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7586 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7587 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7588 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7589 | } |
| 7590 | } |
| 7591 | |
| 7592 | boolean finishDrawingLocked() { |
| 7593 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7594 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7595 | TAG, "finishDrawingLocked: " + mSurface); |
| 7596 | mCommitDrawPending = true; |
| 7597 | mDrawPending = false; |
| 7598 | return true; |
| 7599 | } |
| 7600 | return false; |
| 7601 | } |
| 7602 | |
| 7603 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7604 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7605 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7606 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7607 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7608 | } |
| 7609 | mCommitDrawPending = false; |
| 7610 | mReadyToShow = true; |
| 7611 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7612 | final AppWindowToken atoken = mAppToken; |
| 7613 | if (atoken == null || atoken.allDrawn || starting) { |
| 7614 | performShowLocked(); |
| 7615 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7616 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7617 | } |
| 7618 | |
| 7619 | // This must be called while inside a transaction. |
| 7620 | boolean performShowLocked() { |
| 7621 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7622 | RuntimeException e = null; |
| 7623 | if (!HIDE_STACK_CRAWLS) { |
| 7624 | e = new RuntimeException(); |
| 7625 | e.fillInStackTrace(); |
| 7626 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7627 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7628 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7629 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7630 | } |
| 7631 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7632 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7633 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7634 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7635 | + " during animation: policyVis=" + mPolicyVisibility |
| 7636 | + " attHidden=" + mAttachedHidden |
| 7637 | + " tok.hiddenRequested=" |
| 7638 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7639 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7640 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7641 | + " animating=" + mAnimating |
| 7642 | + " tok animating=" |
| 7643 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7644 | if (!showSurfaceRobustlyLocked(this)) { |
| 7645 | return false; |
| 7646 | } |
| 7647 | mLastAlpha = -1; |
| 7648 | mHasDrawn = true; |
| 7649 | mLastHidden = false; |
| 7650 | mReadyToShow = false; |
| 7651 | enableScreenIfNeededLocked(); |
| 7652 | |
| 7653 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7655 | int i = mChildWindows.size(); |
| 7656 | while (i > 0) { |
| 7657 | i--; |
| 7658 | WindowState c = (WindowState)mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7659 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7660 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7661 | if (c.mSurface != null) { |
| 7662 | c.performShowLocked(); |
| 7663 | // It hadn't been shown, which means layout not |
| 7664 | // performed on it, so now we want to make sure to |
| 7665 | // do a layout. If called from within the transaction |
| 7666 | // loop, this will cause it to restart with a new |
| 7667 | // layout. |
| 7668 | mLayoutNeeded = true; |
| 7669 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7670 | } |
| 7671 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7672 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7673 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7674 | && mAppToken != null) { |
| 7675 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7676 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7677 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7678 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7679 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7680 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7681 | // If this initial window is animating, stop it -- we |
| 7682 | // will do an animation to reveal it from behind the |
| 7683 | // starting window, so there is no need for it to also |
| 7684 | // be doing its own stuff. |
| 7685 | if (mAnimation != null) { |
| 7686 | mAnimation = null; |
| 7687 | // Make sure we clean up the animation. |
| 7688 | mAnimating = true; |
| 7689 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | mFinishedStarting.add(mAppToken); |
| 7691 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7692 | } |
| 7693 | mAppToken.updateReportedVisibilityLocked(); |
| 7694 | } |
| 7695 | } |
| 7696 | return true; |
| 7697 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7698 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7699 | // This must be called while inside a transaction. Returns true if |
| 7700 | // there is more animation to run. |
| 7701 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7702 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7704 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7705 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7706 | mHasTransformation = true; |
| 7707 | mHasLocalTransformation = true; |
| 7708 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7709 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7710 | TAG, "Starting animation in " + this + |
| 7711 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7712 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7713 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7714 | mAnimation.setStartTime(currentTime); |
| 7715 | mLocalAnimating = true; |
| 7716 | mAnimating = true; |
| 7717 | } |
| 7718 | mTransformation.clear(); |
| 7719 | final boolean more = mAnimation.getTransformation( |
| 7720 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7721 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7722 | TAG, "Stepped animation in " + this + |
| 7723 | ": more=" + more + ", xform=" + mTransformation); |
| 7724 | if (more) { |
| 7725 | // we're not done! |
| 7726 | return true; |
| 7727 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7728 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7729 | TAG, "Finished animation in " + this + |
| 7730 | " @ " + currentTime); |
| 7731 | mAnimation = null; |
| 7732 | //WindowManagerService.this.dump(); |
| 7733 | } |
| 7734 | mHasLocalTransformation = false; |
| 7735 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7736 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7737 | // When our app token is animating, we kind-of pretend like |
| 7738 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7739 | // part of this check means that we will only do this if |
| 7740 | // our window is not currently exiting, or it is not |
| 7741 | // locally animating itself. The idea being that one that |
| 7742 | // is exiting and doing a local animation should be removed |
| 7743 | // once that animation is done. |
| 7744 | mAnimating = true; |
| 7745 | mHasTransformation = true; |
| 7746 | mTransformation.clear(); |
| 7747 | return false; |
| 7748 | } else if (mHasTransformation) { |
| 7749 | // Little trick to get through the path below to act like |
| 7750 | // we have finished an animation. |
| 7751 | mAnimating = true; |
| 7752 | } else if (isAnimating()) { |
| 7753 | mAnimating = true; |
| 7754 | } |
| 7755 | } else if (mAnimation != null) { |
| 7756 | // If the display is frozen, and there is a pending animation, |
| 7757 | // clear it and make sure we run the cleanup code. |
| 7758 | mAnimating = true; |
| 7759 | mLocalAnimating = true; |
| 7760 | mAnimation = null; |
| 7761 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7763 | if (!mAnimating && !mLocalAnimating) { |
| 7764 | return false; |
| 7765 | } |
| 7766 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7767 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7768 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7769 | + ", reportedVisible=" |
| 7770 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7771 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7772 | mAnimating = false; |
| 7773 | mLocalAnimating = false; |
| 7774 | mAnimation = null; |
| 7775 | mAnimLayer = mLayer; |
| 7776 | if (mIsImWindow) { |
| 7777 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7778 | } else if (mIsWallpaper) { |
| 7779 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7780 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7781 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7782 | + " anim layer: " + mAnimLayer); |
| 7783 | mHasTransformation = false; |
| 7784 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7785 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7786 | if (DEBUG_VISIBILITY) { |
| 7787 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7788 | + mPolicyVisibilityAfterAnim); |
| 7789 | } |
| 7790 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7791 | if (!mPolicyVisibility) { |
| 7792 | if (mCurrentFocus == this) { |
| 7793 | mFocusMayChange = true; |
| 7794 | } |
| 7795 | // Window is no longer visible -- make sure if we were waiting |
| 7796 | // for it to be displayed before enabling the display, that |
| 7797 | // we allow the display to be enabled now. |
| 7798 | enableScreenIfNeededLocked(); |
| 7799 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7800 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7801 | mTransformation.clear(); |
| 7802 | if (mHasDrawn |
| 7803 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7804 | && mAppToken != null |
| 7805 | && mAppToken.firstWindowDrawn |
| 7806 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7807 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7808 | + mToken + ": first real window done animating"); |
| 7809 | mFinishedStarting.add(mAppToken); |
| 7810 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7811 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7812 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7813 | finishExit(); |
| 7814 | |
| 7815 | if (mAppToken != null) { |
| 7816 | mAppToken.updateReportedVisibilityLocked(); |
| 7817 | } |
| 7818 | |
| 7819 | return false; |
| 7820 | } |
| 7821 | |
| 7822 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7823 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | TAG, "finishExit in " + this |
| 7825 | + ": exiting=" + mExiting |
| 7826 | + " remove=" + mRemoveOnExit |
| 7827 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7828 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7829 | final int N = mChildWindows.size(); |
| 7830 | for (int i=0; i<N; i++) { |
| 7831 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 7832 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7834 | if (!mExiting) { |
| 7835 | return; |
| 7836 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7838 | if (isWindowAnimating()) { |
| 7839 | return; |
| 7840 | } |
| 7841 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7842 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7843 | TAG, "Exit animation finished in " + this |
| 7844 | + ": remove=" + mRemoveOnExit); |
| 7845 | if (mSurface != null) { |
| 7846 | mDestroySurface.add(this); |
| 7847 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7848 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7849 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7850 | try { |
| 7851 | mSurface.hide(); |
| 7852 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7853 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7854 | } |
| 7855 | mLastHidden = true; |
| 7856 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7857 | } |
| 7858 | mExiting = false; |
| 7859 | if (mRemoveOnExit) { |
| 7860 | mPendingRemove.add(this); |
| 7861 | mRemoveOnExit = false; |
| 7862 | } |
| 7863 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7864 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7865 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7866 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7867 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7868 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7869 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7870 | return true; |
| 7871 | } |
| 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 | void computeShownFrameLocked() { |
| 7874 | final boolean selfTransformation = mHasLocalTransformation; |
| 7875 | Transformation attachedTransformation = |
| 7876 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7877 | ? mAttachedWindow.mTransformation : null; |
| 7878 | Transformation appTransformation = |
| 7879 | (mAppToken != null && mAppToken.hasTransformation) |
| 7880 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7881 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7882 | // Wallpapers are animated based on the "real" window they |
| 7883 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7884 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7885 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7886 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7887 | mWallpaperTarget.mAnimation != null && |
| 7888 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7889 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7890 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7891 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7892 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7893 | } |
| 7894 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7895 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7896 | mWallpaperTarget.mAppToken.animation != null && |
| 7897 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7898 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7899 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7900 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7901 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7902 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7903 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7904 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7905 | if (selfTransformation || attachedTransformation != null |
| 7906 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7907 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7908 | final Rect frame = mFrame; |
| 7909 | final float tmpFloats[] = mTmpFloats; |
| 7910 | final Matrix tmpMatrix = mTmpMatrix; |
| 7911 | |
| 7912 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7913 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7914 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7915 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7916 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7917 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7918 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7919 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7920 | } |
| 7921 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7922 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7923 | } |
| 7924 | |
| 7925 | // "convert" it into SurfaceFlinger's format |
| 7926 | // (a 2x2 matrix + an offset) |
| 7927 | // Here we must not transform the position of the surface |
| 7928 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7929 | //Slog.i(TAG, "Transform: " + matrix); |
| 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 | tmpMatrix.getValues(tmpFloats); |
| 7932 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7933 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7934 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7935 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7936 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7937 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7938 | int w = frame.width(); |
| 7939 | int h = frame.height(); |
| 7940 | mShownFrame.set(x, y, x+w, y+h); |
| 7941 | |
| 7942 | // Now set the alpha... but because our current hardware |
| 7943 | // can't do alpha transformation on a non-opaque surface, |
| 7944 | // turn it off if we are running an animation that is also |
| 7945 | // transforming since it is more important to have that |
| 7946 | // animation be smooth. |
| 7947 | mShownAlpha = mAlpha; |
| 7948 | if (!mLimitedAlphaCompositing |
| 7949 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7950 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7951 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7952 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7953 | if (selfTransformation) { |
| 7954 | mShownAlpha *= mTransformation.getAlpha(); |
| 7955 | } |
| 7956 | if (attachedTransformation != null) { |
| 7957 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7958 | } |
| 7959 | if (appTransformation != null) { |
| 7960 | mShownAlpha *= appTransformation.getAlpha(); |
| 7961 | } |
| 7962 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7963 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7964 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7965 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7966 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7967 | TAG, "Continuing animation in " + this + |
| 7968 | ": " + mShownFrame + |
| 7969 | ", alpha=" + mTransformation.getAlpha()); |
| 7970 | return; |
| 7971 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7973 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7974 | if (mXOffset != 0 || mYOffset != 0) { |
| 7975 | mShownFrame.offset(mXOffset, mYOffset); |
| 7976 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7977 | mShownAlpha = mAlpha; |
| 7978 | mDsDx = 1; |
| 7979 | mDtDx = 0; |
| 7980 | mDsDy = 0; |
| 7981 | mDtDy = 1; |
| 7982 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7983 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7984 | /** |
| 7985 | * Is this window visible? It is not visible if there is no |
| 7986 | * surface, or we are in the process of running an exit animation |
| 7987 | * that will remove the surface, or its app token has been hidden. |
| 7988 | */ |
| 7989 | public boolean isVisibleLw() { |
| 7990 | final AppWindowToken atoken = mAppToken; |
| 7991 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7992 | && (atoken == null || !atoken.hiddenRequested) |
| 7993 | && !mExiting && !mDestroying; |
| 7994 | } |
| 7995 | |
| 7996 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7997 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7998 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7999 | * things like window flags that impact the keyguard. |
| 8000 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 8001 | * for this "hidden behind keyguard" state rather than overloading |
| 8002 | * mPolicyVisibility. Ungh. |
| 8003 | */ |
| 8004 | public boolean isVisibleOrBehindKeyguardLw() { |
| 8005 | final AppWindowToken atoken = mAppToken; |
| 8006 | return mSurface != null && !mAttachedHidden |
| 8007 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 8008 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)) |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 8009 | && !mExiting && !mDestroying; |
| 8010 | } |
| 8011 | |
| 8012 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8013 | * Is this window visible, ignoring its app token? It is not visible |
| 8014 | * if there is no surface, or we are in the process of running an exit animation |
| 8015 | * that will remove the surface. |
| 8016 | */ |
| 8017 | public boolean isWinVisibleLw() { |
| 8018 | final AppWindowToken atoken = mAppToken; |
| 8019 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 8020 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 8021 | && !mExiting && !mDestroying; |
| 8022 | } |
| 8023 | |
| 8024 | /** |
| 8025 | * The same as isVisible(), but follows the current hidden state of |
| 8026 | * the associated app token, not the pending requested hidden state. |
| 8027 | */ |
| 8028 | boolean isVisibleNow() { |
| 8029 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 8030 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8031 | } |
| 8032 | |
| 8033 | /** |
| 8034 | * Same as isVisible(), but we also count it as visible between the |
| 8035 | * call to IWindowSession.add() and the first relayout(). |
| 8036 | */ |
| 8037 | boolean isVisibleOrAdding() { |
| 8038 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8039 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8040 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 8041 | && mPolicyVisibility && !mAttachedHidden |
| 8042 | && (atoken == null || !atoken.hiddenRequested) |
| 8043 | && !mExiting && !mDestroying; |
| 8044 | } |
| 8045 | |
| 8046 | /** |
| 8047 | * Is this window currently on-screen? It is on-screen either if it |
| 8048 | * is visible or it is currently running an animation before no longer |
| 8049 | * being visible. |
| 8050 | */ |
| 8051 | boolean isOnScreen() { |
| 8052 | final AppWindowToken atoken = mAppToken; |
| 8053 | if (atoken != null) { |
| 8054 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8055 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8056 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8057 | } else { |
| 8058 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8059 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8060 | } |
| 8061 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8062 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8063 | /** |
| 8064 | * Like isOnScreen(), but we don't return true if the window is part |
| 8065 | * of a transition that has not yet been started. |
| 8066 | */ |
| 8067 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8068 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8069 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8070 | return false; |
| 8071 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8072 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8073 | final boolean animating = atoken != null |
| 8074 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8075 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8076 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 8077 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8078 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8079 | } |
| 8080 | |
| 8081 | /** Is the window or its container currently animating? */ |
| 8082 | boolean isAnimating() { |
| 8083 | final WindowState attached = mAttachedWindow; |
| 8084 | final AppWindowToken atoken = mAppToken; |
| 8085 | return mAnimation != null |
| 8086 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8087 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8088 | (atoken.animation != null |
| 8089 | || atoken.inPendingTransaction)); |
| 8090 | } |
| 8091 | |
| 8092 | /** Is this window currently animating? */ |
| 8093 | boolean isWindowAnimating() { |
| 8094 | return mAnimation != null; |
| 8095 | } |
| 8096 | |
| 8097 | /** |
| 8098 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 8099 | * been drawn. |
| 8100 | */ |
| 8101 | public boolean isDisplayedLw() { |
| 8102 | final AppWindowToken atoken = mAppToken; |
| 8103 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8104 | && !mDrawPending && !mCommitDrawPending |
| 8105 | && ((!mAttachedHidden && |
| 8106 | (atoken == null || !atoken.hiddenRequested)) |
| 8107 | || mAnimating); |
| 8108 | } |
| 8109 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8110 | /** |
| 8111 | * 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] | 8112 | * complete UI in to. Note that this returns true if the orientation |
| 8113 | * is changing even if the window hasn't redrawn because we don't want |
| 8114 | * to stop things from executing during that time. |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8115 | */ |
| 8116 | public boolean isDrawnLw() { |
| 8117 | final AppWindowToken atoken = mAppToken; |
| 8118 | return mSurface != null && !mDestroying |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 8119 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8120 | } |
| 8121 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8122 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 8123 | boolean shownFrame, boolean onlyOpaque) { |
| 8124 | if (mSurface == null) { |
| 8125 | return false; |
| 8126 | } |
| 8127 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 8128 | return false; |
| 8129 | } |
| 8130 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 8131 | return false; |
| 8132 | } |
| 8133 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8134 | |
| 8135 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8136 | return frame.left <= mCompatibleScreenFrame.left && |
| 8137 | frame.top <= mCompatibleScreenFrame.top && |
| 8138 | frame.right >= mCompatibleScreenFrame.right && |
| 8139 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 8140 | } else { |
| 8141 | return frame.left <= 0 && frame.top <= 0 |
| 8142 | && frame.right >= screenWidth |
| 8143 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8144 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8146 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8147 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8148 | * Return true if the window is opaque and fully drawn. This indicates |
| 8149 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8150 | */ |
| 8151 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8152 | return (mAttrs.format == PixelFormat.OPAQUE |
| 8153 | || mAttrs.type == TYPE_WALLPAPER) |
| 8154 | && mSurface != null && mAnimation == null |
| 8155 | && (mAppToken == null || mAppToken.animation == null) |
| 8156 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8157 | } |
| 8158 | |
| 8159 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 8160 | return |
| 8161 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8162 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 8163 | // only if it's visible |
| 8164 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8165 | // and only if the application fills the compatible screen |
| 8166 | mFrame.left <= mCompatibleScreenFrame.left && |
| 8167 | mFrame.top <= mCompatibleScreenFrame.top && |
| 8168 | mFrame.right >= mCompatibleScreenFrame.right && |
| 8169 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8170 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8171 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8172 | } |
| 8173 | |
| 8174 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 8175 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8176 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8177 | } |
| 8178 | |
| 8179 | void removeLocked() { |
| 8180 | if (mAttachedWindow != null) { |
| 8181 | mAttachedWindow.mChildWindows.remove(this); |
| 8182 | } |
| 8183 | destroySurfaceLocked(); |
| 8184 | mSession.windowRemovedLocked(); |
| 8185 | try { |
| 8186 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8187 | } catch (RuntimeException e) { |
| 8188 | // Ignore if it has already been removed (usually because |
| 8189 | // we are doing this as part of processing a death note.) |
| 8190 | } |
| 8191 | } |
| 8192 | |
| 8193 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8194 | public void binderDied() { |
| 8195 | try { |
| 8196 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8197 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8198 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8199 | if (win != null) { |
| 8200 | removeWindowLocked(mSession, win); |
| 8201 | } |
| 8202 | } |
| 8203 | } catch (IllegalArgumentException ex) { |
| 8204 | // This will happen if the window has already been |
| 8205 | // removed. |
| 8206 | } |
| 8207 | } |
| 8208 | } |
| 8209 | |
| 8210 | /** Returns true if this window desires key events. */ |
| 8211 | public final boolean canReceiveKeys() { |
| 8212 | return isVisibleOrAdding() |
| 8213 | && (mViewVisibility == View.VISIBLE) |
| 8214 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8215 | } |
| 8216 | |
| 8217 | public boolean hasDrawnLw() { |
| 8218 | return mHasDrawn; |
| 8219 | } |
| 8220 | |
| 8221 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8222 | return showLw(doAnimation, true); |
| 8223 | } |
| 8224 | |
| 8225 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8226 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8227 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8228 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8229 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8230 | if (doAnimation) { |
| 8231 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8232 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8233 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8234 | doAnimation = false; |
| 8235 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8236 | // Check for the case where we are currently visible and |
| 8237 | // not animating; we do not want to do animation at such a |
| 8238 | // point to become visible when we already are. |
| 8239 | doAnimation = false; |
| 8240 | } |
| 8241 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8242 | mPolicyVisibility = true; |
| 8243 | mPolicyVisibilityAfterAnim = true; |
| 8244 | if (doAnimation) { |
| 8245 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8246 | } |
| 8247 | if (requestAnim) { |
| 8248 | requestAnimationLocked(0); |
| 8249 | } |
| 8250 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8251 | } |
| 8252 | |
| 8253 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8254 | return hideLw(doAnimation, true); |
| 8255 | } |
| 8256 | |
| 8257 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8258 | if (doAnimation) { |
| 8259 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8260 | doAnimation = false; |
| 8261 | } |
| 8262 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8263 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8264 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8265 | if (!current) { |
| 8266 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8267 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8268 | if (doAnimation) { |
| 8269 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8270 | if (mAnimation == null) { |
| 8271 | doAnimation = false; |
| 8272 | } |
| 8273 | } |
| 8274 | if (doAnimation) { |
| 8275 | mPolicyVisibilityAfterAnim = false; |
| 8276 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8277 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8278 | mPolicyVisibilityAfterAnim = false; |
| 8279 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8280 | // Window is no longer visible -- make sure if we were waiting |
| 8281 | // for it to be displayed before enabling the display, that |
| 8282 | // we allow the display to be enabled now. |
| 8283 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8284 | if (mCurrentFocus == this) { |
| 8285 | mFocusMayChange = true; |
| 8286 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8287 | } |
| 8288 | if (requestAnim) { |
| 8289 | requestAnimationLocked(0); |
| 8290 | } |
| 8291 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8292 | } |
| 8293 | |
| 8294 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8295 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8296 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8297 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8298 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8299 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8300 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8301 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8302 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8303 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8304 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8305 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8306 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8307 | } |
| 8308 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8309 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8310 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8311 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8312 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8313 | pw.print("="); pw.print(mAnimLayer); |
| 8314 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8315 | if (mSurface != null) { |
| 8316 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8317 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8318 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8319 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8320 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8321 | pw.print(","); pw.print(mSurfaceY); |
| 8322 | pw.print(") "); pw.print(mSurfaceW); |
| 8323 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8324 | } |
| 8325 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8326 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8327 | if (mAppToken != null) { |
| 8328 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8329 | } |
| 8330 | if (mTargetAppToken != null) { |
| 8331 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8332 | } |
| 8333 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8334 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8335 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8336 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8337 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8338 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8339 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8340 | pw.print(mPolicyVisibility); |
| 8341 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8342 | pw.print(mPolicyVisibilityAfterAnim); |
| 8343 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8344 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8345 | if (!mRelayoutCalled) { |
| 8346 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8347 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8348 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8349 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8350 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8351 | if (mXOffset != 0 || mYOffset != 0) { |
| 8352 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8353 | pw.print(" y="); pw.println(mYOffset); |
| 8354 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8355 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8356 | mGivenContentInsets.printShortString(pw); |
| 8357 | pw.print(" mGivenVisibleInsets="); |
| 8358 | mGivenVisibleInsets.printShortString(pw); |
| 8359 | pw.println(); |
| 8360 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8361 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8362 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8363 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8364 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8365 | pw.print(prefix); pw.print("mShownFrame="); |
| 8366 | mShownFrame.printShortString(pw); |
| 8367 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8368 | pw.println(); |
| 8369 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8370 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8371 | pw.println(); |
| 8372 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8373 | mContainingFrame.printShortString(pw); |
| 8374 | pw.print(" mDisplayFrame="); |
| 8375 | mDisplayFrame.printShortString(pw); |
| 8376 | pw.println(); |
| 8377 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8378 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8379 | pw.println(); |
| 8380 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8381 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8382 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8383 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8384 | pw.println(); |
| 8385 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8386 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8387 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8388 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8389 | } |
| 8390 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8391 | || mAnimation != null) { |
| 8392 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8393 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8394 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8395 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8396 | } |
| 8397 | if (mHasTransformation || mHasLocalTransformation) { |
| 8398 | pw.print(prefix); pw.print("XForm: has="); |
| 8399 | pw.print(mHasTransformation); |
| 8400 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8401 | pw.print(" "); mTransformation.printShortString(pw); |
| 8402 | pw.println(); |
| 8403 | } |
| 8404 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8405 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8406 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8407 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8408 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8409 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8410 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8411 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8412 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8413 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8414 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8415 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8416 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8417 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8418 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8419 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8420 | if (mHScale != 1 || mVScale != 1) { |
| 8421 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8422 | pw.print(" mVScale="); pw.println(mVScale); |
| 8423 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8424 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8425 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8426 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8427 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8428 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8429 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8430 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8431 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | } |
| 8433 | |
| 8434 | @Override |
| 8435 | public String toString() { |
| 8436 | return "Window{" |
| 8437 | + Integer.toHexString(System.identityHashCode(this)) |
| 8438 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 8439 | } |
| 8440 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8442 | // ------------------------------------------------------------- |
| 8443 | // Window Token State |
| 8444 | // ------------------------------------------------------------- |
| 8445 | |
| 8446 | class WindowToken { |
| 8447 | // The actual token. |
| 8448 | final IBinder token; |
| 8449 | |
| 8450 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8451 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8453 | // Set if this token was explicitly added by a client, so should |
| 8454 | // not be removed when all windows are removed. |
| 8455 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8456 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8457 | // For printing. |
| 8458 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8460 | // If this is an AppWindowToken, this is non-null. |
| 8461 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8463 | // All of the windows associated with this token. |
| 8464 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8465 | |
| 8466 | // Is key dispatching paused for this token? |
| 8467 | boolean paused = false; |
| 8468 | |
| 8469 | // Should this token's windows be hidden? |
| 8470 | boolean hidden; |
| 8471 | |
| 8472 | // Temporary for finding which tokens no longer have visible windows. |
| 8473 | boolean hasVisible; |
| 8474 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8475 | // Set to true when this token is in a pending transaction where it |
| 8476 | // will be shown. |
| 8477 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8478 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8479 | // Set to true when this token is in a pending transaction where it |
| 8480 | // will be hidden. |
| 8481 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8482 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8483 | // Set to true when this token is in a pending transaction where its |
| 8484 | // windows will be put to the bottom of the list. |
| 8485 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8486 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8487 | // Set to true when this token is in a pending transaction where its |
| 8488 | // windows will be put to the top of the list. |
| 8489 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8490 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8491 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8492 | token = _token; |
| 8493 | windowType = type; |
| 8494 | explicit = _explicit; |
| 8495 | } |
| 8496 | |
| 8497 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8498 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8499 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8500 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8501 | pw.print(" hidden="); pw.print(hidden); |
| 8502 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8503 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8504 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8505 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8506 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8507 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8508 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8509 | } |
| 8510 | |
| 8511 | @Override |
| 8512 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8513 | if (stringName == null) { |
| 8514 | StringBuilder sb = new StringBuilder(); |
| 8515 | sb.append("WindowToken{"); |
| 8516 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8517 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8518 | stringName = sb.toString(); |
| 8519 | } |
| 8520 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8521 | } |
| 8522 | }; |
| 8523 | |
| 8524 | class AppWindowToken extends WindowToken { |
| 8525 | // Non-null only for application tokens. |
| 8526 | final IApplicationToken appToken; |
| 8527 | |
| 8528 | // All of the windows and child windows that are included in this |
| 8529 | // application token. Note this list is NOT sorted! |
| 8530 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8531 | |
| 8532 | int groupId = -1; |
| 8533 | boolean appFullscreen; |
| 8534 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 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 | // These are used for determining when all windows associated with |
| 8537 | // an activity have been drawn, so they can be made visible together |
| 8538 | // at the same time. |
| 8539 | int lastTransactionSequence = mTransactionSequence-1; |
| 8540 | int numInterestingWindows; |
| 8541 | int numDrawnWindows; |
| 8542 | boolean inPendingTransaction; |
| 8543 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8545 | // Is this token going to be hidden in a little while? If so, it |
| 8546 | // won't be taken into account for setting the screen orientation. |
| 8547 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8548 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8549 | // Is this window's surface needed? This is almost like hidden, except |
| 8550 | // it will sometimes be true a little earlier: when the token has |
| 8551 | // been shown, but is still waiting for its app transition to execute |
| 8552 | // before making its windows shown. |
| 8553 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8555 | // Have we told the window clients to hide themselves? |
| 8556 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8558 | // Last visibility state we reported to the app token. |
| 8559 | boolean reportedVisible; |
| 8560 | |
| 8561 | // Set to true when the token has been removed from the window mgr. |
| 8562 | boolean removed; |
| 8563 | |
| 8564 | // Have we been asked to have this token keep the screen frozen? |
| 8565 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8566 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8567 | boolean animating; |
| 8568 | Animation animation; |
| 8569 | boolean hasTransformation; |
| 8570 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8572 | // Offset to the window of all layers in the token, for use by |
| 8573 | // AppWindowToken animations. |
| 8574 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8575 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8576 | // Information about an application starting window if displayed. |
| 8577 | StartingData startingData; |
| 8578 | WindowState startingWindow; |
| 8579 | View startingView; |
| 8580 | boolean startingDisplayed; |
| 8581 | boolean startingMoved; |
| 8582 | boolean firstWindowDrawn; |
| 8583 | |
| 8584 | AppWindowToken(IApplicationToken _token) { |
| 8585 | super(_token.asBinder(), |
| 8586 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8587 | appWindowToken = this; |
| 8588 | appToken = _token; |
| 8589 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8590 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8591 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8592 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8593 | TAG, "Setting animation in " + this + ": " + anim); |
| 8594 | animation = anim; |
| 8595 | animating = false; |
| 8596 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8597 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8598 | int zorder = anim.getZAdjustment(); |
| 8599 | int adj = 0; |
| 8600 | if (zorder == Animation.ZORDER_TOP) { |
| 8601 | adj = TYPE_LAYER_OFFSET; |
| 8602 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8603 | adj = -TYPE_LAYER_OFFSET; |
| 8604 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8605 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8606 | if (animLayerAdjustment != adj) { |
| 8607 | animLayerAdjustment = adj; |
| 8608 | updateLayers(); |
| 8609 | } |
| 8610 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8612 | public void setDummyAnimation() { |
| 8613 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8614 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8615 | TAG, "Setting dummy animation in " + this); |
| 8616 | animation = sDummyAnimation; |
| 8617 | } |
| 8618 | } |
| 8619 | |
| 8620 | public void clearAnimation() { |
| 8621 | if (animation != null) { |
| 8622 | animation = null; |
| 8623 | animating = true; |
| 8624 | } |
| 8625 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8626 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8627 | void updateLayers() { |
| 8628 | final int N = allAppWindows.size(); |
| 8629 | final int adj = animLayerAdjustment; |
| 8630 | for (int i=0; i<N; i++) { |
| 8631 | WindowState w = allAppWindows.get(i); |
| 8632 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8633 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8634 | + w.mAnimLayer); |
| 8635 | if (w == mInputMethodTarget) { |
| 8636 | setInputMethodAnimLayerAdjustment(adj); |
| 8637 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8638 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8639 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8640 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8641 | } |
| 8642 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8643 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8644 | void sendAppVisibilityToClients() { |
| 8645 | final int N = allAppWindows.size(); |
| 8646 | for (int i=0; i<N; i++) { |
| 8647 | WindowState win = allAppWindows.get(i); |
| 8648 | if (win == startingWindow && clientHidden) { |
| 8649 | // Don't hide the starting window. |
| 8650 | continue; |
| 8651 | } |
| 8652 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8653 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8654 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8655 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8656 | } catch (RemoteException e) { |
| 8657 | } |
| 8658 | } |
| 8659 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8660 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8661 | void showAllWindowsLocked() { |
| 8662 | final int NW = allAppWindows.size(); |
| 8663 | for (int i=0; i<NW; i++) { |
| 8664 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8665 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8666 | "performing show on: " + w); |
| 8667 | w.performShowLocked(); |
| 8668 | } |
| 8669 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8670 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8671 | // This must be called while inside a transaction. |
| 8672 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8673 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8674 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8675 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8676 | if (animation == sDummyAnimation) { |
| 8677 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8678 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8679 | // when it is really time to animate, this will be set to |
| 8680 | // a real animation and the next call will execute normally. |
| 8681 | return false; |
| 8682 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8683 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8684 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8685 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8686 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8687 | TAG, "Starting animation in " + this + |
| 8688 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8689 | + " scale=" + mTransitionAnimationScale |
| 8690 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8691 | animation.initialize(dw, dh, dw, dh); |
| 8692 | animation.setStartTime(currentTime); |
| 8693 | animating = true; |
| 8694 | } |
| 8695 | transformation.clear(); |
| 8696 | final boolean more = animation.getTransformation( |
| 8697 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8698 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8699 | TAG, "Stepped animation in " + this + |
| 8700 | ": more=" + more + ", xform=" + transformation); |
| 8701 | if (more) { |
| 8702 | // we're done! |
| 8703 | hasTransformation = true; |
| 8704 | return true; |
| 8705 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8706 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8707 | TAG, "Finished animation in " + this + |
| 8708 | " @ " + currentTime); |
| 8709 | animation = null; |
| 8710 | } |
| 8711 | } else if (animation != null) { |
| 8712 | // If the display is frozen, and there is a pending animation, |
| 8713 | // clear it and make sure we run the cleanup code. |
| 8714 | animating = true; |
| 8715 | animation = null; |
| 8716 | } |
| 8717 | |
| 8718 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8719 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8720 | if (!animating) { |
| 8721 | return false; |
| 8722 | } |
| 8723 | |
| 8724 | clearAnimation(); |
| 8725 | animating = false; |
| 8726 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8727 | moveInputMethodWindowsIfNeededLocked(true); |
| 8728 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8729 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8730 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8731 | TAG, "Animation done in " + this |
| 8732 | + ": reportedVisible=" + reportedVisible); |
| 8733 | |
| 8734 | transformation.clear(); |
| 8735 | if (animLayerAdjustment != 0) { |
| 8736 | animLayerAdjustment = 0; |
| 8737 | updateLayers(); |
| 8738 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8740 | final int N = windows.size(); |
| 8741 | for (int i=0; i<N; i++) { |
| 8742 | ((WindowState)windows.get(i)).finishExit(); |
| 8743 | } |
| 8744 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8745 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8746 | return false; |
| 8747 | } |
| 8748 | |
| 8749 | void updateReportedVisibilityLocked() { |
| 8750 | if (appToken == null) { |
| 8751 | return; |
| 8752 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8753 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8754 | int numInteresting = 0; |
| 8755 | int numVisible = 0; |
| 8756 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8757 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8758 | 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] | 8759 | final int N = allAppWindows.size(); |
| 8760 | for (int i=0; i<N; i++) { |
| 8761 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8762 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8763 | || win.mViewVisibility != View.VISIBLE |
| Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8764 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8765 | || win.mDestroying) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8766 | continue; |
| 8767 | } |
| 8768 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8769 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8770 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8771 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8772 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8773 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8774 | + " pv=" + win.mPolicyVisibility |
| 8775 | + " dp=" + win.mDrawPending |
| 8776 | + " cdp=" + win.mCommitDrawPending |
| 8777 | + " ah=" + win.mAttachedHidden |
| 8778 | + " th=" |
| 8779 | + (win.mAppToken != null |
| 8780 | ? win.mAppToken.hiddenRequested : false) |
| 8781 | + " a=" + win.mAnimating); |
| 8782 | } |
| 8783 | } |
| 8784 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8785 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8786 | if (!win.isAnimating()) { |
| 8787 | numVisible++; |
| 8788 | } |
| 8789 | nowGone = false; |
| 8790 | } else if (win.isAnimating()) { |
| 8791 | nowGone = false; |
| 8792 | } |
| 8793 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8794 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8795 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8796 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8797 | + numInteresting + " visible=" + numVisible); |
| 8798 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8799 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8800 | TAG, "Visibility changed in " + this |
| 8801 | + ": vis=" + nowVisible); |
| 8802 | reportedVisible = nowVisible; |
| 8803 | Message m = mH.obtainMessage( |
| 8804 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8805 | nowVisible ? 1 : 0, |
| 8806 | nowGone ? 1 : 0, |
| 8807 | this); |
| 8808 | mH.sendMessage(m); |
| 8809 | } |
| 8810 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8811 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8812 | WindowState findMainWindow() { |
| 8813 | int j = windows.size(); |
| 8814 | while (j > 0) { |
| 8815 | j--; |
| 8816 | WindowState win = windows.get(j); |
| 8817 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8818 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8819 | return win; |
| 8820 | } |
| 8821 | } |
| 8822 | return null; |
| 8823 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8824 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8825 | void dump(PrintWriter pw, String prefix) { |
| 8826 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8827 | if (appToken != null) { |
| 8828 | pw.print(prefix); pw.println("app=true"); |
| 8829 | } |
| 8830 | if (allAppWindows.size() > 0) { |
| 8831 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8832 | } |
| 8833 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8834 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8835 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8836 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8837 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8838 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8839 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8840 | if (paused || freezingScreen) { |
| 8841 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8842 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8843 | } |
| 8844 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8845 | || inPendingTransaction || allDrawn) { |
| 8846 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8847 | pw.print(numInterestingWindows); |
| 8848 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8849 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8850 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8851 | } |
| 8852 | if (animating || animation != null) { |
| 8853 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8854 | pw.print(" animation="); pw.println(animation); |
| 8855 | } |
| 8856 | if (animLayerAdjustment != 0) { |
| 8857 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8858 | } |
| 8859 | if (hasTransformation) { |
| 8860 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8861 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8862 | pw.println(); |
| 8863 | } |
| 8864 | if (startingData != null || removed || firstWindowDrawn) { |
| 8865 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8866 | pw.print(" removed="); pw.print(removed); |
| 8867 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8868 | } |
| 8869 | if (startingWindow != null || startingView != null |
| 8870 | || startingDisplayed || startingMoved) { |
| 8871 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8872 | pw.print(" startingView="); pw.print(startingView); |
| 8873 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8874 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8875 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8876 | } |
| 8877 | |
| 8878 | @Override |
| 8879 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8880 | if (stringName == null) { |
| 8881 | StringBuilder sb = new StringBuilder(); |
| 8882 | sb.append("AppWindowToken{"); |
| 8883 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8884 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8885 | stringName = sb.toString(); |
| 8886 | } |
| 8887 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8888 | } |
| 8889 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8890 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8891 | // ------------------------------------------------------------- |
| 8892 | // DummyAnimation |
| 8893 | // ------------------------------------------------------------- |
| 8894 | |
| 8895 | // This is an animation that does nothing: it just immediately finishes |
| 8896 | // itself every time it is called. It is used as a stub animation in cases |
| 8897 | // where we want to synchronize multiple things that may be animating. |
| 8898 | static final class DummyAnimation extends Animation { |
| 8899 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8900 | return false; |
| 8901 | } |
| 8902 | } |
| 8903 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8904 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8905 | // ------------------------------------------------------------- |
| 8906 | // Async Handler |
| 8907 | // ------------------------------------------------------------- |
| 8908 | |
| 8909 | static final class StartingData { |
| 8910 | final String pkg; |
| 8911 | final int theme; |
| 8912 | final CharSequence nonLocalizedLabel; |
| 8913 | final int labelRes; |
| 8914 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8916 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8917 | int _labelRes, int _icon) { |
| 8918 | pkg = _pkg; |
| 8919 | theme = _theme; |
| 8920 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8921 | labelRes = _labelRes; |
| 8922 | icon = _icon; |
| 8923 | } |
| 8924 | } |
| 8925 | |
| 8926 | private final class H extends Handler { |
| 8927 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8928 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8929 | public static final int ANIMATE = 4; |
| 8930 | public static final int ADD_STARTING = 5; |
| 8931 | public static final int REMOVE_STARTING = 6; |
| 8932 | public static final int FINISHED_STARTING = 7; |
| 8933 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8934 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8935 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8936 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8937 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8938 | public static final int FORCE_GC = 15; |
| 8939 | public static final int ENABLE_SCREEN = 16; |
| 8940 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8941 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8943 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8944 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8945 | public H() { |
| 8946 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8948 | @Override |
| 8949 | public void handleMessage(Message msg) { |
| 8950 | switch (msg.what) { |
| 8951 | case REPORT_FOCUS_CHANGE: { |
| 8952 | WindowState lastFocus; |
| 8953 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8955 | synchronized(mWindowMap) { |
| 8956 | lastFocus = mLastFocus; |
| 8957 | newFocus = mCurrentFocus; |
| 8958 | if (lastFocus == newFocus) { |
| 8959 | // Focus is not changing, so nothing to do. |
| 8960 | return; |
| 8961 | } |
| 8962 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8963 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8964 | // + " to " + newFocus); |
| 8965 | if (newFocus != null && lastFocus != null |
| 8966 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8967 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8968 | mLosingFocus.add(lastFocus); |
| 8969 | lastFocus = null; |
| 8970 | } |
| 8971 | } |
| 8972 | |
| 8973 | if (lastFocus != newFocus) { |
| 8974 | //System.out.println("Changing focus from " + lastFocus |
| 8975 | // + " to " + newFocus); |
| 8976 | if (newFocus != null) { |
| 8977 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8978 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8979 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8980 | } catch (RemoteException e) { |
| 8981 | // Ignore if process has died. |
| 8982 | } |
| 8983 | } |
| 8984 | |
| 8985 | if (lastFocus != null) { |
| 8986 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8987 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8988 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8989 | } catch (RemoteException e) { |
| 8990 | // Ignore if process has died. |
| 8991 | } |
| 8992 | } |
| 8993 | } |
| 8994 | } break; |
| 8995 | |
| 8996 | case REPORT_LOSING_FOCUS: { |
| 8997 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8998 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8999 | synchronized(mWindowMap) { |
| 9000 | losers = mLosingFocus; |
| 9001 | mLosingFocus = new ArrayList<WindowState>(); |
| 9002 | } |
| 9003 | |
| 9004 | final int N = losers.size(); |
| 9005 | for (int i=0; i<N; i++) { |
| 9006 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9007 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9008 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 9009 | } catch (RemoteException e) { |
| 9010 | // Ignore if process has died. |
| 9011 | } |
| 9012 | } |
| 9013 | } break; |
| 9014 | |
| 9015 | case ANIMATE: { |
| 9016 | synchronized(mWindowMap) { |
| 9017 | mAnimationPending = false; |
| 9018 | performLayoutAndPlaceSurfacesLocked(); |
| 9019 | } |
| 9020 | } break; |
| 9021 | |
| 9022 | case ADD_STARTING: { |
| 9023 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9024 | final StartingData sd = wtoken.startingData; |
| 9025 | |
| 9026 | if (sd == null) { |
| 9027 | // Animation has been canceled... do nothing. |
| 9028 | return; |
| 9029 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9030 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9031 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9032 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9033 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9034 | View view = null; |
| 9035 | try { |
| 9036 | view = mPolicy.addStartingWindow( |
| 9037 | wtoken.token, sd.pkg, |
| 9038 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 9039 | sd.icon); |
| 9040 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9041 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9042 | } |
| 9043 | |
| 9044 | if (view != null) { |
| 9045 | boolean abort = false; |
| 9046 | |
| 9047 | synchronized(mWindowMap) { |
| 9048 | if (wtoken.removed || wtoken.startingData == null) { |
| 9049 | // If the window was successfully added, then |
| 9050 | // we need to remove it. |
| 9051 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9052 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9053 | "Aborted starting " + wtoken |
| 9054 | + ": removed=" + wtoken.removed |
| 9055 | + " startingData=" + wtoken.startingData); |
| 9056 | wtoken.startingWindow = null; |
| 9057 | wtoken.startingData = null; |
| 9058 | abort = true; |
| 9059 | } |
| 9060 | } else { |
| 9061 | wtoken.startingView = view; |
| 9062 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9063 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9064 | "Added starting " + wtoken |
| 9065 | + ": startingWindow=" |
| 9066 | + wtoken.startingWindow + " startingView=" |
| 9067 | + wtoken.startingView); |
| 9068 | } |
| 9069 | |
| 9070 | if (abort) { |
| 9071 | try { |
| 9072 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 9073 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9074 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9075 | } |
| 9076 | } |
| 9077 | } |
| 9078 | } break; |
| 9079 | |
| 9080 | case REMOVE_STARTING: { |
| 9081 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9082 | IBinder token = null; |
| 9083 | View view = null; |
| 9084 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9085 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9086 | + wtoken + ": startingWindow=" |
| 9087 | + wtoken.startingWindow + " startingView=" |
| 9088 | + wtoken.startingView); |
| 9089 | if (wtoken.startingWindow != null) { |
| 9090 | view = wtoken.startingView; |
| 9091 | token = wtoken.token; |
| 9092 | wtoken.startingData = null; |
| 9093 | wtoken.startingView = null; |
| 9094 | wtoken.startingWindow = null; |
| 9095 | } |
| 9096 | } |
| 9097 | if (view != null) { |
| 9098 | try { |
| 9099 | mPolicy.removeStartingWindow(token, view); |
| 9100 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9101 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9102 | } |
| 9103 | } |
| 9104 | } break; |
| 9105 | |
| 9106 | case FINISHED_STARTING: { |
| 9107 | IBinder token = null; |
| 9108 | View view = null; |
| 9109 | while (true) { |
| 9110 | synchronized (mWindowMap) { |
| 9111 | final int N = mFinishedStarting.size(); |
| 9112 | if (N <= 0) { |
| 9113 | break; |
| 9114 | } |
| 9115 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9116 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9117 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9118 | "Finished starting " + wtoken |
| 9119 | + ": startingWindow=" + wtoken.startingWindow |
| 9120 | + " startingView=" + wtoken.startingView); |
| 9121 | |
| 9122 | if (wtoken.startingWindow == null) { |
| 9123 | continue; |
| 9124 | } |
| 9125 | |
| 9126 | view = wtoken.startingView; |
| 9127 | token = wtoken.token; |
| 9128 | wtoken.startingData = null; |
| 9129 | wtoken.startingView = null; |
| 9130 | wtoken.startingWindow = null; |
| 9131 | } |
| 9132 | |
| 9133 | try { |
| 9134 | mPolicy.removeStartingWindow(token, view); |
| 9135 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9136 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9137 | } |
| 9138 | } |
| 9139 | } break; |
| 9140 | |
| 9141 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9142 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9143 | |
| 9144 | boolean nowVisible = msg.arg1 != 0; |
| 9145 | boolean nowGone = msg.arg2 != 0; |
| 9146 | |
| 9147 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9148 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9149 | TAG, "Reporting visible in " + wtoken |
| 9150 | + " visible=" + nowVisible |
| 9151 | + " gone=" + nowGone); |
| 9152 | if (nowVisible) { |
| 9153 | wtoken.appToken.windowsVisible(); |
| 9154 | } else { |
| 9155 | wtoken.appToken.windowsGone(); |
| 9156 | } |
| 9157 | } catch (RemoteException ex) { |
| 9158 | } |
| 9159 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9160 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9161 | case WINDOW_FREEZE_TIMEOUT: { |
| 9162 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9163 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9164 | int i = mWindows.size(); |
| 9165 | while (i > 0) { |
| 9166 | i--; |
| 9167 | WindowState w = (WindowState)mWindows.get(i); |
| 9168 | if (w.mOrientationChanging) { |
| 9169 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9170 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9171 | } |
| 9172 | } |
| 9173 | performLayoutAndPlaceSurfacesLocked(); |
| 9174 | } |
| 9175 | break; |
| 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 | case HOLD_SCREEN_CHANGED: { |
| 9179 | Session oldHold; |
| 9180 | Session newHold; |
| 9181 | synchronized (mWindowMap) { |
| 9182 | oldHold = mLastReportedHold; |
| 9183 | newHold = (Session)msg.obj; |
| 9184 | mLastReportedHold = newHold; |
| 9185 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9187 | if (oldHold != newHold) { |
| 9188 | try { |
| 9189 | if (oldHold != null) { |
| 9190 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 9191 | "window", |
| 9192 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9193 | } |
| 9194 | if (newHold != null) { |
| 9195 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 9196 | "window", |
| 9197 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9198 | } |
| 9199 | } catch (RemoteException e) { |
| 9200 | } |
| 9201 | } |
| 9202 | break; |
| 9203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9205 | case APP_TRANSITION_TIMEOUT: { |
| 9206 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9207 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9208 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9209 | "*** APP TRANSITION TIMEOUT"); |
| 9210 | mAppTransitionReady = true; |
| 9211 | mAppTransitionTimeout = true; |
| 9212 | performLayoutAndPlaceSurfacesLocked(); |
| 9213 | } |
| 9214 | } |
| 9215 | break; |
| 9216 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | case PERSIST_ANIMATION_SCALE: { |
| 9219 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9220 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9221 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9222 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9223 | break; |
| 9224 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9226 | case FORCE_GC: { |
| 9227 | synchronized(mWindowMap) { |
| 9228 | if (mAnimationPending) { |
| 9229 | // If we are animating, don't do the gc now but |
| 9230 | // delay a bit so we don't interrupt the animation. |
| 9231 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9232 | 2000); |
| 9233 | return; |
| 9234 | } |
| 9235 | // If we are currently rotating the display, it will |
| 9236 | // schedule a new message when done. |
| 9237 | if (mDisplayFrozen) { |
| 9238 | return; |
| 9239 | } |
| 9240 | mFreezeGcPending = 0; |
| 9241 | } |
| 9242 | Runtime.getRuntime().gc(); |
| 9243 | break; |
| 9244 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9246 | case ENABLE_SCREEN: { |
| 9247 | performEnableScreen(); |
| 9248 | break; |
| 9249 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9251 | case APP_FREEZE_TIMEOUT: { |
| 9252 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9253 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9254 | int i = mAppTokens.size(); |
| 9255 | while (i > 0) { |
| 9256 | i--; |
| 9257 | AppWindowToken tok = mAppTokens.get(i); |
| 9258 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9259 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9260 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9261 | } |
| 9262 | } |
| 9263 | } |
| 9264 | break; |
| 9265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9266 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9267 | case SEND_NEW_CONFIGURATION: { |
| 9268 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9269 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9270 | break; |
| 9271 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9273 | } |
| 9274 | } |
| 9275 | } |
| 9276 | |
| 9277 | // ------------------------------------------------------------- |
| 9278 | // IWindowManager API |
| 9279 | // ------------------------------------------------------------- |
| 9280 | |
| 9281 | public IWindowSession openSession(IInputMethodClient client, |
| 9282 | IInputContext inputContext) { |
| 9283 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9284 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 9285 | return new Session(client, inputContext); |
| 9286 | } |
| 9287 | |
| 9288 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9289 | synchronized (mWindowMap) { |
| 9290 | // The focus for the client is the window immediately below |
| 9291 | // where we would place the input method window. |
| 9292 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9293 | WindowState imFocus; |
| 9294 | if (idx > 0) { |
| 9295 | imFocus = (WindowState)mWindows.get(idx-1); |
| 9296 | if (imFocus != null) { |
| 9297 | if (imFocus.mSession.mClient != null && |
| 9298 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9299 | return true; |
| 9300 | } |
| 9301 | } |
| 9302 | } |
| 9303 | } |
| 9304 | return false; |
| 9305 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9306 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9307 | // ------------------------------------------------------------- |
| 9308 | // Internals |
| 9309 | // ------------------------------------------------------------- |
| 9310 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9311 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9312 | boolean throwOnError) { |
| 9313 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9314 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9315 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9316 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9317 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9318 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9319 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | TAG, "Looking up client " + client + ": " + win); |
| 9321 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9322 | RuntimeException ex = new IllegalArgumentException( |
| 9323 | "Requested window " + client + " does not exist"); |
| 9324 | if (throwOnError) { |
| 9325 | throw ex; |
| 9326 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9327 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9328 | return null; |
| 9329 | } |
| 9330 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9331 | RuntimeException ex = new IllegalArgumentException( |
| 9332 | "Requested window " + client + " is in session " + |
| 9333 | win.mSession + ", not " + session); |
| 9334 | if (throwOnError) { |
| 9335 | throw ex; |
| 9336 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9337 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9338 | return null; |
| 9339 | } |
| 9340 | |
| 9341 | return win; |
| 9342 | } |
| 9343 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9344 | final void rebuildAppWindowListLocked() { |
| 9345 | int NW = mWindows.size(); |
| 9346 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9347 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9348 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9349 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9350 | // First remove all existing app windows. |
| 9351 | i=0; |
| 9352 | while (i < NW) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9353 | WindowState w = (WindowState)mWindows.get(i); |
| 9354 | if (w.mAppToken != null) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9355 | WindowState win = (WindowState)mWindows.remove(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9356 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9357 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9358 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9359 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9360 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9361 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9362 | && lastWallpaper == i-1) { |
| 9363 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9364 | } |
| 9365 | i++; |
| 9366 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9367 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9368 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9369 | // so skip them before adding app tokens. |
| 9370 | lastWallpaper++; |
| 9371 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9372 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9373 | // First add all of the exiting app tokens... these are no longer |
| 9374 | // in the main app list, but still have windows shown. We put them |
| 9375 | // in the back because now that the animation is over we no longer |
| 9376 | // will care about them. |
| 9377 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9378 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9379 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9380 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9381 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9382 | // And add in the still active app tokens in Z order. |
| 9383 | NT = mAppTokens.size(); |
| 9384 | for (int j=0; j<NT; j++) { |
| 9385 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9386 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9387 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9388 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9389 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9390 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9391 | + " windows but added " + i); |
| 9392 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9393 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9394 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9395 | private final void assignLayersLocked() { |
| 9396 | int N = mWindows.size(); |
| 9397 | int curBaseLayer = 0; |
| 9398 | int curLayer = 0; |
| 9399 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9401 | for (i=0; i<N; i++) { |
| 9402 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9403 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9404 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9405 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9406 | w.mLayer = curLayer; |
| 9407 | } else { |
| 9408 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9409 | w.mLayer = curLayer; |
| 9410 | } |
| 9411 | if (w.mTargetAppToken != null) { |
| 9412 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9413 | } else if (w.mAppToken != null) { |
| 9414 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9415 | } else { |
| 9416 | w.mAnimLayer = w.mLayer; |
| 9417 | } |
| 9418 | if (w.mIsImWindow) { |
| 9419 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9420 | } else if (w.mIsWallpaper) { |
| 9421 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9422 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9423 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9424 | + w.mAnimLayer); |
| 9425 | //System.out.println( |
| 9426 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9427 | } |
| 9428 | } |
| 9429 | |
| 9430 | private boolean mInLayout = false; |
| 9431 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9432 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9433 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9434 | throw new RuntimeException("Recursive call!"); |
| 9435 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9436 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9437 | return; |
| 9438 | } |
| 9439 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9440 | if (mWaitingForConfig) { |
| 9441 | // Our configuration has changed (most likely rotation), but we |
| 9442 | // don't yet have the complete configuration to report to |
| 9443 | // applications. Don't do any window layout until we have it. |
| 9444 | return; |
| 9445 | } |
| 9446 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9447 | boolean recoveringMemory = false; |
| 9448 | if (mForceRemoves != null) { |
| 9449 | recoveringMemory = true; |
| 9450 | // Wait a little it for things to settle down, and off we go. |
| 9451 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9452 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9453 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9454 | removeWindowInnerLocked(ws.mSession, ws); |
| 9455 | } |
| 9456 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9457 | 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] | 9458 | Object tmp = new Object(); |
| 9459 | synchronized (tmp) { |
| 9460 | try { |
| 9461 | tmp.wait(250); |
| 9462 | } catch (InterruptedException e) { |
| 9463 | } |
| 9464 | } |
| 9465 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9466 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9467 | mInLayout = true; |
| 9468 | try { |
| 9469 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9471 | int i = mPendingRemove.size()-1; |
| 9472 | if (i >= 0) { |
| 9473 | while (i >= 0) { |
| 9474 | WindowState w = mPendingRemove.get(i); |
| 9475 | removeWindowInnerLocked(w.mSession, w); |
| 9476 | i--; |
| 9477 | } |
| 9478 | mPendingRemove.clear(); |
| 9479 | |
| 9480 | mInLayout = false; |
| 9481 | assignLayersLocked(); |
| 9482 | mLayoutNeeded = true; |
| 9483 | performLayoutAndPlaceSurfacesLocked(); |
| 9484 | |
| 9485 | } else { |
| 9486 | mInLayout = false; |
| 9487 | if (mLayoutNeeded) { |
| 9488 | requestAnimationLocked(0); |
| 9489 | } |
| 9490 | } |
| 9491 | } catch (RuntimeException e) { |
| 9492 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9493 | 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] | 9494 | } |
| 9495 | } |
| 9496 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9497 | private final int performLayoutLockedInner() { |
| 9498 | if (!mLayoutNeeded) { |
| 9499 | return 0; |
| 9500 | } |
| 9501 | |
| 9502 | mLayoutNeeded = false; |
| 9503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9504 | final int dw = mDisplay.getWidth(); |
| 9505 | final int dh = mDisplay.getHeight(); |
| 9506 | |
| 9507 | final int N = mWindows.size(); |
| 9508 | int i; |
| 9509 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9510 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9511 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9512 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9513 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9514 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9515 | int seq = mLayoutSeq+1; |
| 9516 | if (seq < 0) seq = 0; |
| 9517 | mLayoutSeq = seq; |
| 9518 | |
| 9519 | // First perform layout of any root windows (not attached |
| 9520 | // to another window). |
| 9521 | int topAttached = -1; |
| 9522 | for (i = N-1; i >= 0; i--) { |
| 9523 | WindowState win = (WindowState) mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9524 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9525 | // Don't do layout of a window if it is not visible, or |
| 9526 | // soon won't be visible, to avoid wasting time and funky |
| 9527 | // changes while a window is animating away. |
| 9528 | final AppWindowToken atoken = win.mAppToken; |
| 9529 | final boolean gone = win.mViewVisibility == View.GONE |
| 9530 | || !win.mRelayoutCalled |
| 9531 | || win.mRootToken.hidden |
| 9532 | || (atoken != null && atoken.hiddenRequested) |
| 9533 | || win.mAttachedHidden |
| 9534 | || win.mExiting || win.mDestroying; |
| 9535 | |
| 9536 | if (!win.mLayoutAttached) { |
| 9537 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 9538 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9539 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9540 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 9541 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9542 | + win.mRelayoutCalled + " hidden=" |
| 9543 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9544 | + (atoken != null && atoken.hiddenRequested) |
| 9545 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9546 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9547 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9548 | // If this view is GONE, then skip it -- keep the current |
| 9549 | // frame, and let the caller know so they can ignore it |
| 9550 | // if they want. (We do the normal layout for INVISIBLE |
| 9551 | // windows, since that means "perform layout as normal, |
| 9552 | // just don't display"). |
| 9553 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9554 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9555 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9556 | win.mLayoutSeq = seq; |
| 9557 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9558 | + win.mFrame + " mContainingFrame=" |
| 9559 | + win.mContainingFrame + " mDisplayFrame=" |
| 9560 | + win.mDisplayFrame); |
| 9561 | } else { |
| 9562 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9563 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9564 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9565 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9566 | |
| 9567 | // Now perform layout of attached windows, which usually |
| 9568 | // depend on the position of the window they are attached to. |
| 9569 | // XXX does not deal with windows that are attached to windows |
| 9570 | // that are themselves attached. |
| 9571 | for (i = topAttached; i >= 0; i--) { |
| 9572 | WindowState win = (WindowState) mWindows.get(i); |
| 9573 | |
| 9574 | // If this view is GONE, then skip it -- keep the current |
| 9575 | // frame, and let the caller know so they can ignore it |
| 9576 | // if they want. (We do the normal layout for INVISIBLE |
| 9577 | // windows, since that means "perform layout as normal, |
| 9578 | // just don't display"). |
| 9579 | if (win.mLayoutAttached) { |
| 9580 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9581 | + " mHaveFrame=" + win.mHaveFrame |
| 9582 | + " mViewVisibility=" + win.mViewVisibility |
| 9583 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 9584 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9585 | || !win.mHaveFrame) { |
| 9586 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9587 | win.mLayoutSeq = seq; |
| 9588 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9589 | + win.mFrame + " mContainingFrame=" |
| 9590 | + win.mContainingFrame + " mDisplayFrame=" |
| 9591 | + win.mDisplayFrame); |
| 9592 | } |
| 9593 | } |
| 9594 | } |
| 9595 | |
| 9596 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9597 | } |
| 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 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9600 | boolean recoveringMemory) { |
| 9601 | final long currentTime = SystemClock.uptimeMillis(); |
| 9602 | final int dw = mDisplay.getWidth(); |
| 9603 | final int dh = mDisplay.getHeight(); |
| 9604 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9605 | int i; |
| 9606 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9607 | if (mFocusMayChange) { |
| 9608 | mFocusMayChange = false; |
| 9609 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9610 | } |
| 9611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9612 | if (mFxSession == null) { |
| 9613 | mFxSession = new SurfaceSession(); |
| 9614 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9615 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9616 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9617 | |
| 9618 | // Initialize state of exiting tokens. |
| 9619 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9620 | mExitingTokens.get(i).hasVisible = false; |
| 9621 | } |
| 9622 | |
| 9623 | // Initialize state of exiting applications. |
| 9624 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9625 | mExitingAppTokens.get(i).hasVisible = false; |
| 9626 | } |
| 9627 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9628 | boolean orientationChangeComplete = true; |
| 9629 | Session holdScreen = null; |
| 9630 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9631 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9632 | boolean focusDisplayed = false; |
| 9633 | boolean animating = false; |
| 9634 | |
| 9635 | Surface.openTransaction(); |
| 9636 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9637 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9638 | int repeats = 0; |
| 9639 | int changes = 0; |
| 9640 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9641 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9642 | repeats++; |
| 9643 | if (repeats > 6) { |
| 9644 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9645 | mLayoutNeeded = false; |
| 9646 | break; |
| 9647 | } |
| 9648 | |
| 9649 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9650 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9651 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9652 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9653 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9654 | assignLayersLocked(); |
| 9655 | mLayoutNeeded = true; |
| 9656 | } |
| 9657 | } |
| 9658 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9659 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9660 | if (updateOrientationFromAppTokensLocked()) { |
| 9661 | mLayoutNeeded = true; |
| 9662 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9663 | } |
| 9664 | } |
| 9665 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9666 | mLayoutNeeded = true; |
| 9667 | } |
| 9668 | } |
| 9669 | |
| 9670 | // FIRST LOOP: Perform a layout, if needed. |
| 9671 | if (repeats < 4) { |
| 9672 | changes = performLayoutLockedInner(); |
| 9673 | if (changes != 0) { |
| 9674 | continue; |
| 9675 | } |
| 9676 | } else { |
| 9677 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9678 | changes = 0; |
| 9679 | } |
| 9680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9681 | final int transactionSequence = ++mTransactionSequence; |
| 9682 | |
| 9683 | // Update animations of all applications, including those |
| 9684 | // associated with exiting/removed apps |
| 9685 | boolean tokensAnimating = false; |
| 9686 | final int NAT = mAppTokens.size(); |
| 9687 | for (i=0; i<NAT; i++) { |
| 9688 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9689 | tokensAnimating = true; |
| 9690 | } |
| 9691 | } |
| 9692 | final int NEAT = mExitingAppTokens.size(); |
| 9693 | for (i=0; i<NEAT; i++) { |
| 9694 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9695 | tokensAnimating = true; |
| 9696 | } |
| 9697 | } |
| 9698 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9699 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9700 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9701 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9702 | + transactionSequence + " tokensAnimating=" |
| 9703 | + tokensAnimating); |
| 9704 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9705 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9706 | |
| 9707 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9708 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9709 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9710 | |
| 9711 | mPolicy.beginAnimationLw(dw, dh); |
| 9712 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9713 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9715 | for (i=N-1; i>=0; i--) { |
| 9716 | WindowState w = (WindowState)mWindows.get(i); |
| 9717 | |
| 9718 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9719 | |
| 9720 | if (w.mSurface != null) { |
| 9721 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9722 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9723 | if ((w.mAttrs.flags |
| 9724 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9725 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9726 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9727 | wallpaperMayChange = true; |
| 9728 | } |
| 9729 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9730 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9731 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9732 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9733 | animating = true; |
| 9734 | //w.dump(" "); |
| 9735 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9736 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9737 | wallpaperMayChange = true; |
| 9738 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9739 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9740 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9741 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9742 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9743 | "Animation done that could impact force hide: " |
| 9744 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9745 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9746 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9747 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9748 | forceHiding = true; |
| 9749 | } |
| 9750 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9751 | boolean changed; |
| 9752 | if (forceHiding) { |
| 9753 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9754 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9755 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9756 | } else { |
| 9757 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9758 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9759 | "Now policy shown: " + w); |
| 9760 | if (changed) { |
| 9761 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9762 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9763 | // Assume we will need to animate. If |
| 9764 | // we don't (because the wallpaper will |
| 9765 | // stay with the lock screen), then we will |
| 9766 | // clean up later. |
| 9767 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9768 | if (a != null) { |
| 9769 | w.setAnimation(a); |
| 9770 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9771 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9772 | if (mCurrentFocus == null || |
| 9773 | mCurrentFocus.mLayer < w.mLayer) { |
| 9774 | // We are showing on to of the current |
| 9775 | // focus, so re-evaluate focus to make |
| 9776 | // sure it is correct. |
| 9777 | mFocusMayChange = true; |
| 9778 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9779 | } |
| 9780 | } |
| 9781 | if (changed && (attrs.flags |
| 9782 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9783 | wallpaperMayChange = true; |
| 9784 | } |
| 9785 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9786 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9787 | mPolicy.animatingWindowLw(w, attrs); |
| 9788 | } |
| 9789 | |
| 9790 | final AppWindowToken atoken = w.mAppToken; |
| 9791 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9792 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9793 | atoken.lastTransactionSequence = transactionSequence; |
| 9794 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9795 | atoken.startingDisplayed = false; |
| 9796 | } |
| 9797 | if ((w.isOnScreen() || w.mAttrs.type |
| 9798 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9799 | && !w.mExiting && !w.mDestroying) { |
| 9800 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9801 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9802 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9803 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9804 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9805 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9806 | + " pv=" + w.mPolicyVisibility |
| 9807 | + " dp=" + w.mDrawPending |
| 9808 | + " cdp=" + w.mCommitDrawPending |
| 9809 | + " ah=" + w.mAttachedHidden |
| 9810 | + " th=" + atoken.hiddenRequested |
| 9811 | + " a=" + w.mAnimating); |
| 9812 | } |
| 9813 | } |
| 9814 | if (w != atoken.startingWindow) { |
| 9815 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9816 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9817 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9818 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9819 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9820 | "tokenMayBeDrawn: " + atoken |
| 9821 | + " freezingScreen=" + atoken.freezingScreen |
| 9822 | + " mAppFreezing=" + w.mAppFreezing); |
| 9823 | tokenMayBeDrawn = true; |
| 9824 | } |
| 9825 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9826 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9827 | atoken.startingDisplayed = true; |
| 9828 | } |
| 9829 | } |
| 9830 | } else if (w.mReadyToShow) { |
| 9831 | w.performShowLocked(); |
| 9832 | } |
| 9833 | } |
| 9834 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9835 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9836 | |
| 9837 | if (tokenMayBeDrawn) { |
| 9838 | // See if any windows have been drawn, so they (and others |
| 9839 | // associated with them) can now be shown. |
| 9840 | final int NT = mTokenList.size(); |
| 9841 | for (i=0; i<NT; i++) { |
| 9842 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9843 | if (wtoken == null) { |
| 9844 | continue; |
| 9845 | } |
| 9846 | if (wtoken.freezingScreen) { |
| 9847 | int numInteresting = wtoken.numInterestingWindows; |
| 9848 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9849 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9850 | "allDrawn: " + wtoken |
| 9851 | + " interesting=" + numInteresting |
| 9852 | + " drawn=" + wtoken.numDrawnWindows); |
| 9853 | wtoken.showAllWindowsLocked(); |
| 9854 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9855 | orientationChangeComplete = true; |
| 9856 | } |
| 9857 | } else if (!wtoken.allDrawn) { |
| 9858 | int numInteresting = wtoken.numInterestingWindows; |
| 9859 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9860 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9861 | "allDrawn: " + wtoken |
| 9862 | + " interesting=" + numInteresting |
| 9863 | + " drawn=" + wtoken.numDrawnWindows); |
| 9864 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9865 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9866 | |
| 9867 | // We can now show all of the drawn windows! |
| 9868 | if (!mOpeningApps.contains(wtoken)) { |
| 9869 | wtoken.showAllWindowsLocked(); |
| 9870 | } |
| 9871 | } |
| 9872 | } |
| 9873 | } |
| 9874 | } |
| 9875 | |
| 9876 | // If we are ready to perform an app transition, check through |
| 9877 | // all of the app tokens to be shown and see if they are ready |
| 9878 | // to go. |
| 9879 | if (mAppTransitionReady) { |
| 9880 | int NN = mOpeningApps.size(); |
| 9881 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9882 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9883 | "Checking " + NN + " opening apps (frozen=" |
| 9884 | + mDisplayFrozen + " timeout=" |
| 9885 | + mAppTransitionTimeout + ")..."); |
| 9886 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9887 | // If the display isn't frozen, wait to do anything until |
| 9888 | // all of the apps are ready. Otherwise just go because |
| 9889 | // we'll unfreeze the display when everyone is ready. |
| 9890 | for (i=0; i<NN && goodToGo; i++) { |
| 9891 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9892 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9893 | "Check opening app" + wtoken + ": allDrawn=" |
| 9894 | + wtoken.allDrawn + " startingDisplayed=" |
| 9895 | + wtoken.startingDisplayed); |
| 9896 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9897 | && !wtoken.startingMoved) { |
| 9898 | goodToGo = false; |
| 9899 | } |
| 9900 | } |
| 9901 | } |
| 9902 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9903 | 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] | 9904 | int transit = mNextAppTransition; |
| 9905 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9906 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9907 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9908 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9909 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9910 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9911 | mAppTransitionTimeout = false; |
| 9912 | mStartingIconInTransition = false; |
| 9913 | mSkipAppTransitionAnimation = false; |
| 9914 | |
| 9915 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9916 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9917 | // If there are applications waiting to come to the |
| 9918 | // top of the stack, now is the time to move their windows. |
| 9919 | // (Note that we don't do apps going to the bottom |
| 9920 | // here -- we want to keep their windows in the old |
| 9921 | // Z-order until the animation completes.) |
| 9922 | if (mToTopApps.size() > 0) { |
| 9923 | NN = mAppTokens.size(); |
| 9924 | for (i=0; i<NN; i++) { |
| 9925 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9926 | if (wtoken.sendingToTop) { |
| 9927 | wtoken.sendingToTop = false; |
| 9928 | moveAppWindowsLocked(wtoken, NN, false); |
| 9929 | } |
| 9930 | } |
| 9931 | mToTopApps.clear(); |
| 9932 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9933 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9934 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9935 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9936 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9937 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9938 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9939 | // The top-most window will supply the layout params, |
| 9940 | // and we will determine it below. |
| 9941 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9942 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9943 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9944 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9945 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9946 | "New wallpaper target=" + mWallpaperTarget |
| 9947 | + ", lower target=" + mLowerWallpaperTarget |
| 9948 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9949 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9950 | // Do a first pass through the tokens for two |
| 9951 | // things: |
| 9952 | // (1) Determine if both the closing and opening |
| 9953 | // app token sets are wallpaper targets, in which |
| 9954 | // case special animations are needed |
| 9955 | // (since the wallpaper needs to stay static |
| 9956 | // behind them). |
| 9957 | // (2) Find the layout params of the top-most |
| 9958 | // application window in the tokens, which is |
| 9959 | // what will control the animation theme. |
| 9960 | final int NC = mClosingApps.size(); |
| 9961 | NN = NC + mOpeningApps.size(); |
| 9962 | for (i=0; i<NN; i++) { |
| 9963 | AppWindowToken wtoken; |
| 9964 | int mode; |
| 9965 | if (i < NC) { |
| 9966 | wtoken = mClosingApps.get(i); |
| 9967 | mode = 1; |
| 9968 | } else { |
| 9969 | wtoken = mOpeningApps.get(i-NC); |
| 9970 | mode = 2; |
| 9971 | } |
| 9972 | if (mLowerWallpaperTarget != null) { |
| 9973 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9974 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9975 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9976 | } |
| 9977 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9978 | if (wtoken.appFullscreen) { |
| 9979 | WindowState ws = wtoken.findMainWindow(); |
| 9980 | if (ws != null) { |
| 9981 | // If this is a compatibility mode |
| 9982 | // window, we will always use its anim. |
| 9983 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9984 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9985 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9986 | bestAnimLayer = Integer.MAX_VALUE; |
| 9987 | } else if (ws.mLayer > bestAnimLayer) { |
| 9988 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9989 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9990 | bestAnimLayer = ws.mLayer; |
| 9991 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9992 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9993 | } |
| 9994 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9995 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9996 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9997 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9998 | "Wallpaper animation!"); |
| 9999 | switch (transit) { |
| 10000 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 10001 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 10002 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 10003 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 10004 | break; |
| 10005 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 10006 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 10007 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 10008 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 10009 | break; |
| 10010 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10011 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10012 | "New transit: " + transit); |
| 10013 | } else if (oldWallpaper != null) { |
| 10014 | // We are transitioning from an activity with |
| 10015 | // a wallpaper to one without. |
| 10016 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10017 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10018 | "New transit away from wallpaper: " + transit); |
| 10019 | } else if (mWallpaperTarget != null) { |
| 10020 | // We are transitioning from an activity without |
| 10021 | // a wallpaper to now showing the wallpaper |
| 10022 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10023 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10024 | "New transit into wallpaper: " + transit); |
| 10025 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10026 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10027 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 10028 | mLastEnterAnimToken = animToken; |
| 10029 | mLastEnterAnimParams = animLp; |
| 10030 | } else if (mLastEnterAnimParams != null) { |
| 10031 | animLp = mLastEnterAnimParams; |
| 10032 | mLastEnterAnimToken = null; |
| 10033 | mLastEnterAnimParams = null; |
| 10034 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10035 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10036 | // If all closing windows are obscured, then there is |
| 10037 | // no need to do an animation. This is the case, for |
| 10038 | // example, when this transition is being done behind |
| 10039 | // the lock screen. |
| 10040 | if (!mPolicy.allowAppAnimationsLw()) { |
| 10041 | animLp = null; |
| 10042 | } |
| 10043 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10044 | NN = mOpeningApps.size(); |
| 10045 | for (i=0; i<NN; i++) { |
| 10046 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10047 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10048 | "Now opening app" + wtoken); |
| 10049 | wtoken.reportedVisible = false; |
| 10050 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10051 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10052 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10053 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10054 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10055 | wtoken.showAllWindowsLocked(); |
| 10056 | } |
| 10057 | NN = mClosingApps.size(); |
| 10058 | for (i=0; i<NN; i++) { |
| 10059 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10060 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10061 | "Now closing app" + wtoken); |
| 10062 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10063 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10064 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10065 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10066 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10067 | // Force the allDrawn flag, because we want to start |
| 10068 | // this guy's animations regardless of whether it's |
| 10069 | // gotten drawn. |
| 10070 | wtoken.allDrawn = true; |
| 10071 | } |
| 10072 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10073 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10074 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10075 | mOpeningApps.clear(); |
| 10076 | mClosingApps.clear(); |
| 10077 | |
| 10078 | // This has changed the visibility of windows, so perform |
| 10079 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10080 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10081 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10082 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10083 | assignLayersLocked(); |
| 10084 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10085 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10086 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10087 | } |
| 10088 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10089 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10090 | int adjResult = 0; |
| 10091 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10092 | if (!animating && mAppTransitionRunning) { |
| 10093 | // We have finished the animation of an app transition. To do |
| 10094 | // this, we have delayed a lot of operations like showing and |
| 10095 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10096 | // reflects the correct Z-order, but the window list may now |
| 10097 | // be out of sync with it. So here we will just rebuild the |
| 10098 | // entire app window list. Fun! |
| 10099 | mAppTransitionRunning = false; |
| 10100 | // Clear information about apps that were moving. |
| 10101 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10102 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10103 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10104 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10105 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10106 | moveInputMethodWindowsIfNeededLocked(false); |
| 10107 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10108 | // Since the window list has been rebuilt, focus might |
| 10109 | // have to be recomputed since the actual order of windows |
| 10110 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10111 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10112 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10113 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10114 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10115 | // At this point, there was a window with a wallpaper that |
| 10116 | // was force hiding other windows behind it, but now it |
| 10117 | // is going away. This may be simple -- just animate |
| 10118 | // away the wallpaper and its window -- or it may be |
| 10119 | // hard -- the wallpaper now needs to be shown behind |
| 10120 | // something that was hidden. |
| 10121 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10122 | if (mLowerWallpaperTarget != null |
| 10123 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10124 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10125 | "wallpaperForceHiding changed with lower=" |
| 10126 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10127 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10128 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10129 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10130 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10131 | // The lower target has become hidden before we |
| 10132 | // actually started the animation... let's completely |
| 10133 | // re-evaluate everything. |
| 10134 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10135 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10136 | } |
| 10137 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10138 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10139 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10140 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10141 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10142 | + " NEW: " + mWallpaperTarget |
| 10143 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10144 | if (mLowerWallpaperTarget == null) { |
| 10145 | // Whoops, we don't need a special wallpaper animation. |
| 10146 | // Clear them out. |
| 10147 | forceHiding = false; |
| 10148 | for (i=N-1; i>=0; i--) { |
| 10149 | WindowState w = (WindowState)mWindows.get(i); |
| 10150 | if (w.mSurface != null) { |
| 10151 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10152 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10153 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10154 | forceHiding = true; |
| 10155 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10156 | if (!w.mAnimating) { |
| 10157 | // We set the animation above so it |
| 10158 | // is not yet running. |
| 10159 | w.clearAnimation(); |
| 10160 | } |
| 10161 | } |
| 10162 | } |
| 10163 | } |
| 10164 | } |
| 10165 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10166 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10167 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10168 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10169 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10170 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10171 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10172 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10173 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10174 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10175 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10176 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10177 | assignLayersLocked(); |
| 10178 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10179 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10180 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10181 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10182 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10183 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10184 | if (mFocusMayChange) { |
| 10185 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10186 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10187 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10188 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10189 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10190 | } |
| 10191 | |
| 10192 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10193 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10194 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10195 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10196 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10197 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10198 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10199 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10200 | |
| 10201 | // THIRD LOOP: Update the surfaces of all windows. |
| 10202 | |
| 10203 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10204 | |
| 10205 | boolean obscured = false; |
| 10206 | boolean blurring = false; |
| 10207 | boolean dimming = false; |
| 10208 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10209 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10210 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10211 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10212 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10213 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10214 | for (i=N-1; i>=0; i--) { |
| 10215 | WindowState w = (WindowState)mWindows.get(i); |
| 10216 | |
| 10217 | boolean displayed = false; |
| 10218 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10219 | final int attrFlags = attrs.flags; |
| 10220 | |
| 10221 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10222 | // XXX NOTE: The logic here could be improved. We have |
| 10223 | // the decision about whether to resize a window separated |
| 10224 | // from whether to hide the surface. This can cause us to |
| 10225 | // resize a surface even if we are going to hide it. You |
| 10226 | // can see this by (1) holding device in landscape mode on |
| 10227 | // home screen; (2) tapping browser icon (device will rotate |
| 10228 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10229 | // in step 2 but then immediately hidden, causing us to |
| 10230 | // have to resize and then redraw it again in step 3. It |
| 10231 | // would be nice to figure out how to avoid this, but it is |
| 10232 | // difficult because we do need to resize surfaces in some |
| 10233 | // cases while they are hidden such as when first showing a |
| 10234 | // window. |
| 10235 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10236 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10237 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10238 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10239 | + ": new=" + w.mShownFrame + ", old=" |
| 10240 | + w.mLastShownFrame); |
| 10241 | |
| 10242 | boolean resize; |
| 10243 | int width, height; |
| 10244 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 10245 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 10246 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 10247 | // for a scaled surface, we just want to use |
| 10248 | // the requested size. |
| 10249 | width = w.mRequestedWidth; |
| 10250 | height = w.mRequestedHeight; |
| 10251 | w.mLastRequestedWidth = width; |
| 10252 | w.mLastRequestedHeight = height; |
| 10253 | w.mLastShownFrame.set(w.mShownFrame); |
| 10254 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10255 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10256 | "POS " + w.mShownFrame.left |
| 10257 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10258 | w.mSurfaceX = w.mShownFrame.left; |
| 10259 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10260 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10261 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10262 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10263 | if (!recoveringMemory) { |
| 10264 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10265 | } |
| 10266 | } |
| 10267 | } else { |
| 10268 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 10269 | width = w.mShownFrame.width(); |
| 10270 | height = w.mShownFrame.height(); |
| 10271 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10272 | } |
| 10273 | |
| 10274 | if (resize) { |
| 10275 | if (width < 1) width = 1; |
| 10276 | if (height < 1) height = 1; |
| 10277 | if (w.mSurface != null) { |
| 10278 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10279 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10280 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10281 | + w.mShownFrame.top + " SIZE " |
| 10282 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10283 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10284 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10285 | w.mSurfaceW = width; |
| 10286 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10287 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10288 | w.mSurfaceX = w.mShownFrame.left; |
| 10289 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10290 | w.mSurface.setPosition(w.mShownFrame.left, |
| 10291 | w.mShownFrame.top); |
| 10292 | } catch (RuntimeException e) { |
| 10293 | // If something goes wrong with the surface (such |
| 10294 | // as running out of memory), don't take down the |
| 10295 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10296 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10297 | + "size=(" + width + "x" + height |
| 10298 | + "), pos=(" + w.mShownFrame.left |
| 10299 | + "," + w.mShownFrame.top + ")", e); |
| 10300 | if (!recoveringMemory) { |
| 10301 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10302 | } |
| 10303 | } |
| 10304 | } |
| 10305 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10306 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10307 | w.mContentInsetsChanged = |
| 10308 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10309 | w.mVisibleInsetsChanged = |
| 10310 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10311 | boolean configChanged = |
| 10312 | w.mConfiguration != mCurConfiguration |
| 10313 | && (w.mConfiguration == null |
| 10314 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10315 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10316 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10317 | + mCurConfiguration); |
| 10318 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10319 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10320 | + ": configChanged=" + configChanged |
| 10321 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10322 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10323 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10324 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10325 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10326 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10327 | w.mLastFrame.set(w.mFrame); |
| 10328 | w.mLastContentInsets.set(w.mContentInsets); |
| 10329 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10330 | // If the screen is currently frozen, then keep |
| 10331 | // it frozen until this window draws at its new |
| 10332 | // orientation. |
| 10333 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10334 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10335 | "Resizing while display frozen: " + w); |
| 10336 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10337 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10338 | mWindowsFreezingScreen = true; |
| 10339 | // XXX should probably keep timeout from |
| 10340 | // when we first froze the display. |
| 10341 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10342 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10343 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10344 | } |
| 10345 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10346 | // If the orientation is changing, then we need to |
| 10347 | // hold off on unfreezing the display until this |
| 10348 | // window has been redrawn; to do that, we need |
| 10349 | // to go through the process of getting informed |
| 10350 | // by the application when it has finished drawing. |
| 10351 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10352 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10353 | "Orientation start waiting for draw in " |
| 10354 | + w + ", surface " + w.mSurface); |
| 10355 | w.mDrawPending = true; |
| 10356 | w.mCommitDrawPending = false; |
| 10357 | w.mReadyToShow = false; |
| 10358 | if (w.mAppToken != null) { |
| 10359 | w.mAppToken.allDrawn = false; |
| 10360 | } |
| 10361 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10362 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10363 | "Resizing window " + w + " to " + w.mFrame); |
| 10364 | mResizingWindows.add(w); |
| 10365 | } else if (w.mOrientationChanging) { |
| 10366 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10367 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10368 | "Orientation not waiting for draw in " |
| 10369 | + w + ", surface " + w.mSurface); |
| 10370 | w.mOrientationChanging = false; |
| 10371 | } |
| 10372 | } |
| 10373 | } |
| 10374 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10375 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10376 | if (!w.mLastHidden) { |
| 10377 | //dump(); |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 10378 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow=" |
| 10379 | + w.mRootToken.waitingToShow + " polvis=" |
| 10380 | + w.mPolicyVisibility + " atthid=" |
| 10381 | + w.mAttachedHidden + " tokhid=" |
| 10382 | + w.mRootToken.hidden + " vis=" |
| 10383 | + w.mViewVisibility); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10384 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10385 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10386 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10387 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10388 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10389 | try { |
| 10390 | w.mSurface.hide(); |
| 10391 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10392 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10393 | } |
| 10394 | } |
| 10395 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 10396 | } |
| 10397 | // If we are waiting for this window to handle an |
| 10398 | // orientation change, well, it is hidden, so |
| 10399 | // doesn't really matter. Note that this does |
| 10400 | // introduce a potential glitch if the window |
| 10401 | // becomes unhidden before it has drawn for the |
| 10402 | // new orientation. |
| 10403 | if (w.mOrientationChanging) { |
| 10404 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10405 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10406 | "Orientation change skips hidden " + w); |
| 10407 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10408 | } else if (w.mLastLayer != w.mAnimLayer |
| 10409 | || w.mLastAlpha != w.mShownAlpha |
| 10410 | || w.mLastDsDx != w.mDsDx |
| 10411 | || w.mLastDtDx != w.mDtDx |
| 10412 | || w.mLastDsDy != w.mDsDy |
| 10413 | || w.mLastDtDy != w.mDtDy |
| 10414 | || w.mLastHScale != w.mHScale |
| 10415 | || w.mLastVScale != w.mVScale |
| 10416 | || w.mLastHidden) { |
| 10417 | displayed = true; |
| 10418 | w.mLastAlpha = w.mShownAlpha; |
| 10419 | w.mLastLayer = w.mAnimLayer; |
| 10420 | w.mLastDsDx = w.mDsDx; |
| 10421 | w.mLastDtDx = w.mDtDx; |
| 10422 | w.mLastDsDy = w.mDsDy; |
| 10423 | w.mLastDtDy = w.mDtDy; |
| 10424 | w.mLastHScale = w.mHScale; |
| 10425 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10426 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10427 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10428 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10429 | + "," + (w.mDtDx*w.mVScale) |
| 10430 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10431 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10432 | if (w.mSurface != null) { |
| 10433 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10434 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10435 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10436 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10437 | w.mSurface.setLayer(w.mAnimLayer); |
| 10438 | w.mSurface.setMatrix( |
| 10439 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10440 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10441 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10442 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10443 | if (!recoveringMemory) { |
| 10444 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10445 | } |
| 10446 | } |
| 10447 | } |
| 10448 | |
| 10449 | if (w.mLastHidden && !w.mDrawPending |
| 10450 | && !w.mCommitDrawPending |
| 10451 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10452 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10453 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10454 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10455 | + " during relayout"); |
| 10456 | if (showSurfaceRobustlyLocked(w)) { |
| 10457 | w.mHasDrawn = true; |
| 10458 | w.mLastHidden = false; |
| 10459 | } else { |
| 10460 | w.mOrientationChanging = false; |
| 10461 | } |
| 10462 | } |
| 10463 | if (w.mSurface != null) { |
| 10464 | w.mToken.hasVisible = true; |
| 10465 | } |
| 10466 | } else { |
| 10467 | displayed = true; |
| 10468 | } |
| 10469 | |
| 10470 | if (displayed) { |
| 10471 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10472 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10473 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10474 | covered = true; |
| 10475 | } |
| 10476 | } |
| 10477 | if (w.mOrientationChanging) { |
| 10478 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10479 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10480 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10481 | "Orientation continue waiting for draw in " + w); |
| 10482 | } else { |
| 10483 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10484 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10485 | "Orientation change complete in " + w); |
| 10486 | } |
| 10487 | } |
| 10488 | w.mToken.hasVisible = true; |
| 10489 | } |
| 10490 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10491 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10492 | "Orientation change skips hidden " + w); |
| 10493 | w.mOrientationChanging = false; |
| 10494 | } |
| 10495 | |
| 10496 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10497 | |
| 10498 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10499 | focusDisplayed = true; |
| 10500 | } |
| 10501 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10502 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10504 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10505 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10506 | if (w.mSurface != null) { |
| 10507 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10508 | holdScreen = w.mSession; |
| 10509 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10510 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10511 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10512 | screenBrightness = w.mAttrs.screenBrightness; |
| 10513 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10514 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10515 | && buttonBrightness < 0) { |
| 10516 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10517 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10518 | if (canBeSeen |
| 10519 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10520 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10521 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10522 | syswin = true; |
| 10523 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10524 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10525 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10526 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10527 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10528 | // This window completely covers everything behind it, |
| 10529 | // so we want to leave all of them as unblurred (for |
| 10530 | // performance reasons). |
| 10531 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10532 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10533 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10534 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10535 | obscured = true; |
| 10536 | if (mBackgroundFillerSurface == null) { |
| 10537 | try { |
| 10538 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10539 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10540 | 0, dw, dh, |
| 10541 | PixelFormat.OPAQUE, |
| 10542 | Surface.FX_SURFACE_NORMAL); |
| 10543 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10544 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10545 | } |
| 10546 | } |
| 10547 | try { |
| 10548 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10549 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10550 | // Using the same layer as Dim because they will never be shown at the |
| 10551 | // same time. |
| 10552 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10553 | mBackgroundFillerSurface.show(); |
| 10554 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10555 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10556 | } |
| 10557 | backgroundFillerShown = true; |
| 10558 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10559 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10560 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10561 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10562 | + ": blurring=" + blurring |
| 10563 | + " obscured=" + obscured |
| 10564 | + " displayed=" + displayed); |
| 10565 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10566 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10567 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10568 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10569 | if (mDimAnimator == null) { |
| 10570 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10571 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10572 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10573 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10574 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10575 | } |
| 10576 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10577 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10578 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10579 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10580 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10581 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10582 | + mBlurSurface + ": CREATE"); |
| 10583 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10584 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10585 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10586 | -1, 16, 16, |
| 10587 | PixelFormat.OPAQUE, |
| 10588 | Surface.FX_SURFACE_BLUR); |
| 10589 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10590 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10591 | } |
| 10592 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10593 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10594 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10595 | + mBlurSurface + ": pos=(0,0) (" + |
| 10596 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10597 | mBlurSurface.setPosition(0, 0); |
| 10598 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10599 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10600 | if (!mBlurShown) { |
| 10601 | try { |
| 10602 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10603 | + mBlurSurface + ": SHOW"); |
| 10604 | mBlurSurface.show(); |
| 10605 | } catch (RuntimeException e) { |
| 10606 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10607 | } |
| 10608 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10609 | } |
| 10610 | } |
| 10611 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10612 | } |
| 10613 | } |
| 10614 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10615 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10616 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10617 | // This is the wallpaper target and its obscured state |
| 10618 | // changed... make sure the current wallaper's visibility |
| 10619 | // has been updated accordingly. |
| 10620 | updateWallpaperVisibilityLocked(); |
| 10621 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10622 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10623 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10624 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10625 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10626 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10627 | try { |
| 10628 | mBackgroundFillerSurface.hide(); |
| 10629 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10630 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10631 | } |
| 10632 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10633 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10634 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10635 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10636 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10637 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10638 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10639 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10640 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10641 | + ": HIDE"); |
| 10642 | try { |
| 10643 | mBlurSurface.hide(); |
| 10644 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10645 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | } |
| 10647 | mBlurShown = false; |
| 10648 | } |
| 10649 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10650 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10651 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10652 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10653 | } |
| 10654 | |
| 10655 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10656 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10657 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10658 | "With display frozen, orientationChangeComplete=" |
| 10659 | + orientationChangeComplete); |
| 10660 | if (orientationChangeComplete) { |
| 10661 | if (mWindowsFreezingScreen) { |
| 10662 | mWindowsFreezingScreen = false; |
| 10663 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10664 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10665 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10666 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10667 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10668 | i = mResizingWindows.size(); |
| 10669 | if (i > 0) { |
| 10670 | do { |
| 10671 | i--; |
| 10672 | WindowState win = mResizingWindows.get(i); |
| 10673 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10674 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10675 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10676 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10677 | boolean configChanged = |
| 10678 | win.mConfiguration != mCurConfiguration |
| 10679 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10680 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10681 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10682 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10683 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10684 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10685 | + " / " + mCurConfiguration + " / 0x" |
| 10686 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10687 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10688 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10689 | win.mClient.resized(win.mFrame.width(), |
| 10690 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10691 | win.mLastVisibleInsets, win.mDrawPending, |
| 10692 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10693 | win.mContentInsetsChanged = false; |
| 10694 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10695 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10696 | } catch (RemoteException e) { |
| 10697 | win.mOrientationChanging = false; |
| 10698 | } |
| 10699 | } while (i > 0); |
| 10700 | mResizingWindows.clear(); |
| 10701 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10702 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10703 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10704 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10705 | i = mDestroySurface.size(); |
| 10706 | if (i > 0) { |
| 10707 | do { |
| 10708 | i--; |
| 10709 | WindowState win = mDestroySurface.get(i); |
| 10710 | win.mDestroying = false; |
| 10711 | if (mInputMethodWindow == win) { |
| 10712 | mInputMethodWindow = null; |
| 10713 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10714 | if (win == mWallpaperTarget) { |
| 10715 | wallpaperDestroyed = true; |
| 10716 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10717 | win.destroySurfaceLocked(); |
| 10718 | } while (i > 0); |
| 10719 | mDestroySurface.clear(); |
| 10720 | } |
| 10721 | |
| 10722 | // Time to remove any exiting tokens? |
| 10723 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10724 | WindowToken token = mExitingTokens.get(i); |
| 10725 | if (!token.hasVisible) { |
| 10726 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10727 | if (token.windowType == TYPE_WALLPAPER) { |
| 10728 | mWallpaperTokens.remove(token); |
| 10729 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10730 | } |
| 10731 | } |
| 10732 | |
| 10733 | // Time to remove any exiting applications? |
| 10734 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10735 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10736 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10737 | // Make sure there is no animation running on this token, |
| 10738 | // so any windows associated with it will be removed as |
| 10739 | // soon as their animations are complete |
| 10740 | token.animation = null; |
| 10741 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10742 | mAppTokens.remove(token); |
| 10743 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10744 | if (mLastEnterAnimToken == token) { |
| 10745 | mLastEnterAnimToken = null; |
| 10746 | mLastEnterAnimParams = null; |
| 10747 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10748 | } |
| 10749 | } |
| 10750 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10751 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10752 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10753 | if (!animating && mAppTransitionRunning) { |
| 10754 | // We have finished the animation of an app transition. To do |
| 10755 | // this, we have delayed a lot of operations like showing and |
| 10756 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10757 | // reflects the correct Z-order, but the window list may now |
| 10758 | // be out of sync with it. So here we will just rebuild the |
| 10759 | // entire app window list. Fun! |
| 10760 | mAppTransitionRunning = false; |
| 10761 | needRelayout = true; |
| 10762 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10763 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10764 | // Clear information about apps that were moving. |
| 10765 | mToBottomApps.clear(); |
| 10766 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10767 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10768 | if (focusDisplayed) { |
| 10769 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10770 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10771 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10772 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10773 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10774 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10775 | requestAnimationLocked(0); |
| 10776 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10777 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10778 | } |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 10779 | |
| 10780 | if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen |
| 10781 | + " holdScreen=" + holdScreen); |
| 10782 | if (!mDisplayFrozen) { |
| 10783 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 10784 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10785 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10786 | } else { |
| 10787 | mPowerManager.setScreenBrightnessOverride((int) |
| 10788 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10789 | } |
| 10790 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10791 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10792 | } else { |
| 10793 | mPowerManager.setButtonBrightnessOverride((int) |
| 10794 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10795 | } |
| 10796 | if (holdScreen != mHoldingScreenOn) { |
| 10797 | mHoldingScreenOn = holdScreen; |
| 10798 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10799 | mH.sendMessage(m); |
| 10800 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10801 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10802 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10803 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10804 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10805 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10806 | LocalPowerManager.BUTTON_EVENT, true); |
| 10807 | mTurnOnScreen = false; |
| 10808 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10809 | |
| 10810 | // Check to see if we are now in a state where the screen should |
| 10811 | // be enabled, because the window obscured flags have changed. |
| 10812 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10813 | } |
| 10814 | |
| 10815 | void requestAnimationLocked(long delay) { |
| 10816 | if (!mAnimationPending) { |
| 10817 | mAnimationPending = true; |
| 10818 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10819 | } |
| 10820 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10821 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10822 | /** |
| 10823 | * Have the surface flinger show a surface, robustly dealing with |
| 10824 | * error conditions. In particular, if there is not enough memory |
| 10825 | * to show the surface, then we will try to get rid of other surfaces |
| 10826 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10827 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10828 | * @return Returns true if the surface was successfully shown. |
| 10829 | */ |
| 10830 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10831 | try { |
| 10832 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10833 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10834 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10835 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10836 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10837 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10838 | win.mTurnOnScreen = false; |
| 10839 | mTurnOnScreen = true; |
| 10840 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10841 | } |
| 10842 | return true; |
| 10843 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10844 | 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] | 10845 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10846 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10847 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10848 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10849 | return false; |
| 10850 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10851 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10852 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10853 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10854 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10855 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10856 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10857 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10858 | if (mForceRemoves == null) { |
| 10859 | mForceRemoves = new ArrayList<WindowState>(); |
| 10860 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10861 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10862 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10863 | try { |
| 10864 | // There was some problem... first, do a sanity check of the |
| 10865 | // window list to make sure we haven't left any dangling surfaces |
| 10866 | // around. |
| 10867 | int N = mWindows.size(); |
| 10868 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10869 | 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] | 10870 | for (int i=0; i<N; i++) { |
| 10871 | WindowState ws = (WindowState)mWindows.get(i); |
| 10872 | if (ws.mSurface != null) { |
| 10873 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10874 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10875 | + ws + " surface=" + ws.mSurface |
| 10876 | + " token=" + win.mToken |
| 10877 | + " pid=" + ws.mSession.mPid |
| 10878 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10879 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10880 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10881 | ws.mSurface = null; |
| 10882 | mForceRemoves.add(ws); |
| 10883 | i--; |
| 10884 | N--; |
| 10885 | leakedSurface = true; |
| 10886 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10887 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10888 | + ws + " surface=" + ws.mSurface |
| 10889 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10890 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10891 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10892 | ws.mSurface = null; |
| 10893 | leakedSurface = true; |
| 10894 | } |
| 10895 | } |
| 10896 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10897 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10898 | boolean killedApps = false; |
| 10899 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10900 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10901 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10902 | for (int i=0; i<N; i++) { |
| 10903 | WindowState ws = (WindowState)mWindows.get(i); |
| 10904 | if (ws.mSurface != null) { |
| 10905 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10906 | } |
| 10907 | } |
| 10908 | if (pidCandidates.size() > 0) { |
| 10909 | int[] pids = new int[pidCandidates.size()]; |
| 10910 | for (int i=0; i<pids.length; i++) { |
| 10911 | pids[i] = pidCandidates.keyAt(i); |
| 10912 | } |
| 10913 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10914 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10915 | killedApps = true; |
| 10916 | } |
| 10917 | } catch (RemoteException e) { |
| 10918 | } |
| 10919 | } |
| 10920 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10921 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10922 | if (leakedSurface || killedApps) { |
| 10923 | // We managed to reclaim some memory, so get rid of the trouble |
| 10924 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10925 | 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] | 10926 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10927 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10928 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10929 | win.mSurface = null; |
| 10930 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10932 | try { |
| 10933 | win.mClient.dispatchGetNewSurface(); |
| 10934 | } catch (RemoteException e) { |
| 10935 | } |
| 10936 | } |
| 10937 | } finally { |
| 10938 | Binder.restoreCallingIdentity(callingIdentity); |
| 10939 | } |
| 10940 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10942 | private boolean updateFocusedWindowLocked(int mode) { |
| 10943 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10944 | if (mCurrentFocus != newFocus) { |
| 10945 | // This check makes sure that we don't already have the focus |
| 10946 | // change message pending. |
| 10947 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10948 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10949 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10950 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10951 | final WindowState oldFocus = mCurrentFocus; |
| 10952 | mCurrentFocus = newFocus; |
| 10953 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10955 | final WindowState imWindow = mInputMethodWindow; |
| 10956 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10957 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10958 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10959 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10960 | mLayoutNeeded = true; |
| 10961 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10962 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10963 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10964 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10965 | // Client will do the layout, but we need to assign layers |
| 10966 | // for handleNewWindowLocked() below. |
| 10967 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10968 | } |
| 10969 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10970 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10971 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10972 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 10973 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10974 | return true; |
| 10975 | } |
| 10976 | return false; |
| 10977 | } |
| 10978 | |
| 10979 | private WindowState computeFocusedWindowLocked() { |
| 10980 | WindowState result = null; |
| 10981 | WindowState win; |
| 10982 | |
| 10983 | int i = mWindows.size() - 1; |
| 10984 | int nextAppIndex = mAppTokens.size()-1; |
| 10985 | WindowToken nextApp = nextAppIndex >= 0 |
| 10986 | ? mAppTokens.get(nextAppIndex) : null; |
| 10987 | |
| 10988 | while (i >= 0) { |
| 10989 | win = (WindowState)mWindows.get(i); |
| 10990 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10991 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10992 | TAG, "Looking for focus: " + i |
| 10993 | + " = " + win |
| 10994 | + ", flags=" + win.mAttrs.flags |
| 10995 | + ", canReceive=" + win.canReceiveKeys()); |
| 10996 | |
| 10997 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10998 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10999 | // If this window's application has been removed, just skip it. |
| 11000 | if (thisApp != null && thisApp.removed) { |
| 11001 | i--; |
| 11002 | continue; |
| 11003 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11004 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11005 | // If there is a focused app, don't allow focus to go to any |
| 11006 | // windows below it. If this is an application window, step |
| 11007 | // through the app tokens until we find its app. |
| 11008 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 11009 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 11010 | int origAppIndex = nextAppIndex; |
| 11011 | while (nextAppIndex > 0) { |
| 11012 | if (nextApp == mFocusedApp) { |
| 11013 | // Whoops, we are below the focused app... no focus |
| 11014 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11015 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11016 | TAG, "Reached focused app: " + mFocusedApp); |
| 11017 | return null; |
| 11018 | } |
| 11019 | nextAppIndex--; |
| 11020 | nextApp = mAppTokens.get(nextAppIndex); |
| 11021 | if (nextApp == thisApp) { |
| 11022 | break; |
| 11023 | } |
| 11024 | } |
| 11025 | if (thisApp != nextApp) { |
| 11026 | // Uh oh, the app token doesn't exist! This shouldn't |
| 11027 | // happen, but if it does we can get totally hosed... |
| 11028 | // so restart at the original app. |
| 11029 | nextAppIndex = origAppIndex; |
| 11030 | nextApp = mAppTokens.get(nextAppIndex); |
| 11031 | } |
| 11032 | } |
| 11033 | |
| 11034 | // Dispatch to this window if it is wants key events. |
| 11035 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11036 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11037 | TAG, "Found focus @ " + i + " = " + win); |
| 11038 | result = win; |
| 11039 | break; |
| 11040 | } |
| 11041 | |
| 11042 | i--; |
| 11043 | } |
| 11044 | |
| 11045 | return result; |
| 11046 | } |
| 11047 | |
| 11048 | private void startFreezingDisplayLocked() { |
| 11049 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 11050 | // Freezing the display also suspends key event delivery, to |
| 11051 | // keep events from going astray while the display is reconfigured. |
| 11052 | // If someone has changed orientation again while the screen is |
| 11053 | // still frozen, the events will continue to be blocked while the |
| 11054 | // successive orientation change is processed. To prevent spurious |
| 11055 | // ANRs, we reset the event dispatch timeout in this case. |
| 11056 | synchronized (mKeyWaiter) { |
| 11057 | mKeyWaiter.mWasFrozen = true; |
| 11058 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11059 | return; |
| 11060 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11061 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11062 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11063 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11064 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11065 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11066 | if (mFreezeGcPending != 0) { |
| 11067 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11068 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11069 | mH.removeMessages(H.FORCE_GC); |
| 11070 | Runtime.getRuntime().gc(); |
| 11071 | mFreezeGcPending = now; |
| 11072 | } |
| 11073 | } else { |
| 11074 | mFreezeGcPending = now; |
| 11075 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11076 | |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11077 | if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException()); |
| 11078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11079 | mDisplayFrozen = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11080 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11081 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11082 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11083 | mAppTransitionReady = true; |
| 11084 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11085 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11086 | if (PROFILE_ORIENTATION) { |
| 11087 | File file = new File("/data/system/frozen"); |
| 11088 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11089 | } |
| 11090 | Surface.freezeDisplay(0); |
| 11091 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11092 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11093 | private void stopFreezingDisplayLocked() { |
| 11094 | if (!mDisplayFrozen) { |
| 11095 | return; |
| 11096 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11097 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11098 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11099 | return; |
| 11100 | } |
| 11101 | |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 11102 | if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException()); |
| 11103 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11104 | mDisplayFrozen = false; |
| 11105 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11106 | if (PROFILE_ORIENTATION) { |
| 11107 | Debug.stopMethodTracing(); |
| 11108 | } |
| 11109 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11110 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 11111 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 11112 | // too because regular key delivery processing should resume immediately. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11113 | synchronized (mKeyWaiter) { |
| 11114 | mKeyWaiter.mWasFrozen = true; |
| 11115 | mKeyWaiter.notifyAll(); |
| 11116 | } |
| 11117 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11118 | // While the display is frozen we don't re-compute the orientation |
| 11119 | // to avoid inconsistent states. However, something interesting |
| 11120 | // could have actually changed during that time so re-evaluate it |
| 11121 | // now to catch that. |
| 11122 | if (updateOrientationFromAppTokensLocked()) { |
| 11123 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 11124 | } |
| 11125 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11126 | // A little kludge: a lot could have happened while the |
| 11127 | // display was frozen, so now that we are coming back we |
| 11128 | // do a gc so that any remote references the system |
| 11129 | // processes holds on others can be released if they are |
| 11130 | // no longer needed. |
| 11131 | mH.removeMessages(H.FORCE_GC); |
| 11132 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11133 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11134 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11135 | mScreenFrozenLock.release(); |
| 11136 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11137 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11138 | @Override |
| 11139 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11140 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11141 | != PackageManager.PERMISSION_GRANTED) { |
| 11142 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11143 | + Binder.getCallingPid() |
| 11144 | + ", uid=" + Binder.getCallingUid()); |
| 11145 | return; |
| 11146 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11147 | |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11148 | pw.println("Input State:"); |
| 11149 | mQueue.dump(pw, " "); |
| 11150 | pw.println(" "); |
| 11151 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11152 | synchronized(mWindowMap) { |
| 11153 | pw.println("Current Window Manager state:"); |
| 11154 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 11155 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11156 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11157 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11158 | w.dump(pw, " "); |
| 11159 | } |
| 11160 | if (mInputMethodDialogs.size() > 0) { |
| 11161 | pw.println(" "); |
| 11162 | pw.println(" Input method dialogs:"); |
| 11163 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11164 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11165 | 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] | 11166 | } |
| 11167 | } |
| 11168 | if (mPendingRemove.size() > 0) { |
| 11169 | pw.println(" "); |
| 11170 | pw.println(" Remove pending for:"); |
| 11171 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11172 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11173 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11174 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11175 | w.dump(pw, " "); |
| 11176 | } |
| 11177 | } |
| 11178 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11179 | pw.println(" "); |
| 11180 | pw.println(" Windows force removing:"); |
| 11181 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11182 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11183 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11184 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11185 | w.dump(pw, " "); |
| 11186 | } |
| 11187 | } |
| 11188 | if (mDestroySurface.size() > 0) { |
| 11189 | pw.println(" "); |
| 11190 | pw.println(" Windows waiting to destroy their surface:"); |
| 11191 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11192 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11193 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11194 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11195 | w.dump(pw, " "); |
| 11196 | } |
| 11197 | } |
| 11198 | if (mLosingFocus.size() > 0) { |
| 11199 | pw.println(" "); |
| 11200 | pw.println(" Windows losing focus:"); |
| 11201 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11202 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11203 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11204 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11205 | w.dump(pw, " "); |
| 11206 | } |
| 11207 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11208 | if (mResizingWindows.size() > 0) { |
| 11209 | pw.println(" "); |
| 11210 | pw.println(" Windows waiting to resize:"); |
| 11211 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11212 | WindowState w = mResizingWindows.get(i); |
| 11213 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11214 | pw.print(w); pw.println(":"); |
| 11215 | w.dump(pw, " "); |
| 11216 | } |
| 11217 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11218 | if (mSessions.size() > 0) { |
| 11219 | pw.println(" "); |
| 11220 | pw.println(" All active sessions:"); |
| 11221 | Iterator<Session> it = mSessions.iterator(); |
| 11222 | while (it.hasNext()) { |
| 11223 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11224 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11225 | s.dump(pw, " "); |
| 11226 | } |
| 11227 | } |
| 11228 | if (mTokenMap.size() > 0) { |
| 11229 | pw.println(" "); |
| 11230 | pw.println(" All tokens:"); |
| 11231 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11232 | while (it.hasNext()) { |
| 11233 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11234 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11235 | token.dump(pw, " "); |
| 11236 | } |
| 11237 | } |
| 11238 | if (mTokenList.size() > 0) { |
| 11239 | pw.println(" "); |
| 11240 | pw.println(" Window token list:"); |
| 11241 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11242 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 11243 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11244 | } |
| 11245 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11246 | if (mWallpaperTokens.size() > 0) { |
| 11247 | pw.println(" "); |
| 11248 | pw.println(" Wallpaper tokens:"); |
| 11249 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11250 | WindowToken token = mWallpaperTokens.get(i); |
| 11251 | pw.print(" Wallpaper #"); pw.print(i); |
| 11252 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11253 | token.dump(pw, " "); |
| 11254 | } |
| 11255 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11256 | if (mAppTokens.size() > 0) { |
| 11257 | pw.println(" "); |
| 11258 | pw.println(" Application tokens in Z order:"); |
| 11259 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11260 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11261 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11262 | } |
| 11263 | } |
| 11264 | if (mFinishedStarting.size() > 0) { |
| 11265 | pw.println(" "); |
| 11266 | pw.println(" Finishing start of application tokens:"); |
| 11267 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11268 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11269 | pw.print(" Finished Starting #"); pw.print(i); |
| 11270 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11271 | token.dump(pw, " "); |
| 11272 | } |
| 11273 | } |
| 11274 | if (mExitingTokens.size() > 0) { |
| 11275 | pw.println(" "); |
| 11276 | pw.println(" Exiting tokens:"); |
| 11277 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11278 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11279 | pw.print(" Exiting #"); pw.print(i); |
| 11280 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11281 | token.dump(pw, " "); |
| 11282 | } |
| 11283 | } |
| 11284 | if (mExitingAppTokens.size() > 0) { |
| 11285 | pw.println(" "); |
| 11286 | pw.println(" Exiting application tokens:"); |
| 11287 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11288 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11289 | pw.print(" Exiting App #"); pw.print(i); |
| 11290 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11291 | token.dump(pw, " "); |
| 11292 | } |
| 11293 | } |
| 11294 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11295 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11296 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11297 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11298 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11299 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11300 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11301 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11302 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11303 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11304 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11305 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11306 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11307 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11308 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11309 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11310 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11311 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11312 | if (mDimAnimator != null) { |
| 11313 | mDimAnimator.printTo(pw); |
| 11314 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11315 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11316 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11317 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11318 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11319 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11320 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11321 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11322 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11323 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11324 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11325 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11326 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11327 | pw.print(" mRotation="); pw.print(mRotation); |
| 11328 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11329 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11330 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11331 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11332 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11333 | pw.print(" mNextAppTransition=0x"); |
| 11334 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11335 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11336 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11337 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11338 | if (mNextAppTransitionPackage != null) { |
| 11339 | pw.print(" mNextAppTransitionPackage="); |
| 11340 | pw.print(mNextAppTransitionPackage); |
| 11341 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11342 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11343 | pw.print(", mNextAppTransitionExit=0x"); |
| 11344 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11345 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11346 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11347 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11348 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11349 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11350 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11351 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11352 | if (mOpeningApps.size() > 0) { |
| 11353 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11354 | } |
| 11355 | if (mClosingApps.size() > 0) { |
| 11356 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11357 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11358 | if (mToTopApps.size() > 0) { |
| 11359 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11360 | } |
| 11361 | if (mToBottomApps.size() > 0) { |
| 11362 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11363 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11364 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11365 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11366 | pw.println(" KeyWaiter state:"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11367 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 11368 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 11369 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 11370 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 11371 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 11372 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11373 | } |
| 11374 | } |
| 11375 | |
| 11376 | public void monitor() { |
| 11377 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11378 | synchronized (mKeyguardTokenWatcher) { } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11379 | synchronized (mKeyWaiter) { } |
| 11380 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11381 | |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11382 | public void virtualKeyFeedback(KeyEvent event) { |
| 11383 | mPolicy.keyFeedbackFromInput(event); |
| 11384 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11385 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11386 | /** |
| 11387 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11388 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11389 | */ |
| 11390 | private static class DimAnimator { |
| 11391 | Surface mDimSurface; |
| 11392 | boolean mDimShown = false; |
| 11393 | float mDimCurrentAlpha; |
| 11394 | float mDimTargetAlpha; |
| 11395 | float mDimDeltaPerMs; |
| 11396 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11397 | |
| 11398 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11399 | |
| 11400 | DimAnimator (SurfaceSession session) { |
| 11401 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11402 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11403 | + mDimSurface + ": CREATE"); |
| 11404 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11405 | mDimSurface = new Surface(session, 0, |
| 11406 | "DimSurface", |
| 11407 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11408 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11409 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11410 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11411 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11412 | } |
| 11413 | } |
| 11414 | } |
| 11415 | |
| 11416 | /** |
| 11417 | * Show the dim surface. |
| 11418 | */ |
| 11419 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11420 | if (!mDimShown) { |
| 11421 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11422 | dw + "x" + dh + ")"); |
| 11423 | mDimShown = true; |
| 11424 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11425 | mLastDimWidth = dw; |
| 11426 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11427 | mDimSurface.setPosition(0, 0); |
| 11428 | mDimSurface.setSize(dw, dh); |
| 11429 | mDimSurface.show(); |
| 11430 | } catch (RuntimeException e) { |
| 11431 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11432 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11433 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11434 | mLastDimWidth = dw; |
| 11435 | mLastDimHeight = dh; |
| 11436 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11437 | } |
| 11438 | } |
| 11439 | |
| 11440 | /** |
| 11441 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11442 | * {@link updateSurface} after all windows are examined. |
| 11443 | */ |
| 11444 | void updateParameters(WindowState w, long currentTime) { |
| 11445 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11446 | |
| 11447 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11448 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11449 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11450 | if (mDimTargetAlpha != target) { |
| 11451 | // If the desired dim level has changed, then |
| 11452 | // start an animation to it. |
| 11453 | mLastDimAnimTime = currentTime; |
| 11454 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11455 | ? w.mAnimation.computeDurationHint() |
| 11456 | : DEFAULT_DIM_DURATION; |
| 11457 | if (target > mDimTargetAlpha) { |
| 11458 | // This is happening behind the activity UI, |
| 11459 | // so we can make it run a little longer to |
| 11460 | // give a stronger impression without disrupting |
| 11461 | // the user. |
| 11462 | duration *= DIM_DURATION_MULTIPLIER; |
| 11463 | } |
| 11464 | if (duration < 1) { |
| 11465 | // Don't divide by zero |
| 11466 | duration = 1; |
| 11467 | } |
| 11468 | mDimTargetAlpha = target; |
| 11469 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11470 | } |
| 11471 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11472 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11473 | /** |
| 11474 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11475 | * false when the animation is finished and the dim surface is hidden. |
| 11476 | */ |
| 11477 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11478 | if (!dimming) { |
| 11479 | if (mDimTargetAlpha != 0) { |
| 11480 | mLastDimAnimTime = currentTime; |
| 11481 | mDimTargetAlpha = 0; |
| 11482 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11483 | } |
| 11484 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11485 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11486 | boolean animating = false; |
| 11487 | if (mLastDimAnimTime != 0) { |
| 11488 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11489 | * (currentTime-mLastDimAnimTime); |
| 11490 | boolean more = true; |
| 11491 | if (displayFrozen) { |
| 11492 | // If the display is frozen, there is no reason to animate. |
| 11493 | more = false; |
| 11494 | } else if (mDimDeltaPerMs > 0) { |
| 11495 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11496 | more = false; |
| 11497 | } |
| 11498 | } else if (mDimDeltaPerMs < 0) { |
| 11499 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11500 | more = false; |
| 11501 | } |
| 11502 | } else { |
| 11503 | more = false; |
| 11504 | } |
| 11505 | |
| 11506 | // Do we need to continue animating? |
| 11507 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11508 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11509 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11510 | mLastDimAnimTime = currentTime; |
| 11511 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11512 | animating = true; |
| 11513 | } else { |
| 11514 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11515 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11516 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11517 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11518 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11519 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11520 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11521 | + ": HIDE"); |
| 11522 | try { |
| 11523 | mDimSurface.hide(); |
| 11524 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11525 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11526 | } |
| 11527 | mDimShown = false; |
| 11528 | } |
| 11529 | } |
| 11530 | } |
| 11531 | return animating; |
| 11532 | } |
| 11533 | |
| 11534 | public void printTo(PrintWriter pw) { |
| 11535 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11536 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11537 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11538 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11539 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11540 | } |
| 11541 | } |
| 11542 | |
| 11543 | /** |
| 11544 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11545 | * This is used for opening/closing transition for apps in compatible mode. |
| 11546 | */ |
| 11547 | private static class FadeInOutAnimation extends Animation { |
| 11548 | int mWidth; |
| 11549 | boolean mFadeIn; |
| 11550 | |
| 11551 | public FadeInOutAnimation(boolean fadeIn) { |
| 11552 | setInterpolator(new AccelerateInterpolator()); |
| 11553 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11554 | mFadeIn = fadeIn; |
| 11555 | } |
| 11556 | |
| 11557 | @Override |
| 11558 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11559 | float x = interpolatedTime; |
| 11560 | if (!mFadeIn) { |
| 11561 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11562 | } |
| 11563 | if (x < 0.5) { |
| 11564 | // move the window out of the screen. |
| 11565 | t.getMatrix().setTranslate(mWidth, 0); |
| 11566 | } else { |
| 11567 | t.getMatrix().setTranslate(0, 0);// show |
| 11568 | t.setAlpha((x - 0.5f) * 2); |
| 11569 | } |
| 11570 | } |
| 11571 | |
| 11572 | @Override |
| 11573 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11574 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11575 | mWidth = width; |
| 11576 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11577 | |
| 11578 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11579 | public int getZAdjustment() { |
| 11580 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11581 | } |
| 11582 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11583 | } |