| 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; |
| 57 | import android.content.Context; |
| 58 | import android.content.pm.ActivityInfo; |
| 59 | import android.content.pm.PackageManager; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 60 | import android.content.res.CompatibilityInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.content.res.Configuration; |
| 62 | import android.graphics.Matrix; |
| 63 | import android.graphics.PixelFormat; |
| 64 | import android.graphics.Rect; |
| 65 | import android.graphics.Region; |
| 66 | import android.os.BatteryStats; |
| 67 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 68 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.os.Debug; |
| 70 | import android.os.Handler; |
| 71 | import android.os.IBinder; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 72 | import android.os.LatencyTimer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.os.LocalPowerManager; |
| 74 | import android.os.Looper; |
| 75 | import android.os.Message; |
| 76 | import android.os.Parcel; |
| 77 | import android.os.ParcelFileDescriptor; |
| 78 | import android.os.Power; |
| 79 | import android.os.PowerManager; |
| 80 | import android.os.Process; |
| 81 | import android.os.RemoteException; |
| 82 | import android.os.ServiceManager; |
| 83 | import android.os.SystemClock; |
| 84 | import android.os.SystemProperties; |
| 85 | import android.os.TokenWatcher; |
| 86 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 87 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.util.EventLog; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 89 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.util.SparseIntArray; |
| 91 | import android.view.Display; |
| 92 | import android.view.Gravity; |
| 93 | import android.view.IApplicationToken; |
| 94 | import android.view.IOnKeyguardExitResult; |
| 95 | import android.view.IRotationWatcher; |
| 96 | import android.view.IWindow; |
| 97 | import android.view.IWindowManager; |
| 98 | import android.view.IWindowSession; |
| 99 | import android.view.KeyEvent; |
| 100 | import android.view.MotionEvent; |
| 101 | import android.view.RawInputEvent; |
| 102 | import android.view.Surface; |
| 103 | import android.view.SurfaceSession; |
| 104 | import android.view.View; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 105 | import android.view.ViewConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.ViewTreeObserver; |
| 107 | import android.view.WindowManager; |
| 108 | import android.view.WindowManagerImpl; |
| 109 | import android.view.WindowManagerPolicy; |
| 110 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 111 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import android.view.animation.Animation; |
| 113 | import android.view.animation.AnimationUtils; |
| 114 | import android.view.animation.Transformation; |
| 115 | |
| 116 | import java.io.BufferedWriter; |
| 117 | import java.io.File; |
| 118 | import java.io.FileDescriptor; |
| 119 | import java.io.IOException; |
| 120 | import java.io.OutputStream; |
| 121 | import java.io.OutputStreamWriter; |
| 122 | import java.io.PrintWriter; |
| 123 | import java.io.StringWriter; |
| 124 | import java.net.Socket; |
| 125 | import java.util.ArrayList; |
| 126 | import java.util.HashMap; |
| 127 | import java.util.HashSet; |
| 128 | import java.util.Iterator; |
| 129 | import java.util.List; |
| 130 | |
| 131 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 132 | public class WindowManagerService extends IWindowManager.Stub |
| 133 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | static final String TAG = "WindowManager"; |
| 135 | static final boolean DEBUG = false; |
| 136 | static final boolean DEBUG_FOCUS = false; |
| 137 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 138 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 139 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | static final boolean DEBUG_LAYERS = false; |
| 141 | static final boolean DEBUG_INPUT = false; |
| 142 | static final boolean DEBUG_INPUT_METHOD = false; |
| 143 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 146 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 148 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 149 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 150 | static final boolean DEBUG_WALLPAPER = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 152 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 153 | static final boolean MEASURE_LATENCY = false; |
| 154 | static private LatencyTimer lt; |
| 155 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | static final boolean PROFILE_ORIENTATION = false; |
| 157 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 158 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 161 | static final int KEY_REPEAT_DELAY = 50; |
| 162 | |
| 163 | /** How much to multiply the policy's type layer, to reserve room |
| 164 | * for multiple windows of the same type and Z-ordering adjustment |
| 165 | * with TYPE_LAYER_OFFSET. */ |
| 166 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 169 | * or below others in the same layer. */ |
| 170 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | /** How much to increment the layer for each window, to reserve room |
| 173 | * for effect surfaces between them. |
| 174 | */ |
| 175 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 176 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** The maximum length we will accept for a loaded animation duration: |
| 178 | * this is 10 seconds. |
| 179 | */ |
| 180 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 181 | |
| 182 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 183 | * value to another, when no window animation is driving it. |
| 184 | */ |
| 185 | static final int DEFAULT_DIM_DURATION = 200; |
| 186 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 187 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 188 | * compatible windows. |
| 189 | */ |
| 190 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 193 | */ |
| 194 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 195 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 196 | static final int INJECT_FAILED = 0; |
| 197 | static final int INJECT_SUCCEEDED = 1; |
| 198 | static final int INJECT_NO_PERMISSION = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 199 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 201 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 202 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 203 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 204 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 205 | /** The minimum time between dispatching touch events. */ |
| 206 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 207 | |
| 208 | // Last touch event time |
| 209 | long mLastTouchEventTime = 0; |
| 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 | // Last touch event type |
| 212 | int mLastTouchEventType = OTHER_EVENT; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 213 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 214 | // Time to wait before calling useractivity again. This saves CPU usage |
| 215 | // when we get a flood of touch events. |
| 216 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 217 | |
| 218 | // Last time we call user activity |
| 219 | long mLastUserActivityCallTime = 0; |
| 220 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 221 | // Last time we updated battery stats |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 222 | long mLastBatteryStatsCallTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 225 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 229 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 230 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 231 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 233 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 235 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 236 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | public void acquired() { |
| 238 | mPolicy.enableKeyguard(false); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 239 | mKeyguardDisabled = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | } |
| 241 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 242 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 243 | synchronized (mKeyguardTokenWatcher) { |
| 244 | mKeyguardDisabled = false; |
| 245 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | }; |
| 249 | |
| 250 | final Context mContext; |
| 251 | |
| 252 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 255 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 257 | |
| 258 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 259 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | /** |
| 263 | * All currently active sessions with clients. |
| 264 | */ |
| 265 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | /** |
| 268 | * Mapping from an IWindow IBinder to the server's Window object. |
| 269 | * This is also used as the lock for all of our state. |
| 270 | */ |
| 271 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 272 | |
| 273 | /** |
| 274 | * Mapping from a token IBinder to a WindowToken object. |
| 275 | */ |
| 276 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 277 | new HashMap<IBinder, WindowToken>(); |
| 278 | |
| 279 | /** |
| 280 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 281 | * over them. |
| 282 | */ |
| 283 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | /** |
| 286 | * Window tokens that are in the process of exiting, but still |
| 287 | * on screen for animations. |
| 288 | */ |
| 289 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 290 | |
| 291 | /** |
| 292 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 293 | * controlling the ordering of windows in different applications. This |
| 294 | * contains WindowToken objects. |
| 295 | */ |
| 296 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 297 | |
| 298 | /** |
| 299 | * Application tokens that are in the process of exiting, but still |
| 300 | * on screen for animations. |
| 301 | */ |
| 302 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 303 | |
| 304 | /** |
| 305 | * List of window tokens that have finished starting their application, |
| 306 | * and now need to have the policy remove their windows. |
| 307 | */ |
| 308 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 309 | |
| 310 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 311 | * This was the app token that was used to retrieve the last enter |
| 312 | * animation. It will be used for the next exit animation. |
| 313 | */ |
| 314 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 315 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 316 | /** |
| 317 | * These were the layout params used to retrieve the last enter animation. |
| 318 | * They will be used for the next exit animation. |
| 319 | */ |
| 320 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 321 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 322 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | * Z-ordered (bottom-most first) list of all Window objects. |
| 324 | */ |
| 325 | final ArrayList mWindows = new ArrayList(); |
| 326 | |
| 327 | /** |
| 328 | * Windows that are being resized. Used so we can tell the client about |
| 329 | * the resize after closing the transaction in which we resized the |
| 330 | * underlying surface. |
| 331 | */ |
| 332 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 333 | |
| 334 | /** |
| 335 | * Windows whose animations have ended and now must be removed. |
| 336 | */ |
| 337 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 338 | |
| 339 | /** |
| 340 | * Windows whose surface should be destroyed. |
| 341 | */ |
| 342 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 343 | |
| 344 | /** |
| 345 | * Windows that have lost input focus and are waiting for the new |
| 346 | * focus window to be displayed before they are told about this. |
| 347 | */ |
| 348 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 349 | |
| 350 | /** |
| 351 | * This is set when we have run out of memory, and will either be an empty |
| 352 | * list or contain windows that need to be force removed. |
| 353 | */ |
| 354 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 359 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | Surface mBlurSurface; |
| 361 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | final float[] mTmpFloats = new float[9]; |
| 366 | |
| 367 | boolean mSafeMode; |
| 368 | boolean mDisplayEnabled = false; |
| 369 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 370 | int mInitialDisplayWidth = 0; |
| 371 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | int mRotation = 0; |
| 373 | int mRequestedRotation = 0; |
| 374 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 375 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | ArrayList<IRotationWatcher> mRotationWatchers |
| 377 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 378 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | boolean mLayoutNeeded = true; |
| 380 | boolean mAnimationPending = false; |
| 381 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 382 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | boolean mWindowsFreezingScreen = false; |
| 384 | long mFreezeGcPending = 0; |
| 385 | int mAppsFreezingScreen = 0; |
| 386 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 387 | int mLayoutSeq = 0; |
| 388 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 389 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 390 | boolean mFocusMayChange; |
| 391 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 392 | Configuration mCurConfiguration = new Configuration(); |
| 393 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | // This is held as long as we have the screen frozen, to give us time to |
| 395 | // perform a rotation animation when turning off shows the lock screen which |
| 396 | // changes the orientation. |
| 397 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 398 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | // State management of app transitions. When we are preparing for a |
| 400 | // transition, mNextAppTransition will be the kind of transition to |
| 401 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 402 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 403 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 404 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 405 | String mNextAppTransitionPackage; |
| 406 | int mNextAppTransitionEnter; |
| 407 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 409 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | boolean mAppTransitionTimeout = false; |
| 411 | boolean mStartingIconInTransition = false; |
| 412 | boolean mSkipAppTransitionAnimation = false; |
| 413 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 414 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 415 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 416 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | //flag to detect fat touch events |
| 419 | boolean mFatTouch = false; |
| 420 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 421 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | H mH = new H(); |
| 423 | |
| 424 | WindowState mCurrentFocus = null; |
| 425 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 426 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | // This just indicates the window the input method is on top of, not |
| 428 | // necessarily the window its input is going to. |
| 429 | WindowState mInputMethodTarget = null; |
| 430 | WindowState mUpcomingInputMethodTarget = null; |
| 431 | boolean mInputMethodTargetWaitingAnim; |
| 432 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | WindowState mInputMethodWindow = null; |
| 435 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 436 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 437 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 438 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 439 | // If non-null, this is the currently visible window that is associated |
| 440 | // with the wallpaper. |
| 441 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 442 | // If non-null, we are in the middle of animating from one wallpaper target |
| 443 | // to another, and this is the lower one in Z-order. |
| 444 | WindowState mLowerWallpaperTarget = null; |
| 445 | // If non-null, we are in the middle of animating from one wallpaper target |
| 446 | // to another, and this is the higher one in Z-order. |
| 447 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 448 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 449 | float mLastWallpaperX = -1; |
| 450 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 451 | float mLastWallpaperXStep = -1; |
| 452 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 453 | boolean mSendingPointersToWallpaper = false; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 454 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 455 | // changing its scroll position. |
| 456 | WindowState mWaitingOnWallpaper; |
| 457 | // The last time we had a timeout when waiting for a wallpaper. |
| 458 | long mLastWallpaperTimeoutTime; |
| 459 | // We give a wallpaper up to 150ms to finish scrolling. |
| 460 | static final long WALLPAPER_TIMEOUT = 150; |
| 461 | // Time we wait after a timeout before trying to wait again. |
| 462 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 463 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | AppWindowToken mFocusedApp = null; |
| 465 | |
| 466 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | float mWindowAnimationScale = 1.0f; |
| 469 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 472 | final KeyQ mQueue; |
| 473 | final InputDispatcherThread mInputThread; |
| 474 | |
| 475 | // Who is holding the screen on. |
| 476 | Session mHoldingScreenOn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 477 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 478 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | /** |
| 481 | * Whether the UI is currently running in touch mode (not showing |
| 482 | * navigational focus because the user is directly pressing the screen). |
| 483 | */ |
| 484 | boolean mInTouchMode = false; |
| 485 | |
| 486 | private ViewServer mViewServer; |
| 487 | |
| 488 | final Rect mTempRect = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 489 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 490 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 491 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 492 | |
| 493 | // The frame use to limit the size of the app running in compatibility mode. |
| 494 | Rect mCompatibleScreenFrame = new Rect(); |
| 495 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 496 | Surface mBackgroundFillerSurface = null; |
| 497 | boolean mBackgroundFillerShown = false; |
| 498 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | public static WindowManagerService main(Context context, |
| 500 | PowerManagerService pm, boolean haveInputMethods) { |
| 501 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 502 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | synchronized (thr) { |
| 505 | while (thr.mService == null) { |
| 506 | try { |
| 507 | thr.wait(); |
| 508 | } catch (InterruptedException e) { |
| 509 | } |
| 510 | } |
| 511 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 512 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | return thr.mService; |
| 514 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | static class WMThread extends Thread { |
| 517 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | private final Context mContext; |
| 520 | private final PowerManagerService mPM; |
| 521 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | public WMThread(Context context, PowerManagerService pm, |
| 524 | boolean haveInputMethods) { |
| 525 | super("WindowManager"); |
| 526 | mContext = context; |
| 527 | mPM = pm; |
| 528 | mHaveInputMethods = haveInputMethods; |
| 529 | } |
| 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 | public void run() { |
| 532 | Looper.prepare(); |
| 533 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 534 | mHaveInputMethods); |
| 535 | android.os.Process.setThreadPriority( |
| 536 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 537 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | synchronized (this) { |
| 539 | mService = s; |
| 540 | notifyAll(); |
| 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 | Looper.loop(); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | static class PolicyThread extends Thread { |
| 548 | private final WindowManagerPolicy mPolicy; |
| 549 | private final WindowManagerService mService; |
| 550 | private final Context mContext; |
| 551 | private final PowerManagerService mPM; |
| 552 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | public PolicyThread(WindowManagerPolicy policy, |
| 555 | WindowManagerService service, Context context, |
| 556 | PowerManagerService pm) { |
| 557 | super("WindowManagerPolicy"); |
| 558 | mPolicy = policy; |
| 559 | mService = service; |
| 560 | mContext = context; |
| 561 | mPM = pm; |
| 562 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 563 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | public void run() { |
| 565 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 566 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 569 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | android.os.Process.setThreadPriority( |
| 571 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 572 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | synchronized (this) { |
| 575 | mRunning = true; |
| 576 | notifyAll(); |
| 577 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | Looper.loop(); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | private WindowManagerService(Context context, PowerManagerService pm, |
| 584 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 585 | if (MEASURE_LATENCY) { |
| 586 | lt = new LatencyTimer(100, 1000); |
| 587 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | mContext = context; |
| 590 | mHaveInputMethods = haveInputMethods; |
| 591 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 592 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | mPowerManager = pm; |
| 595 | mPowerManager.setPolicy(mPolicy); |
| 596 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 597 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 598 | "SCREEN_FROZEN"); |
| 599 | mScreenFrozenLock.setReferenceCounted(false); |
| 600 | |
| 601 | mActivityManager = ActivityManagerNative.getDefault(); |
| 602 | mBatteryStats = BatteryStatsService.getService(); |
| 603 | |
| 604 | // Get persisted window scale setting |
| 605 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 606 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 607 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 608 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 609 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 610 | int max_events_per_sec = 35; |
| 611 | try { |
| 612 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 613 | .get("windowsmgr.max_events_per_sec")); |
| 614 | if (max_events_per_sec < 1) { |
| 615 | max_events_per_sec = 35; |
| 616 | } |
| 617 | } catch (NumberFormatException e) { |
| 618 | } |
| 619 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | mQueue = new KeyQ(); |
| 622 | |
| 623 | mInputThread = new InputDispatcherThread(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 626 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 627 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | synchronized (thr) { |
| 629 | while (!thr.mRunning) { |
| 630 | try { |
| 631 | thr.wait(); |
| 632 | } catch (InterruptedException e) { |
| 633 | } |
| 634 | } |
| 635 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | mInputThread.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 638 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | // Add ourself to the Watchdog monitors. |
| 640 | Watchdog.getInstance().addMonitor(this); |
| 641 | } |
| 642 | |
| 643 | @Override |
| 644 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 645 | throws RemoteException { |
| 646 | try { |
| 647 | return super.onTransact(code, data, reply, flags); |
| 648 | } catch (RuntimeException e) { |
| 649 | // The window manager only throws security exceptions, so let's |
| 650 | // log all others. |
| 651 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 652 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | } |
| 654 | throw e; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | private void placeWindowAfter(Object pos, WindowState window) { |
| 659 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 660 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | TAG, "Adding window " + window + " at " |
| 662 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 663 | mWindows.add(i+1, window); |
| 664 | } |
| 665 | |
| 666 | private void placeWindowBefore(Object pos, WindowState window) { |
| 667 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 668 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | TAG, "Adding window " + window + " at " |
| 670 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 671 | mWindows.add(i, window); |
| 672 | } |
| 673 | |
| 674 | //This method finds out the index of a window that has the same app token as |
| 675 | //win. used for z ordering the windows in mWindows |
| 676 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 677 | //use a local variable to cache mWindows |
| 678 | ArrayList localmWindows = mWindows; |
| 679 | int jmax = localmWindows.size(); |
| 680 | if(jmax == 0) { |
| 681 | return -1; |
| 682 | } |
| 683 | for(int j = (jmax-1); j >= 0; j--) { |
| 684 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 685 | if(wentry.mAppToken == win.mAppToken) { |
| 686 | return j; |
| 687 | } |
| 688 | } |
| 689 | return -1; |
| 690 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 691 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 693 | final IWindow client = win.mClient; |
| 694 | final WindowToken token = win.mToken; |
| 695 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 696 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | final int N = localmWindows.size(); |
| 698 | final WindowState attached = win.mAttachedWindow; |
| 699 | int i; |
| 700 | if (attached == null) { |
| 701 | int tokenWindowsPos = token.windows.size(); |
| 702 | if (token.appWindowToken != null) { |
| 703 | int index = tokenWindowsPos-1; |
| 704 | if (index >= 0) { |
| 705 | // If this application has existing windows, we |
| 706 | // simply place the new window on top of them... but |
| 707 | // keep the starting window on top. |
| 708 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 709 | // Base windows go behind everything else. |
| 710 | placeWindowBefore(token.windows.get(0), win); |
| 711 | tokenWindowsPos = 0; |
| 712 | } else { |
| 713 | AppWindowToken atoken = win.mAppToken; |
| 714 | if (atoken != null && |
| 715 | token.windows.get(index) == atoken.startingWindow) { |
| 716 | placeWindowBefore(token.windows.get(index), win); |
| 717 | tokenWindowsPos--; |
| 718 | } else { |
| 719 | int newIdx = findIdxBasedOnAppTokens(win); |
| 720 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 721 | //there is a window above this one associated with the same |
| 722 | //apptoken note that the window could be a floating window |
| 723 | //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] | 724 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 725 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 726 | TAG, "Adding window " + win + " at " |
| 727 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | localmWindows.add(newIdx+1, win); |
| 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 | } |
| 731 | } |
| 732 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 733 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | TAG, "Figuring out where to add app window " |
| 735 | + client.asBinder() + " (token=" + token + ")"); |
| 736 | // Figure out where the window should go, based on the |
| 737 | // order of applications. |
| 738 | final int NA = mAppTokens.size(); |
| 739 | Object pos = null; |
| 740 | for (i=NA-1; i>=0; i--) { |
| 741 | AppWindowToken t = mAppTokens.get(i); |
| 742 | if (t == token) { |
| 743 | i--; |
| 744 | break; |
| 745 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 746 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 747 | // We haven't reached the token yet; if this token |
| 748 | // is not going to the bottom and has windows, we can |
| 749 | // use it as an anchor for when we do reach the token. |
| 750 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | pos = t.windows.get(0); |
| 752 | } |
| 753 | } |
| 754 | // We now know the index into the apps. If we found |
| 755 | // an app window above, that gives us the position; else |
| 756 | // we need to look some more. |
| 757 | if (pos != null) { |
| 758 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 759 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 761 | if (atoken != null) { |
| 762 | final int NC = atoken.windows.size(); |
| 763 | if (NC > 0) { |
| 764 | WindowState bottom = atoken.windows.get(0); |
| 765 | if (bottom.mSubLayer < 0) { |
| 766 | pos = bottom; |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | placeWindowBefore(pos, win); |
| 771 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 772 | // Continue looking down until we find the first |
| 773 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | while (i >= 0) { |
| 775 | AppWindowToken t = mAppTokens.get(i); |
| 776 | final int NW = t.windows.size(); |
| 777 | if (NW > 0) { |
| 778 | pos = t.windows.get(NW-1); |
| 779 | break; |
| 780 | } |
| 781 | i--; |
| 782 | } |
| 783 | if (pos != null) { |
| 784 | // Move in front of any windows attached to this |
| 785 | // one. |
| 786 | WindowToken atoken = |
| 787 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 788 | if (atoken != null) { |
| 789 | final int NC = atoken.windows.size(); |
| 790 | if (NC > 0) { |
| 791 | WindowState top = atoken.windows.get(NC-1); |
| 792 | if (top.mSubLayer >= 0) { |
| 793 | pos = top; |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | placeWindowAfter(pos, win); |
| 798 | } else { |
| 799 | // Just search for the start of this layer. |
| 800 | final int myLayer = win.mBaseLayer; |
| 801 | for (i=0; i<N; i++) { |
| 802 | WindowState w = (WindowState)localmWindows.get(i); |
| 803 | if (w.mBaseLayer > myLayer) { |
| 804 | break; |
| 805 | } |
| 806 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 807 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 808 | TAG, "Adding window " + win + " at " |
| 809 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | localmWindows.add(i, win); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | } else { |
| 815 | // Figure out where window should go, based on layer. |
| 816 | final int myLayer = win.mBaseLayer; |
| 817 | for (i=N-1; i>=0; i--) { |
| 818 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 819 | i++; |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 824 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 825 | TAG, "Adding window " + win + " at " |
| 826 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | localmWindows.add(i, win); |
| 828 | } |
| 829 | if (addToToken) { |
| 830 | token.windows.add(tokenWindowsPos, win); |
| 831 | } |
| 832 | |
| 833 | } else { |
| 834 | // Figure out this window's ordering relative to the window |
| 835 | // it is attached to. |
| 836 | final int NA = token.windows.size(); |
| 837 | final int sublayer = win.mSubLayer; |
| 838 | int largestSublayer = Integer.MIN_VALUE; |
| 839 | WindowState windowWithLargestSublayer = null; |
| 840 | for (i=0; i<NA; i++) { |
| 841 | WindowState w = token.windows.get(i); |
| 842 | final int wSublayer = w.mSubLayer; |
| 843 | if (wSublayer >= largestSublayer) { |
| 844 | largestSublayer = wSublayer; |
| 845 | windowWithLargestSublayer = w; |
| 846 | } |
| 847 | if (sublayer < 0) { |
| 848 | // For negative sublayers, we go below all windows |
| 849 | // in the same sublayer. |
| 850 | if (wSublayer >= sublayer) { |
| 851 | if (addToToken) { |
| 852 | token.windows.add(i, win); |
| 853 | } |
| 854 | placeWindowBefore( |
| 855 | wSublayer >= 0 ? attached : w, win); |
| 856 | break; |
| 857 | } |
| 858 | } else { |
| 859 | // For positive sublayers, we go above all windows |
| 860 | // in the same sublayer. |
| 861 | if (wSublayer > sublayer) { |
| 862 | if (addToToken) { |
| 863 | token.windows.add(i, win); |
| 864 | } |
| 865 | placeWindowBefore(w, win); |
| 866 | break; |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | if (i >= NA) { |
| 871 | if (addToToken) { |
| 872 | token.windows.add(win); |
| 873 | } |
| 874 | if (sublayer < 0) { |
| 875 | placeWindowBefore(attached, win); |
| 876 | } else { |
| 877 | placeWindowAfter(largestSublayer >= 0 |
| 878 | ? windowWithLargestSublayer |
| 879 | : attached, |
| 880 | win); |
| 881 | } |
| 882 | } |
| 883 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | if (win.mAppToken != null && addToToken) { |
| 886 | win.mAppToken.allAppWindows.add(win); |
| 887 | } |
| 888 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 889 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | static boolean canBeImeTarget(WindowState w) { |
| 891 | final int fl = w.mAttrs.flags |
| 892 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 893 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 894 | return w.isVisibleOrAdding(); |
| 895 | } |
| 896 | return false; |
| 897 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 898 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 900 | final ArrayList localmWindows = mWindows; |
| 901 | final int N = localmWindows.size(); |
| 902 | WindowState w = null; |
| 903 | int i = N; |
| 904 | while (i > 0) { |
| 905 | i--; |
| 906 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 907 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 908 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | // + Integer.toHexString(w.mAttrs.flags)); |
| 910 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 911 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | // Yet more tricksyness! If this window is a "starting" |
| 914 | // window, we do actually want to be on top of it, but |
| 915 | // it is not -really- where input will go. So if the caller |
| 916 | // is not actually looking to move the IME, look down below |
| 917 | // for a real window to target... |
| 918 | if (!willMove |
| 919 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 920 | && i > 0) { |
| 921 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 922 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 923 | i--; |
| 924 | w = wb; |
| 925 | } |
| 926 | } |
| 927 | break; |
| 928 | } |
| 929 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 930 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 932 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 933 | 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] | 934 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 935 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | if (willMove && w != null) { |
| 937 | final WindowState curTarget = mInputMethodTarget; |
| 938 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 939 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | // Now some fun for dealing with window animations that |
| 941 | // modify the Z order. We need to look at all windows below |
| 942 | // the current target that are in this app, finding the highest |
| 943 | // visible one in layering. |
| 944 | AppWindowToken token = curTarget.mAppToken; |
| 945 | WindowState highestTarget = null; |
| 946 | int highestPos = 0; |
| 947 | if (token.animating || token.animation != null) { |
| 948 | int pos = 0; |
| 949 | pos = localmWindows.indexOf(curTarget); |
| 950 | while (pos >= 0) { |
| 951 | WindowState win = (WindowState)localmWindows.get(pos); |
| 952 | if (win.mAppToken != token) { |
| 953 | break; |
| 954 | } |
| 955 | if (!win.mRemoved) { |
| 956 | if (highestTarget == null || win.mAnimLayer > |
| 957 | highestTarget.mAnimLayer) { |
| 958 | highestTarget = win; |
| 959 | highestPos = pos; |
| 960 | } |
| 961 | } |
| 962 | pos--; |
| 963 | } |
| 964 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 965 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 967 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | + mNextAppTransition + " " + highestTarget |
| 969 | + " animating=" + highestTarget.isAnimating() |
| 970 | + " layer=" + highestTarget.mAnimLayer |
| 971 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 972 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 973 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | // If we are currently setting up for an animation, |
| 975 | // hold everything until we can find out what will happen. |
| 976 | mInputMethodTargetWaitingAnim = true; |
| 977 | mInputMethodTarget = highestTarget; |
| 978 | return highestPos + 1; |
| 979 | } else if (highestTarget.isAnimating() && |
| 980 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 981 | // If the window we are currently targeting is involved |
| 982 | // with an animation, and it is on top of the next target |
| 983 | // we will be over, then hold off on moving until |
| 984 | // that is done. |
| 985 | mInputMethodTarget = highestTarget; |
| 986 | return highestPos + 1; |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 991 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 992 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | if (w != null) { |
| 994 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 995 | if (DEBUG_INPUT_METHOD) { |
| 996 | RuntimeException e = null; |
| 997 | if (!HIDE_STACK_CRAWLS) { |
| 998 | e = new RuntimeException(); |
| 999 | e.fillInStackTrace(); |
| 1000 | } |
| 1001 | Slog.w(TAG, "Moving IM target from " |
| 1002 | + mInputMethodTarget + " to " + w, e); |
| 1003 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | mInputMethodTarget = w; |
| 1005 | if (w.mAppToken != null) { |
| 1006 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1007 | } else { |
| 1008 | setInputMethodAnimLayerAdjustment(0); |
| 1009 | } |
| 1010 | } |
| 1011 | return i+1; |
| 1012 | } |
| 1013 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1014 | if (DEBUG_INPUT_METHOD) { |
| 1015 | RuntimeException e = null; |
| 1016 | if (!HIDE_STACK_CRAWLS) { |
| 1017 | e = new RuntimeException(); |
| 1018 | e.fillInStackTrace(); |
| 1019 | } |
| 1020 | Slog.w(TAG, "Moving IM target from " |
| 1021 | + mInputMethodTarget + " to null", e); |
| 1022 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | mInputMethodTarget = null; |
| 1024 | setInputMethodAnimLayerAdjustment(0); |
| 1025 | } |
| 1026 | return -1; |
| 1027 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1030 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1031 | if (pos >= 0) { |
| 1032 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1033 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1034 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | mWindows.add(pos, win); |
| 1036 | moveInputMethodDialogsLocked(pos+1); |
| 1037 | return; |
| 1038 | } |
| 1039 | win.mTargetAppToken = null; |
| 1040 | addWindowToListInOrderLocked(win, true); |
| 1041 | moveInputMethodDialogsLocked(pos); |
| 1042 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1043 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1045 | 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] | 1046 | mInputMethodAnimLayerAdjustment = adj; |
| 1047 | WindowState imw = mInputMethodWindow; |
| 1048 | if (imw != null) { |
| 1049 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1050 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1051 | + " anim layer: " + imw.mAnimLayer); |
| 1052 | int wi = imw.mChildWindows.size(); |
| 1053 | while (wi > 0) { |
| 1054 | wi--; |
| 1055 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1056 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1057 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | + " anim layer: " + cw.mAnimLayer); |
| 1059 | } |
| 1060 | } |
| 1061 | int di = mInputMethodDialogs.size(); |
| 1062 | while (di > 0) { |
| 1063 | di --; |
| 1064 | imw = mInputMethodDialogs.get(di); |
| 1065 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1066 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | + " anim layer: " + imw.mAnimLayer); |
| 1068 | } |
| 1069 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1070 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1072 | int wpos = mWindows.indexOf(win); |
| 1073 | if (wpos >= 0) { |
| 1074 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1075 | 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] | 1076 | mWindows.remove(wpos); |
| 1077 | int NC = win.mChildWindows.size(); |
| 1078 | while (NC > 0) { |
| 1079 | NC--; |
| 1080 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1081 | int cpos = mWindows.indexOf(cw); |
| 1082 | if (cpos >= 0) { |
| 1083 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1084 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1085 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | mWindows.remove(cpos); |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | return interestingPos; |
| 1091 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1092 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1094 | addWindowToListInOrderLocked(win, false); |
| 1095 | // This is a hack to get all of the child windows added as well |
| 1096 | // at the right position. Child windows should be rare and |
| 1097 | // this case should be rare, so it shouldn't be that big a deal. |
| 1098 | int wpos = mWindows.indexOf(win); |
| 1099 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1100 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1101 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | mWindows.remove(wpos); |
| 1103 | reAddWindowLocked(wpos, win); |
| 1104 | } |
| 1105 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | void logWindowList(String prefix) { |
| 1108 | int N = mWindows.size(); |
| 1109 | while (N > 0) { |
| 1110 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1111 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | } |
| 1113 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1114 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | void moveInputMethodDialogsLocked(int pos) { |
| 1116 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1117 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1119 | 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] | 1120 | for (int i=0; i<N; i++) { |
| 1121 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1122 | } |
| 1123 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1124 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | logWindowList(" "); |
| 1126 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1127 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | if (pos >= 0) { |
| 1129 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1130 | if (pos < mWindows.size()) { |
| 1131 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1132 | if (wp == mInputMethodWindow) { |
| 1133 | pos++; |
| 1134 | } |
| 1135 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1136 | 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] | 1137 | for (int i=0; i<N; i++) { |
| 1138 | WindowState win = dialogs.get(i); |
| 1139 | win.mTargetAppToken = targetAppToken; |
| 1140 | pos = reAddWindowLocked(pos, win); |
| 1141 | } |
| 1142 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1143 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | logWindowList(" "); |
| 1145 | } |
| 1146 | return; |
| 1147 | } |
| 1148 | for (int i=0; i<N; i++) { |
| 1149 | WindowState win = dialogs.get(i); |
| 1150 | win.mTargetAppToken = null; |
| 1151 | reAddWindowToListInOrderLocked(win); |
| 1152 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1153 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | logWindowList(" "); |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1158 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1160 | final WindowState imWin = mInputMethodWindow; |
| 1161 | final int DN = mInputMethodDialogs.size(); |
| 1162 | if (imWin == null && DN == 0) { |
| 1163 | return false; |
| 1164 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1165 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1167 | if (imPos >= 0) { |
| 1168 | // In this case, the input method windows are to be placed |
| 1169 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | // First check to see if the input method windows are already |
| 1172 | // located here, and contiguous. |
| 1173 | final int N = mWindows.size(); |
| 1174 | WindowState firstImWin = imPos < N |
| 1175 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1176 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | // Figure out the actual input method window that should be |
| 1178 | // at the bottom of their stack. |
| 1179 | WindowState baseImWin = imWin != null |
| 1180 | ? imWin : mInputMethodDialogs.get(0); |
| 1181 | if (baseImWin.mChildWindows.size() > 0) { |
| 1182 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1183 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1184 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | if (firstImWin == baseImWin) { |
| 1187 | // The windows haven't moved... but are they still contiguous? |
| 1188 | // First find the top IM window. |
| 1189 | int pos = imPos+1; |
| 1190 | while (pos < N) { |
| 1191 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1192 | break; |
| 1193 | } |
| 1194 | pos++; |
| 1195 | } |
| 1196 | pos++; |
| 1197 | // Now there should be no more input method windows above. |
| 1198 | while (pos < N) { |
| 1199 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1200 | break; |
| 1201 | } |
| 1202 | pos++; |
| 1203 | } |
| 1204 | if (pos >= N) { |
| 1205 | // All is good! |
| 1206 | return false; |
| 1207 | } |
| 1208 | } |
| 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 | if (imWin != null) { |
| 1211 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1212 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | logWindowList(" "); |
| 1214 | } |
| 1215 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1216 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1217 | 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] | 1218 | logWindowList(" "); |
| 1219 | } |
| 1220 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1221 | reAddWindowLocked(imPos, imWin); |
| 1222 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1223 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1224 | logWindowList(" "); |
| 1225 | } |
| 1226 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1227 | } else { |
| 1228 | moveInputMethodDialogsLocked(imPos); |
| 1229 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1230 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | } else { |
| 1232 | // In this case, the input method windows go in a fixed layer, |
| 1233 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1234 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1236 | 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] | 1237 | tmpRemoveWindowLocked(0, imWin); |
| 1238 | imWin.mTargetAppToken = null; |
| 1239 | reAddWindowToListInOrderLocked(imWin); |
| 1240 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1241 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | logWindowList(" "); |
| 1243 | } |
| 1244 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1245 | } else { |
| 1246 | moveInputMethodDialogsLocked(-1);; |
| 1247 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | if (needAssignLayers) { |
| 1252 | assignLayersLocked(); |
| 1253 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1254 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | return true; |
| 1256 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | void adjustInputMethodDialogsLocked() { |
| 1259 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1260 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1261 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1262 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1263 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1264 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1265 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1266 | ? wallpaperTarget.mAppToken.animation : null) |
| 1267 | + " upper=" + mUpperWallpaperTarget |
| 1268 | + " lower=" + mLowerWallpaperTarget); |
| 1269 | return (wallpaperTarget != null |
| 1270 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1271 | && wallpaperTarget.mAppToken.animation != null))) |
| 1272 | || mUpperWallpaperTarget != null |
| 1273 | || mLowerWallpaperTarget != null; |
| 1274 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1275 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1276 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1277 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1278 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1279 | int adjustWallpaperWindowsLocked() { |
| 1280 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1281 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1282 | final int dw = mDisplay.getWidth(); |
| 1283 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1284 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1285 | // First find top-most window that has asked to be on top of the |
| 1286 | // wallpaper; all wallpapers go behind it. |
| 1287 | final ArrayList localmWindows = mWindows; |
| 1288 | int N = localmWindows.size(); |
| 1289 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1290 | WindowState foundW = null; |
| 1291 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1292 | WindowState topCurW = null; |
| 1293 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1294 | int i = N; |
| 1295 | while (i > 0) { |
| 1296 | i--; |
| 1297 | w = (WindowState)localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1298 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1299 | if (topCurW == null) { |
| 1300 | topCurW = w; |
| 1301 | topCurI = i; |
| 1302 | } |
| 1303 | continue; |
| 1304 | } |
| 1305 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1306 | if (w.mAppToken != null) { |
| 1307 | // If this window's app token is hidden and not animating, |
| 1308 | // it is of no interest to us. |
| 1309 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1310 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1311 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1312 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1313 | continue; |
| 1314 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1315 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1316 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1317 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1318 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1319 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1320 | && (mWallpaperTarget == w |
| 1321 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1322 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1323 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1324 | foundW = w; |
| 1325 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1326 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1327 | && w.mAppToken.animation != null) |
| 1328 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1329 | // The current wallpaper target is animating, so we'll |
| 1330 | // look behind it for another possible target and figure |
| 1331 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1332 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1333 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1334 | continue; |
| 1335 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1336 | break; |
| 1337 | } |
| 1338 | } |
| 1339 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1340 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1341 | // If we are currently waiting for an app transition, and either |
| 1342 | // the current target or the next target are involved with it, |
| 1343 | // then hold off on doing anything with the wallpaper. |
| 1344 | // Note that we are checking here for just whether the target |
| 1345 | // is part of an app token... which is potentially overly aggressive |
| 1346 | // (the app token may not be involved in the transition), but good |
| 1347 | // enough (we'll just wait until whatever transition is pending |
| 1348 | // executes). |
| 1349 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1350 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1351 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1352 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1353 | } |
| 1354 | if (foundW != null && foundW.mAppToken != null) { |
| 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 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1357 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1358 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1359 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1360 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1361 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1362 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1363 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1364 | + " oldTarget: " + mWallpaperTarget); |
| 1365 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1366 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1367 | mLowerWallpaperTarget = null; |
| 1368 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1369 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1370 | WindowState oldW = mWallpaperTarget; |
| 1371 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1372 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1373 | // Now what is happening... if the current and new targets are |
| 1374 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1375 | if (foundW != null && oldW != null) { |
| 1376 | boolean oldAnim = oldW.mAnimation != null |
| 1377 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1378 | boolean foundAnim = foundW.mAnimation != null |
| 1379 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1380 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1381 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1382 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1383 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1384 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1385 | int oldI = localmWindows.indexOf(oldW); |
| 1386 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1387 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1388 | } |
| 1389 | if (oldI >= 0) { |
| 1390 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1391 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1392 | + "=" + oldW + "; new#" + foundI |
| 1393 | + "=" + foundW); |
| 1394 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1395 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1396 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1397 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1398 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1399 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1400 | } |
| 1401 | mWallpaperTarget = oldW; |
| 1402 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1403 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1404 | // Now set the upper and lower wallpaper targets |
| 1405 | // correctly, and make sure that we are positioning |
| 1406 | // the wallpaper below the lower. |
| 1407 | if (foundI > oldI) { |
| 1408 | // The new target is on top of the old one. |
| 1409 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1410 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1411 | } |
| 1412 | mUpperWallpaperTarget = foundW; |
| 1413 | mLowerWallpaperTarget = oldW; |
| 1414 | foundW = oldW; |
| 1415 | foundI = oldI; |
| 1416 | } else { |
| 1417 | // The new target is below the old one. |
| 1418 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1419 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1420 | } |
| 1421 | mUpperWallpaperTarget = oldW; |
| 1422 | mLowerWallpaperTarget = foundW; |
| 1423 | } |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1427 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1428 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1429 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1430 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1431 | || (mLowerWallpaperTarget.mAppToken != null |
| 1432 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1433 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1434 | || (mUpperWallpaperTarget.mAppToken != null |
| 1435 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1436 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1437 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1438 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1439 | } |
| 1440 | mLowerWallpaperTarget = null; |
| 1441 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1442 | } |
| 1443 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1444 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1445 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1446 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1447 | // The window is visible to the compositor... but is it visible |
| 1448 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1449 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1450 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1451 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1452 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1453 | // its layer adjustment. Only do this if we are not transfering |
| 1454 | // between two wallpaper targets. |
| 1455 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1456 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1457 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1458 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1459 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1460 | * TYPE_LAYER_MULTIPLIER |
| 1461 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1462 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1463 | // Now w is the window we are supposed to be behind... but we |
| 1464 | // 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] | 1465 | // AND any starting window associated with it, AND below the |
| 1466 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1467 | while (foundI > 0) { |
| 1468 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1469 | if (wb.mBaseLayer < maxLayer && |
| 1470 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1471 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1472 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1473 | // This window is not related to the previous one in any |
| 1474 | // interesting way, so stop here. |
| 1475 | break; |
| 1476 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1477 | foundW = wb; |
| 1478 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1479 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1480 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1481 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1482 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1483 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1484 | if (foundW == null && topCurW != null) { |
| 1485 | // There is no wallpaper target, so it goes at the bottom. |
| 1486 | // We will assume it is the same place as last time, if known. |
| 1487 | foundW = topCurW; |
| 1488 | foundI = topCurI+1; |
| 1489 | } else { |
| 1490 | // Okay i is the position immediately above the wallpaper. Look at |
| 1491 | // what is below it for later. |
| 1492 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1493 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1494 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1495 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1496 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1497 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1498 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1499 | } |
| 1500 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1501 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1502 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1503 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1504 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1505 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1506 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1507 | // are correctly placed. |
| 1508 | int curTokenIndex = mWallpaperTokens.size(); |
| 1509 | while (curTokenIndex > 0) { |
| 1510 | curTokenIndex--; |
| 1511 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1512 | if (token.hidden == visible) { |
| 1513 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1514 | token.hidden = !visible; |
| 1515 | // Need to do a layout to ensure the wallpaper now has the |
| 1516 | // correct size. |
| 1517 | mLayoutNeeded = true; |
| 1518 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1519 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1520 | int curWallpaperIndex = token.windows.size(); |
| 1521 | while (curWallpaperIndex > 0) { |
| 1522 | curWallpaperIndex--; |
| 1523 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1524 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1525 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1526 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1527 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1528 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1529 | // First, make sure the client has the current visibility |
| 1530 | // state. |
| 1531 | if (wallpaper.mWallpaperVisible != visible) { |
| 1532 | wallpaper.mWallpaperVisible = visible; |
| 1533 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1534 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1535 | "Setting visibility of wallpaper " + wallpaper |
| 1536 | + ": " + visible); |
| 1537 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1538 | } catch (RemoteException e) { |
| 1539 | } |
| 1540 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1541 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1542 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1543 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1544 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1545 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1546 | // First, if this window is at the current index, then all |
| 1547 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1548 | if (wallpaper == foundW) { |
| 1549 | foundI--; |
| 1550 | foundW = foundI > 0 |
| 1551 | ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1552 | continue; |
| 1553 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1554 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1555 | // The window didn't match... the current wallpaper window, |
| 1556 | // wherever it is, is in the wrong place, so make sure it is |
| 1557 | // not in the list. |
| 1558 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1559 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1560 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1561 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1562 | localmWindows.remove(oldIndex); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1563 | if (oldIndex < foundI) { |
| 1564 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1565 | } |
| 1566 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1567 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1568 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1569 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1570 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1571 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1572 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1573 | localmWindows.add(foundI, wallpaper); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1574 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1575 | } |
| 1576 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1577 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1578 | return changed; |
| 1579 | } |
| 1580 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1581 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1582 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1583 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1584 | mWallpaperAnimLayerAdjustment = adj; |
| 1585 | int curTokenIndex = mWallpaperTokens.size(); |
| 1586 | while (curTokenIndex > 0) { |
| 1587 | curTokenIndex--; |
| 1588 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1589 | int curWallpaperIndex = token.windows.size(); |
| 1590 | while (curWallpaperIndex > 0) { |
| 1591 | curWallpaperIndex--; |
| 1592 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1593 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1594 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1595 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1600 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1601 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1602 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1603 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1604 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1605 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1606 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1607 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1608 | changed = wallpaperWin.mXOffset != offset; |
| 1609 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1610 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1611 | + wallpaperWin + " x: " + offset); |
| 1612 | wallpaperWin.mXOffset = offset; |
| 1613 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1614 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1615 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1616 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1617 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1618 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1619 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1620 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1621 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1622 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1623 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1624 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1625 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1626 | + wallpaperWin + " y: " + offset); |
| 1627 | changed = true; |
| 1628 | wallpaperWin.mYOffset = offset; |
| 1629 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1630 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1631 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1632 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1633 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1634 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1635 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1636 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1637 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1638 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1639 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1640 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1641 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1642 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1643 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1644 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1645 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1646 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1647 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1648 | if (mWaitingOnWallpaper != null) { |
| 1649 | long start = SystemClock.uptimeMillis(); |
| 1650 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1651 | < start) { |
| 1652 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1653 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1654 | "Waiting for offset complete..."); |
| 1655 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1656 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1657 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1658 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1659 | if ((start+WALLPAPER_TIMEOUT) |
| 1660 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1661 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1662 | + wallpaperWin); |
| 1663 | mLastWallpaperTimeoutTime = start; |
| 1664 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1665 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1666 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1667 | } |
| 1668 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1669 | } catch (RemoteException e) { |
| 1670 | } |
| 1671 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1672 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1673 | return changed; |
| 1674 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1675 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1676 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1677 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1678 | if (mWaitingOnWallpaper != null && |
| 1679 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1680 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1681 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1685 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1686 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1687 | final int dw = mDisplay.getWidth(); |
| 1688 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1689 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1690 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1691 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1692 | WindowState target = mWallpaperTarget; |
| 1693 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1694 | if (target.mWallpaperX >= 0) { |
| 1695 | mLastWallpaperX = target.mWallpaperX; |
| 1696 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1697 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1698 | } |
| 1699 | if (target.mWallpaperY >= 0) { |
| 1700 | mLastWallpaperY = target.mWallpaperY; |
| 1701 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1702 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1703 | } |
| 1704 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1705 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1706 | int curTokenIndex = mWallpaperTokens.size(); |
| 1707 | while (curTokenIndex > 0) { |
| 1708 | curTokenIndex--; |
| 1709 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1710 | int curWallpaperIndex = token.windows.size(); |
| 1711 | while (curWallpaperIndex > 0) { |
| 1712 | curWallpaperIndex--; |
| 1713 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1714 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1715 | wallpaper.computeShownFrameLocked(); |
| 1716 | changed = true; |
| 1717 | // We only want to be synchronous with one wallpaper. |
| 1718 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1722 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1723 | return changed; |
| 1724 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1725 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1726 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1727 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1728 | final int dw = mDisplay.getWidth(); |
| 1729 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1730 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1731 | int curTokenIndex = mWallpaperTokens.size(); |
| 1732 | while (curTokenIndex > 0) { |
| 1733 | curTokenIndex--; |
| 1734 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1735 | if (token.hidden == visible) { |
| 1736 | token.hidden = !visible; |
| 1737 | // Need to do a layout to ensure the wallpaper now has the |
| 1738 | // correct size. |
| 1739 | mLayoutNeeded = true; |
| 1740 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1741 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1742 | int curWallpaperIndex = token.windows.size(); |
| 1743 | while (curWallpaperIndex > 0) { |
| 1744 | curWallpaperIndex--; |
| 1745 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1746 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1747 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1748 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1749 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1750 | if (wallpaper.mWallpaperVisible != visible) { |
| 1751 | wallpaper.mWallpaperVisible = visible; |
| 1752 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1753 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1754 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1755 | + ": " + visible); |
| 1756 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1757 | } catch (RemoteException e) { |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1763 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1764 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1765 | MotionEvent pointer, long eventTime) { |
| 1766 | int curTokenIndex = mWallpaperTokens.size(); |
| 1767 | while (curTokenIndex > 0) { |
| 1768 | curTokenIndex--; |
| 1769 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1770 | int curWallpaperIndex = token.windows.size(); |
| 1771 | while (curWallpaperIndex > 0) { |
| 1772 | curWallpaperIndex--; |
| 1773 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1774 | if ((wallpaper.mAttrs.flags & |
| 1775 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1776 | continue; |
| 1777 | } |
| 1778 | try { |
| 1779 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1780 | if (srcWin != null) { |
| 1781 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1782 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1783 | } else { |
| 1784 | ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top); |
| 1785 | } |
| 1786 | switch (pointer.getAction()) { |
| 1787 | case MotionEvent.ACTION_DOWN: |
| 1788 | mSendingPointersToWallpaper = true; |
| 1789 | break; |
| 1790 | case MotionEvent.ACTION_UP: |
| 1791 | mSendingPointersToWallpaper = false; |
| 1792 | break; |
| 1793 | } |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1794 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1795 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1796 | Slog.w(TAG, "Failure sending pointer to wallpaper", e); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1801 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1802 | void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin, |
| 1803 | MotionEvent pointer, long eventTime, boolean skipped) { |
| 1804 | if (relWin != null) { |
| 1805 | mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top); |
| 1806 | } else { |
| 1807 | mPolicy.dispatchedPointerEventLw(pointer, 0, 0); |
| 1808 | } |
| 1809 | |
| 1810 | // If we sent an initial down to the wallpaper, then continue |
| 1811 | // sending events until the final up. |
| 1812 | if (mSendingPointersToWallpaper) { |
| 1813 | if (skipped) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1814 | Slog.i(TAG, "Sending skipped pointer to wallpaper!"); |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1815 | } |
| 1816 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1817 | |
| 1818 | // If we are on top of the wallpaper, then the wallpaper also |
| 1819 | // gets to see this movement. |
| 1820 | } else if (srcWin != null |
| 1821 | && pointer.getAction() == MotionEvent.ACTION_DOWN |
| 1822 | && mWallpaperTarget == srcWin |
| 1823 | && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 1824 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1825 | } |
| 1826 | } |
| 1827 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1828 | public int addWindow(Session session, IWindow client, |
| 1829 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1830 | Rect outContentInsets) { |
| 1831 | int res = mPolicy.checkAddPermission(attrs); |
| 1832 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1833 | return res; |
| 1834 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1835 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | boolean reportNewConfig = false; |
| 1837 | WindowState attachedWindow = null; |
| 1838 | WindowState win = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | synchronized(mWindowMap) { |
| 1841 | // Instantiating a Display requires talking with the simulator, |
| 1842 | // so don't do it until we know the system is mostly up and |
| 1843 | // running. |
| 1844 | if (mDisplay == null) { |
| 1845 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1846 | mDisplay = wm.getDefaultDisplay(); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 1847 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 1848 | mInitialDisplayHeight = mDisplay.getHeight(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1849 | mQueue.setDisplay(mDisplay); |
| 1850 | reportNewConfig = true; |
| 1851 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1852 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1853 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1854 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1855 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1856 | } |
| 1857 | |
| 1858 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1859 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1860 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1861 | 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] | 1862 | + attrs.token + ". Aborting."); |
| 1863 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1864 | } |
| 1865 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1866 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1867 | 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] | 1868 | + attrs.token + ". Aborting."); |
| 1869 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | boolean addToken = false; |
| 1874 | WindowToken token = mTokenMap.get(attrs.token); |
| 1875 | if (token == null) { |
| 1876 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1877 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1878 | 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] | 1879 | + attrs.token + ". Aborting."); |
| 1880 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1881 | } |
| 1882 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1883 | 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] | 1884 | + attrs.token + ". Aborting."); |
| 1885 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1886 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1887 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1888 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1889 | + attrs.token + ". Aborting."); |
| 1890 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1891 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | token = new WindowToken(attrs.token, -1, false); |
| 1893 | addToken = true; |
| 1894 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1895 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1896 | AppWindowToken atoken = token.appWindowToken; |
| 1897 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1898 | 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] | 1899 | + token + ". Aborting."); |
| 1900 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1901 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1902 | 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] | 1903 | + token + ". Aborting."); |
| 1904 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1905 | } |
| 1906 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1907 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1908 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1910 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1911 | } |
| 1912 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1913 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1914 | 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] | 1915 | + attrs.token + ". Aborting."); |
| 1916 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1917 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1918 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1919 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1920 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1921 | + attrs.token + ". Aborting."); |
| 1922 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1923 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | win = new WindowState(session, client, token, |
| 1927 | attachedWindow, attrs, viewVisibility); |
| 1928 | if (win.mDeathRecipient == null) { |
| 1929 | // Client has apparently died, so there is no reason to |
| 1930 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1931 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | + " that is dead, aborting."); |
| 1933 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1934 | } |
| 1935 | |
| 1936 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1937 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1939 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1940 | return res; |
| 1941 | } |
| 1942 | |
| 1943 | // From now on, no exceptions or errors allowed! |
| 1944 | |
| 1945 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1947 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1948 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | if (addToken) { |
| 1950 | mTokenMap.put(attrs.token, token); |
| 1951 | mTokenList.add(token); |
| 1952 | } |
| 1953 | win.attach(); |
| 1954 | mWindowMap.put(client.asBinder(), win); |
| 1955 | |
| 1956 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1957 | token.appWindowToken != null) { |
| 1958 | token.appWindowToken.startingWindow = win; |
| 1959 | } |
| 1960 | |
| 1961 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1962 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1964 | mInputMethodWindow = win; |
| 1965 | addInputMethodWindowToListLocked(win); |
| 1966 | imMayMove = false; |
| 1967 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1968 | mInputMethodDialogs.add(win); |
| 1969 | addWindowToListInOrderLocked(win, true); |
| 1970 | adjustInputMethodDialogsLocked(); |
| 1971 | imMayMove = false; |
| 1972 | } else { |
| 1973 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1974 | if (attrs.type == TYPE_WALLPAPER) { |
| 1975 | mLastWallpaperTimeoutTime = 0; |
| 1976 | adjustWallpaperWindowsLocked(); |
| 1977 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1978 | adjustWallpaperWindowsLocked(); |
| 1979 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1981 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1983 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1985 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | if (mInTouchMode) { |
| 1987 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1988 | } |
| 1989 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1990 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1991 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1992 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1993 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1994 | if (win.canReceiveKeys()) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1995 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1996 | == true) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | imMayMove = false; |
| 1998 | } |
| 1999 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2002 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2003 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2004 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | assignLayersLocked(); |
| 2006 | // Don't do layout here, the window must call |
| 2007 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2008 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | //dump(); |
| 2010 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2011 | if (focusChanged) { |
| 2012 | if (mCurrentFocus != null) { |
| 2013 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 2014 | } |
| 2015 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2016 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2017 | TAG, "New client " + client.asBinder() |
| 2018 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2019 | |
| 2020 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2021 | reportNewConfig = true; |
| 2022 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 2026 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 2027 | // identity anyway, so it's safe to just clear & restore around this whole |
| 2028 | // block. |
| 2029 | final long origId = Binder.clearCallingIdentity(); |
| 2030 | if (reportNewConfig) { |
| 2031 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | } |
| 2033 | Binder.restoreCallingIdentity(origId); |
| 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 | return res; |
| 2036 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2037 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2038 | public void removeWindow(Session session, IWindow client) { |
| 2039 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2040 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | if (win == null) { |
| 2042 | return; |
| 2043 | } |
| 2044 | removeWindowLocked(session, win); |
| 2045 | } |
| 2046 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2047 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2048 | public void removeWindowLocked(Session session, WindowState win) { |
| 2049 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2050 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2051 | TAG, "Remove " + win + " client=" |
| 2052 | + Integer.toHexString(System.identityHashCode( |
| 2053 | win.mClient.asBinder())) |
| 2054 | + ", surface=" + win.mSurface); |
| 2055 | |
| 2056 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2057 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2058 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2059 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2060 | + " mExiting=" + win.mExiting |
| 2061 | + " isAnimating=" + win.isAnimating() |
| 2062 | + " app-animation=" |
| 2063 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2064 | + " inPendingTransaction=" |
| 2065 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2066 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2067 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2068 | boolean wasVisible = false; |
| 2069 | // First, see if we need to run an animation. If we do, we have |
| 2070 | // to hold off on removing the window until the animation is done. |
| 2071 | // If the display is frozen, just remove immediately, since the |
| 2072 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2073 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | // If we are not currently running the exit animation, we |
| 2075 | // need to see about starting one. |
| 2076 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2077 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2079 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2080 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2081 | } |
| 2082 | // Try starting an animation. |
| 2083 | if (applyAnimationLocked(win, transit, false)) { |
| 2084 | win.mExiting = true; |
| 2085 | } |
| 2086 | } |
| 2087 | if (win.mExiting || win.isAnimating()) { |
| 2088 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2089 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | win.mExiting = true; |
| 2091 | win.mRemoveOnExit = true; |
| 2092 | mLayoutNeeded = true; |
| 2093 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2094 | performLayoutAndPlaceSurfacesLocked(); |
| 2095 | if (win.mAppToken != null) { |
| 2096 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2097 | } |
| 2098 | //dump(); |
| 2099 | Binder.restoreCallingIdentity(origId); |
| 2100 | return; |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | removeWindowInnerLocked(session, win); |
| 2105 | // Removing a visible window will effect the computed orientation |
| 2106 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2107 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2108 | != mForcedAppOrientation |
| 2109 | && updateOrientationFromAppTokensLocked()) { |
| 2110 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2111 | } |
| 2112 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2113 | Binder.restoreCallingIdentity(origId); |
| 2114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2116 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 2117 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 2118 | KeyWaiter.RETURN_NOTHING); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 2120 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2121 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | if (mInputMethodTarget == win) { |
| 2125 | moveInputMethodWindowsIfNeededLocked(false); |
| 2126 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2127 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2128 | if (false) { |
| 2129 | RuntimeException e = new RuntimeException("here"); |
| 2130 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2131 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2132 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2134 | mPolicy.removeWindowLw(win); |
| 2135 | win.removeLocked(); |
| 2136 | |
| 2137 | mWindowMap.remove(win.mClient.asBinder()); |
| 2138 | mWindows.remove(win); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2139 | 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] | 2140 | |
| 2141 | if (mInputMethodWindow == win) { |
| 2142 | mInputMethodWindow = null; |
| 2143 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2144 | mInputMethodDialogs.remove(win); |
| 2145 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | final WindowToken token = win.mToken; |
| 2148 | final AppWindowToken atoken = win.mAppToken; |
| 2149 | token.windows.remove(win); |
| 2150 | if (atoken != null) { |
| 2151 | atoken.allAppWindows.remove(win); |
| 2152 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2153 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | TAG, "**** Removing window " + win + ": count=" |
| 2155 | + token.windows.size()); |
| 2156 | if (token.windows.size() == 0) { |
| 2157 | if (!token.explicit) { |
| 2158 | mTokenMap.remove(token.token); |
| 2159 | mTokenList.remove(token); |
| 2160 | } else if (atoken != null) { |
| 2161 | atoken.firstWindowDrawn = false; |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | if (atoken != null) { |
| 2166 | if (atoken.startingWindow == win) { |
| 2167 | atoken.startingWindow = null; |
| 2168 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2169 | // If this is the last window and we had requested a starting |
| 2170 | // transition window, well there is no point now. |
| 2171 | atoken.startingData = null; |
| 2172 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2173 | // If this is the last window except for a starting transition |
| 2174 | // window, we need to get rid of the starting transition. |
| 2175 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2176 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | + ": no more real windows"); |
| 2178 | } |
| 2179 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2180 | mH.sendMessage(m); |
| 2181 | } |
| 2182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2183 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2184 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2185 | mLastWallpaperTimeoutTime = 0; |
| 2186 | adjustWallpaperWindowsLocked(); |
| 2187 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2188 | adjustWallpaperWindowsLocked(); |
| 2189 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2190 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | if (!mInLayout) { |
| 2192 | assignLayersLocked(); |
| 2193 | mLayoutNeeded = true; |
| 2194 | performLayoutAndPlaceSurfacesLocked(); |
| 2195 | if (win.mAppToken != null) { |
| 2196 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2197 | } |
| 2198 | } |
| 2199 | } |
| 2200 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2201 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2202 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2203 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2204 | if (where != null) { |
| 2205 | Slog.i(TAG, str, where); |
| 2206 | } else { |
| 2207 | Slog.i(TAG, str); |
| 2208 | } |
| 2209 | } |
| 2210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2212 | long origId = Binder.clearCallingIdentity(); |
| 2213 | try { |
| 2214 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2215 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2217 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | Surface.openTransaction(); |
| 2219 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2220 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2221 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2222 | w.mSurface.setTransparentRegionHint(region); |
| 2223 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2224 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | Surface.closeTransaction(); |
| 2226 | } |
| 2227 | } |
| 2228 | } |
| 2229 | } finally { |
| 2230 | Binder.restoreCallingIdentity(origId); |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2235 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2236 | Rect visibleInsets) { |
| 2237 | long origId = Binder.clearCallingIdentity(); |
| 2238 | try { |
| 2239 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2240 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2241 | if (w != null) { |
| 2242 | w.mGivenInsetsPending = false; |
| 2243 | w.mGivenContentInsets.set(contentInsets); |
| 2244 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2245 | w.mTouchableInsets = touchableInsets; |
| 2246 | mLayoutNeeded = true; |
| 2247 | performLayoutAndPlaceSurfacesLocked(); |
| 2248 | } |
| 2249 | } |
| 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(origId); |
| 2252 | } |
| 2253 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2254 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2256 | Rect outDisplayFrame) { |
| 2257 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2258 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | if (win == null) { |
| 2260 | outDisplayFrame.setEmpty(); |
| 2261 | return; |
| 2262 | } |
| 2263 | outDisplayFrame.set(win.mDisplayFrame); |
| 2264 | } |
| 2265 | } |
| 2266 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2267 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2268 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2269 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2270 | window.mWallpaperX = x; |
| 2271 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2272 | window.mWallpaperXStep = xStep; |
| 2273 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2274 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2275 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2276 | } |
| 2277 | } |
| 2278 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2279 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2280 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2281 | synchronized (mWindowMap) { |
| 2282 | if (mWaitingOnWallpaper != null && |
| 2283 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2284 | mWaitingOnWallpaper = null; |
| 2285 | mWindowMap.notifyAll(); |
| 2286 | } |
| 2287 | } |
| 2288 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2289 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2290 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2291 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2292 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2293 | || window == mUpperWallpaperTarget) { |
| 2294 | boolean doWait = sync; |
| 2295 | int curTokenIndex = mWallpaperTokens.size(); |
| 2296 | while (curTokenIndex > 0) { |
| 2297 | curTokenIndex--; |
| 2298 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2299 | int curWallpaperIndex = token.windows.size(); |
| 2300 | while (curWallpaperIndex > 0) { |
| 2301 | curWallpaperIndex--; |
| 2302 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2303 | try { |
| 2304 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2305 | x, y, z, extras, sync); |
| 2306 | // We only want to be synchronous with one wallpaper. |
| 2307 | sync = false; |
| 2308 | } catch (RemoteException e) { |
| 2309 | } |
| 2310 | } |
| 2311 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2312 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2313 | if (doWait) { |
| 2314 | // XXX Need to wait for result. |
| 2315 | } |
| 2316 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2317 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2318 | return null; |
| 2319 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | public int relayoutWindow(Session session, IWindow client, |
| 2322 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2323 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2324 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2325 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | boolean displayed = false; |
| 2327 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2328 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2330 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2331 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2332 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2333 | if (win == null) { |
| 2334 | return 0; |
| 2335 | } |
| 2336 | win.mRequestedWidth = requestedWidth; |
| 2337 | win.mRequestedHeight = requestedHeight; |
| 2338 | |
| 2339 | if (attrs != null) { |
| 2340 | mPolicy.adjustWindowParamsLw(attrs); |
| 2341 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2342 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2343 | int attrChanges = 0; |
| 2344 | int flagChanges = 0; |
| 2345 | if (attrs != null) { |
| 2346 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2347 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2348 | } |
| 2349 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2350 | 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] | 2351 | |
| 2352 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2353 | win.mAlpha = attrs.alpha; |
| 2354 | } |
| 2355 | |
| 2356 | final boolean scaledWindow = |
| 2357 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2358 | |
| 2359 | if (scaledWindow) { |
| 2360 | // requested{Width|Height} Surface's physical size |
| 2361 | // attrs.{width|height} Size on screen |
| 2362 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2363 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2364 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2365 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2366 | } else { |
| 2367 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | boolean imMayMove = (flagChanges&( |
| 2371 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2372 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2375 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2376 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2377 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2378 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2379 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2381 | win.mRelayoutCalled = true; |
| 2382 | final int oldVisibility = win.mViewVisibility; |
| 2383 | win.mViewVisibility = viewVisibility; |
| 2384 | if (viewVisibility == View.VISIBLE && |
| 2385 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2386 | displayed = !win.isVisibleLw(); |
| 2387 | if (win.mExiting) { |
| 2388 | win.mExiting = false; |
| 2389 | win.mAnimation = null; |
| 2390 | } |
| 2391 | if (win.mDestroying) { |
| 2392 | win.mDestroying = false; |
| 2393 | mDestroySurface.remove(win); |
| 2394 | } |
| 2395 | if (oldVisibility == View.GONE) { |
| 2396 | win.mEnterAnimationPending = true; |
| 2397 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2398 | if (displayed) { |
| 2399 | if (win.mSurface != null && !win.mDrawPending |
| 2400 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2401 | && mPolicy.isScreenOn()) { |
| 2402 | applyEnterAnimationLocked(win); |
| 2403 | } |
| 2404 | if ((win.mAttrs.flags |
| 2405 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2406 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2407 | "Relayout window turning screen on: " + win); |
| 2408 | win.mTurnOnScreen = true; |
| 2409 | } |
| 2410 | int diff = 0; |
| 2411 | if (win.mConfiguration != mCurConfiguration |
| 2412 | && (win.mConfiguration == null |
| 2413 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2414 | win.mConfiguration = mCurConfiguration; |
| 2415 | if (DEBUG_CONFIGURATION) { |
| 2416 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2417 | + win.mConfiguration + " / 0x" |
| 2418 | + Integer.toHexString(diff)); |
| 2419 | } |
| 2420 | outConfig.setTo(mCurConfiguration); |
| 2421 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2422 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2424 | // To change the format, we need to re-build the surface. |
| 2425 | win.destroySurfaceLocked(); |
| 2426 | displayed = true; |
| 2427 | } |
| 2428 | try { |
| 2429 | Surface surface = win.createSurfaceLocked(); |
| 2430 | if (surface != null) { |
| 2431 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2432 | win.mReportDestroySurface = false; |
| 2433 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2434 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2435 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2436 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2437 | // For some reason there isn't a surface. Clear the |
| 2438 | // caller's object so they see the same state. |
| 2439 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | } |
| 2441 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2442 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2443 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2444 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2445 | Binder.restoreCallingIdentity(origId); |
| 2446 | return 0; |
| 2447 | } |
| 2448 | if (displayed) { |
| 2449 | focusMayChange = true; |
| 2450 | } |
| 2451 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2452 | && mInputMethodWindow == null) { |
| 2453 | mInputMethodWindow = win; |
| 2454 | imMayMove = true; |
| 2455 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2456 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2457 | && win.mAppToken != null |
| 2458 | && win.mAppToken.startingWindow != null) { |
| 2459 | // Special handling of starting window over the base |
| 2460 | // window of the app: propagate lock screen flags to it, |
| 2461 | // to provide the correct semantics while starting. |
| 2462 | final int mask = |
| 2463 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2464 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2465 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2466 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2467 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2468 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | } else { |
| 2470 | win.mEnterAnimationPending = false; |
| 2471 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2472 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2473 | + ": mExiting=" + win.mExiting |
| 2474 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2475 | // If we are not currently running the exit animation, we |
| 2476 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2477 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | // Try starting an animation; if there isn't one, we |
| 2479 | // can destroy the surface right away. |
| 2480 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2481 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2482 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2483 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2484 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2486 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | win.mExiting = true; |
| 2488 | mKeyWaiter.finishedKey(session, client, true, |
| 2489 | KeyWaiter.RETURN_NOTHING); |
| 2490 | } else if (win.isAnimating()) { |
| 2491 | // Currently in a hide animation... turn this into |
| 2492 | // an exit. |
| 2493 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2494 | } else if (win == mWallpaperTarget) { |
| 2495 | // If the wallpaper is currently behind this |
| 2496 | // window, we need to change both of them inside |
| 2497 | // of a transaction to avoid artifacts. |
| 2498 | win.mExiting = true; |
| 2499 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | } else { |
| 2501 | if (mInputMethodWindow == win) { |
| 2502 | mInputMethodWindow = null; |
| 2503 | } |
| 2504 | win.destroySurfaceLocked(); |
| 2505 | } |
| 2506 | } |
| 2507 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2508 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2509 | if (win.mSurface == null || (win.getAttrs().flags |
| 2510 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2511 | || win.mSurfacePendingDestroy) { |
| 2512 | // We are being called from a local process, which |
| 2513 | // means outSurface holds its current surface. Ensure the |
| 2514 | // surface object is cleared, but we don't want it actually |
| 2515 | // destroyed at this point. |
| 2516 | win.mSurfacePendingDestroy = false; |
| 2517 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2518 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2519 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2520 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2521 | "Keeping surface, will report destroy: " + win); |
| 2522 | win.mReportDestroySurface = true; |
| 2523 | outSurface.copyFrom(win.mSurface); |
| 2524 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | } |
| 2526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | if (focusMayChange) { |
| 2528 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2529 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2530 | imMayMove = false; |
| 2531 | } |
| 2532 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2533 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2534 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2535 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2536 | // reassign them at this point if the IM window state gets shuffled |
| 2537 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2539 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2540 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2541 | // Little hack here -- we -should- be able to rely on the |
| 2542 | // function to return true if the IME has moved and needs |
| 2543 | // its layer recomputed. However, if the IME was hidden |
| 2544 | // and isn't actually moved in the list, its layer may be |
| 2545 | // 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] | 2546 | assignLayers = true; |
| 2547 | } |
| 2548 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2549 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2550 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2551 | assignLayers = true; |
| 2552 | } |
| 2553 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | mLayoutNeeded = true; |
| 2556 | win.mGivenInsetsPending = insetsPending; |
| 2557 | if (assignLayers) { |
| 2558 | assignLayersLocked(); |
| 2559 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2560 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2561 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2562 | if (displayed && win.mIsWallpaper) { |
| 2563 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2564 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2565 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | if (win.mAppToken != null) { |
| 2567 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2568 | } |
| 2569 | outFrame.set(win.mFrame); |
| 2570 | outContentInsets.set(win.mContentInsets); |
| 2571 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2572 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2574 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2575 | + ", requestedHeight=" + requestedHeight |
| 2576 | + ", viewVisibility=" + viewVisibility |
| 2577 | + "\nRelayout returning frame=" + outFrame |
| 2578 | + ", surface=" + outSurface); |
| 2579 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2580 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2582 | |
| 2583 | inTouchMode = mInTouchMode; |
| 2584 | } |
| 2585 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2586 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | sendNewConfiguration(); |
| 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 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2592 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2593 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2594 | } |
| 2595 | |
| 2596 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2597 | final long origId = Binder.clearCallingIdentity(); |
| 2598 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2599 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2600 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2601 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2602 | adjustWallpaperWindowsLocked(); |
| 2603 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2604 | mLayoutNeeded = true; |
| 2605 | performLayoutAndPlaceSurfacesLocked(); |
| 2606 | } |
| 2607 | } |
| 2608 | Binder.restoreCallingIdentity(origId); |
| 2609 | } |
| 2610 | |
| 2611 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2612 | 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] | 2613 | + (lp != null ? lp.packageName : null) |
| 2614 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2615 | if (lp != null && lp.windowAnimations != 0) { |
| 2616 | // If this is a system resource, don't try to load it from the |
| 2617 | // application resources. It is nice to avoid loading application |
| 2618 | // resources if we can. |
| 2619 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2620 | int resId = lp.windowAnimations; |
| 2621 | if ((resId&0xFF000000) == 0x01000000) { |
| 2622 | packageName = "android"; |
| 2623 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2624 | 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] | 2625 | + packageName); |
| 2626 | return AttributeCache.instance().get(packageName, resId, |
| 2627 | com.android.internal.R.styleable.WindowAnimation); |
| 2628 | } |
| 2629 | return null; |
| 2630 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2631 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2632 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2633 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2634 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2635 | if (packageName != null) { |
| 2636 | if ((resId&0xFF000000) == 0x01000000) { |
| 2637 | packageName = "android"; |
| 2638 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2639 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2640 | + packageName); |
| 2641 | return AttributeCache.instance().get(packageName, resId, |
| 2642 | com.android.internal.R.styleable.WindowAnimation); |
| 2643 | } |
| 2644 | return null; |
| 2645 | } |
| 2646 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | private void applyEnterAnimationLocked(WindowState win) { |
| 2648 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2649 | if (win.mEnterAnimationPending) { |
| 2650 | win.mEnterAnimationPending = false; |
| 2651 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2652 | } |
| 2653 | |
| 2654 | applyAnimationLocked(win, transit, true); |
| 2655 | } |
| 2656 | |
| 2657 | private boolean applyAnimationLocked(WindowState win, |
| 2658 | int transit, boolean isEntrance) { |
| 2659 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2660 | // If we are trying to apply an animation, but already running |
| 2661 | // an animation of the same type, then just leave that one alone. |
| 2662 | return true; |
| 2663 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2664 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2665 | // Only apply an animation if the display isn't frozen. If it is |
| 2666 | // frozen, there is no reason to animate and it can cause strange |
| 2667 | // artifacts when we unfreeze the display if some different animation |
| 2668 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2669 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2671 | int attr = -1; |
| 2672 | Animation a = null; |
| 2673 | if (anim != 0) { |
| 2674 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2675 | } else { |
| 2676 | switch (transit) { |
| 2677 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2678 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2679 | break; |
| 2680 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2681 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2682 | break; |
| 2683 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2684 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2685 | break; |
| 2686 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2687 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2688 | break; |
| 2689 | } |
| 2690 | if (attr >= 0) { |
| 2691 | a = loadAnimation(win.mAttrs, attr); |
| 2692 | } |
| 2693 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2694 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2696 | + " mAnimation=" + win.mAnimation |
| 2697 | + " isEntrance=" + isEntrance); |
| 2698 | if (a != null) { |
| 2699 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2700 | RuntimeException e = null; |
| 2701 | if (!HIDE_STACK_CRAWLS) { |
| 2702 | e = new RuntimeException(); |
| 2703 | e.fillInStackTrace(); |
| 2704 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2705 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2706 | } |
| 2707 | win.setAnimation(a); |
| 2708 | win.mAnimationIsEntrance = isEntrance; |
| 2709 | } |
| 2710 | } else { |
| 2711 | win.clearAnimation(); |
| 2712 | } |
| 2713 | |
| 2714 | return win.mAnimation != null; |
| 2715 | } |
| 2716 | |
| 2717 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2718 | int anim = 0; |
| 2719 | Context context = mContext; |
| 2720 | if (animAttr >= 0) { |
| 2721 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2722 | if (ent != null) { |
| 2723 | context = ent.context; |
| 2724 | anim = ent.array.getResourceId(animAttr, 0); |
| 2725 | } |
| 2726 | } |
| 2727 | if (anim != 0) { |
| 2728 | return AnimationUtils.loadAnimation(context, anim); |
| 2729 | } |
| 2730 | return null; |
| 2731 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2732 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2733 | private Animation loadAnimation(String packageName, int resId) { |
| 2734 | int anim = 0; |
| 2735 | Context context = mContext; |
| 2736 | if (resId >= 0) { |
| 2737 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2738 | if (ent != null) { |
| 2739 | context = ent.context; |
| 2740 | anim = resId; |
| 2741 | } |
| 2742 | } |
| 2743 | if (anim != 0) { |
| 2744 | return AnimationUtils.loadAnimation(context, anim); |
| 2745 | } |
| 2746 | return null; |
| 2747 | } |
| 2748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2750 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2751 | // Only apply an animation if the display isn't frozen. If it is |
| 2752 | // frozen, there is no reason to animate and it can cause strange |
| 2753 | // artifacts when we unfreeze the display if some different animation |
| 2754 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2755 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2756 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2757 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2758 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2759 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2760 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2761 | } else if (mNextAppTransitionPackage != null) { |
| 2762 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2763 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2764 | } else { |
| 2765 | int animAttr = 0; |
| 2766 | switch (transit) { |
| 2767 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2768 | animAttr = enter |
| 2769 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2770 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2771 | break; |
| 2772 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2773 | animAttr = enter |
| 2774 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2775 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2776 | break; |
| 2777 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2778 | animAttr = enter |
| 2779 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2780 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2781 | break; |
| 2782 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2783 | animAttr = enter |
| 2784 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2785 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2786 | break; |
| 2787 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2788 | animAttr = enter |
| 2789 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2790 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2791 | break; |
| 2792 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2793 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2794 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2795 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2796 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2797 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2798 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2799 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2800 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2801 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2802 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2803 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2804 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2805 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2806 | break; |
| 2807 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2808 | animAttr = enter |
| 2809 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2810 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2811 | break; |
| 2812 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2813 | animAttr = enter |
| 2814 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2815 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2816 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2817 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2818 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2819 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2820 | + " anim=" + a |
| 2821 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2822 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2824 | if (a != null) { |
| 2825 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2826 | RuntimeException e = null; |
| 2827 | if (!HIDE_STACK_CRAWLS) { |
| 2828 | e = new RuntimeException(); |
| 2829 | e.fillInStackTrace(); |
| 2830 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2831 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2832 | } |
| 2833 | wtoken.setAnimation(a); |
| 2834 | } |
| 2835 | } else { |
| 2836 | wtoken.clearAnimation(); |
| 2837 | } |
| 2838 | |
| 2839 | return wtoken.animation != null; |
| 2840 | } |
| 2841 | |
| 2842 | // ------------------------------------------------------------- |
| 2843 | // Application Window Tokens |
| 2844 | // ------------------------------------------------------------- |
| 2845 | |
| 2846 | public void validateAppTokens(List tokens) { |
| 2847 | int v = tokens.size()-1; |
| 2848 | int m = mAppTokens.size()-1; |
| 2849 | while (v >= 0 && m >= 0) { |
| 2850 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2851 | if (wtoken.removed) { |
| 2852 | m--; |
| 2853 | continue; |
| 2854 | } |
| 2855 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2856 | 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] | 2857 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2858 | } |
| 2859 | v--; |
| 2860 | m--; |
| 2861 | } |
| 2862 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2863 | 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] | 2864 | v--; |
| 2865 | } |
| 2866 | while (m >= 0) { |
| 2867 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2868 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2869 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | } |
| 2871 | m--; |
| 2872 | } |
| 2873 | } |
| 2874 | |
| 2875 | boolean checkCallingPermission(String permission, String func) { |
| 2876 | // Quick check: if the calling permission is me, it's all okay. |
| 2877 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2878 | return true; |
| 2879 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | if (mContext.checkCallingPermission(permission) |
| 2882 | == PackageManager.PERMISSION_GRANTED) { |
| 2883 | return true; |
| 2884 | } |
| 2885 | String msg = "Permission Denial: " + func + " from pid=" |
| 2886 | + Binder.getCallingPid() |
| 2887 | + ", uid=" + Binder.getCallingUid() |
| 2888 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2889 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | return false; |
| 2891 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2894 | WindowToken wtoken = mTokenMap.get(token); |
| 2895 | if (wtoken == null) { |
| 2896 | return null; |
| 2897 | } |
| 2898 | return wtoken.appWindowToken; |
| 2899 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2900 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | public void addWindowToken(IBinder token, int type) { |
| 2902 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2903 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2904 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | synchronized(mWindowMap) { |
| 2908 | WindowToken wtoken = mTokenMap.get(token); |
| 2909 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2910 | 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] | 2911 | return; |
| 2912 | } |
| 2913 | wtoken = new WindowToken(token, type, true); |
| 2914 | mTokenMap.put(token, wtoken); |
| 2915 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2916 | if (type == TYPE_WALLPAPER) { |
| 2917 | mWallpaperTokens.add(wtoken); |
| 2918 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2919 | } |
| 2920 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2921 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2922 | public void removeWindowToken(IBinder token) { |
| 2923 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2924 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2925 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | final long origId = Binder.clearCallingIdentity(); |
| 2929 | synchronized(mWindowMap) { |
| 2930 | WindowToken wtoken = mTokenMap.remove(token); |
| 2931 | mTokenList.remove(wtoken); |
| 2932 | if (wtoken != null) { |
| 2933 | boolean delayed = false; |
| 2934 | if (!wtoken.hidden) { |
| 2935 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2936 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | final int N = wtoken.windows.size(); |
| 2938 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2939 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | for (int i=0; i<N; i++) { |
| 2941 | WindowState win = wtoken.windows.get(i); |
| 2942 | |
| 2943 | if (win.isAnimating()) { |
| 2944 | delayed = true; |
| 2945 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | if (win.isVisibleNow()) { |
| 2948 | applyAnimationLocked(win, |
| 2949 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2950 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2951 | KeyWaiter.RETURN_NOTHING); |
| 2952 | changed = true; |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | if (changed) { |
| 2957 | mLayoutNeeded = true; |
| 2958 | performLayoutAndPlaceSurfacesLocked(); |
| 2959 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2960 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2961 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | if (delayed) { |
| 2963 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2964 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2965 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | } |
| 2967 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2970 | 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] | 2971 | } |
| 2972 | } |
| 2973 | Binder.restoreCallingIdentity(origId); |
| 2974 | } |
| 2975 | |
| 2976 | public void addAppToken(int addPos, IApplicationToken token, |
| 2977 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2978 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2979 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2980 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | synchronized(mWindowMap) { |
| 2984 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2985 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2986 | 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] | 2987 | return; |
| 2988 | } |
| 2989 | wtoken = new AppWindowToken(token); |
| 2990 | wtoken.groupId = groupId; |
| 2991 | wtoken.appFullscreen = fullscreen; |
| 2992 | wtoken.requestedOrientation = requestedOrientation; |
| 2993 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2994 | 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] | 2995 | mTokenMap.put(token.asBinder(), wtoken); |
| 2996 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2997 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2998 | // Application tokens start out hidden. |
| 2999 | wtoken.hidden = true; |
| 3000 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | //dump(); |
| 3003 | } |
| 3004 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | public void setAppGroupId(IBinder token, int groupId) { |
| 3007 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3008 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3009 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | synchronized(mWindowMap) { |
| 3013 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3014 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3015 | 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] | 3016 | return; |
| 3017 | } |
| 3018 | wtoken.groupId = groupId; |
| 3019 | } |
| 3020 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3021 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | public int getOrientationFromWindowsLocked() { |
| 3023 | int pos = mWindows.size() - 1; |
| 3024 | while (pos >= 0) { |
| 3025 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 3026 | pos--; |
| 3027 | if (wtoken.mAppToken != null) { |
| 3028 | // We hit an application window. so the orientation will be determined by the |
| 3029 | // app window. No point in continuing further. |
| 3030 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3031 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3032 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | continue; |
| 3034 | } |
| 3035 | int req = wtoken.mAttrs.screenOrientation; |
| 3036 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3037 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3038 | continue; |
| 3039 | } else { |
| 3040 | return req; |
| 3041 | } |
| 3042 | } |
| 3043 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3044 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3046 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3047 | int pos = mAppTokens.size() - 1; |
| 3048 | int curGroup = 0; |
| 3049 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3050 | boolean findingBehind = false; |
| 3051 | boolean haveGroup = false; |
| 3052 | boolean lastFullscreen = false; |
| 3053 | while (pos >= 0) { |
| 3054 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3055 | pos--; |
| 3056 | // if we're about to tear down this window and not seek for |
| 3057 | // the behind activity, don't use it for orientation |
| 3058 | if (!findingBehind |
| 3059 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3060 | continue; |
| 3061 | } |
| 3062 | |
| 3063 | if (!haveGroup) { |
| 3064 | // We ignore any hidden applications on the top. |
| 3065 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3066 | continue; |
| 3067 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3068 | haveGroup = true; |
| 3069 | curGroup = wtoken.groupId; |
| 3070 | lastOrientation = wtoken.requestedOrientation; |
| 3071 | } else if (curGroup != wtoken.groupId) { |
| 3072 | // If we have hit a new application group, and the bottom |
| 3073 | // of the previous group didn't explicitly say to use |
| 3074 | // the orientation behind it, and the last app was |
| 3075 | // full screen, then we'll stick with the |
| 3076 | // user's orientation. |
| 3077 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3078 | && lastFullscreen) { |
| 3079 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3080 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3082 | int or = wtoken.requestedOrientation; |
| 3083 | // If this application is fullscreen, and didn't explicitly say |
| 3084 | // to use the orientation behind it, then just take whatever |
| 3085 | // orientation it has and ignores whatever is under it. |
| 3086 | lastFullscreen = wtoken.appFullscreen; |
| 3087 | if (lastFullscreen |
| 3088 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3089 | return or; |
| 3090 | } |
| 3091 | // If this application has requested an explicit orientation, |
| 3092 | // then use it. |
| 3093 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3094 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3095 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3096 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3097 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3098 | return or; |
| 3099 | } |
| 3100 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3101 | } |
| 3102 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3103 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3104 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3106 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3107 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3108 | "updateOrientationFromAppTokens()")) { |
| 3109 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3110 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3111 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3112 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3113 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3114 | |
| 3115 | synchronized(mWindowMap) { |
| 3116 | if (updateOrientationFromAppTokensLocked()) { |
| 3117 | if (freezeThisOneIfNeeded != null) { |
| 3118 | AppWindowToken wtoken = findAppWindowToken( |
| 3119 | freezeThisOneIfNeeded); |
| 3120 | if (wtoken != null) { |
| 3121 | startAppFreezingScreenLocked(wtoken, |
| 3122 | ActivityInfo.CONFIG_ORIENTATION); |
| 3123 | } |
| 3124 | } |
| 3125 | config = computeNewConfigurationLocked(); |
| 3126 | |
| 3127 | } else if (currentConfig != null) { |
| 3128 | // No obvious action we need to take, but if our current |
| 3129 | // state mismatches the activity maanager's, update it |
| 3130 | mTempConfiguration.setToDefaults(); |
| 3131 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3132 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3133 | mWaitingForConfig = true; |
| 3134 | mLayoutNeeded = true; |
| 3135 | startFreezingDisplayLocked(); |
| 3136 | config = new Configuration(mTempConfiguration); |
| 3137 | } |
| 3138 | } |
| 3139 | } |
| 3140 | } |
| 3141 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3142 | Binder.restoreCallingIdentity(ident); |
| 3143 | return config; |
| 3144 | } |
| 3145 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3146 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3147 | * Determine the new desired orientation of the display, returning |
| 3148 | * a non-null new Configuration if it has changed from the current |
| 3149 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3150 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3151 | * SCREEN. This will typically be done for you if you call |
| 3152 | * sendNewConfiguration(). |
| 3153 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3154 | * The orientation is computed from non-application windows first. If none of |
| 3155 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3156 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3157 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3158 | * android.os.IBinder) |
| 3159 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3160 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3161 | if (mDisplayFrozen) { |
| 3162 | // If the display is frozen, some activities may be in the middle |
| 3163 | // of restarting, and thus have removed their old window. If the |
| 3164 | // window has the flag to hide the lock screen, then the lock screen |
| 3165 | // can re-appear and inflict its own orientation on us. Keep the |
| 3166 | // orientation stable until this all settles down. |
| 3167 | return false; |
| 3168 | } |
| 3169 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | long ident = Binder.clearCallingIdentity(); |
| 3172 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3173 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3175 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3176 | mForcedAppOrientation = req; |
| 3177 | //send a message to Policy indicating orientation change to take |
| 3178 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3179 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3180 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3181 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3182 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3183 | } |
| 3184 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3185 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3186 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | } finally { |
| 3188 | Binder.restoreCallingIdentity(ident); |
| 3189 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3191 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3192 | int computeForcedAppOrientationLocked() { |
| 3193 | int req = getOrientationFromWindowsLocked(); |
| 3194 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3195 | req = getOrientationFromAppTokensLocked(); |
| 3196 | } |
| 3197 | return req; |
| 3198 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3199 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3200 | public void setNewConfiguration(Configuration config) { |
| 3201 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3202 | "setNewConfiguration()")) { |
| 3203 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3204 | } |
| 3205 | |
| 3206 | synchronized(mWindowMap) { |
| 3207 | mCurConfiguration = new Configuration(config); |
| 3208 | mWaitingForConfig = false; |
| 3209 | performLayoutAndPlaceSurfacesLocked(); |
| 3210 | } |
| 3211 | } |
| 3212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3214 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3215 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3216 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3218 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3219 | synchronized(mWindowMap) { |
| 3220 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3221 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3222 | 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] | 3223 | return; |
| 3224 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | wtoken.requestedOrientation = requestedOrientation; |
| 3227 | } |
| 3228 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3229 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3230 | public int getAppOrientation(IApplicationToken token) { |
| 3231 | synchronized(mWindowMap) { |
| 3232 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3233 | if (wtoken == null) { |
| 3234 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3235 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3236 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | return wtoken.requestedOrientation; |
| 3238 | } |
| 3239 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3241 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3242 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3243 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3244 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | synchronized(mWindowMap) { |
| 3248 | boolean changed = false; |
| 3249 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3250 | 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] | 3251 | changed = mFocusedApp != null; |
| 3252 | mFocusedApp = null; |
| 3253 | mKeyWaiter.tickle(); |
| 3254 | } else { |
| 3255 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3256 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3257 | 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] | 3258 | return; |
| 3259 | } |
| 3260 | changed = mFocusedApp != newFocus; |
| 3261 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3262 | 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] | 3263 | mKeyWaiter.tickle(); |
| 3264 | } |
| 3265 | |
| 3266 | if (moveFocusNow && changed) { |
| 3267 | final long origId = Binder.clearCallingIdentity(); |
| 3268 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3269 | Binder.restoreCallingIdentity(origId); |
| 3270 | } |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | public void prepareAppTransition(int transit) { |
| 3275 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3276 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3277 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3280 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3281 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3282 | TAG, "Prepare app transition: transit=" + transit |
| 3283 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3284 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3285 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3286 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3288 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3289 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3290 | // Opening a new task always supersedes a close for the anim. |
| 3291 | mNextAppTransition = transit; |
| 3292 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3293 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3294 | // Opening a new activity always supersedes a close for the anim. |
| 3295 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | } |
| 3297 | mAppTransitionReady = false; |
| 3298 | mAppTransitionTimeout = false; |
| 3299 | mStartingIconInTransition = false; |
| 3300 | mSkipAppTransitionAnimation = false; |
| 3301 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3302 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3303 | 5000); |
| 3304 | } |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | public int getPendingAppTransition() { |
| 3309 | return mNextAppTransition; |
| 3310 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3311 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3312 | public void overridePendingAppTransition(String packageName, |
| 3313 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3314 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3315 | mNextAppTransitionPackage = packageName; |
| 3316 | mNextAppTransitionEnter = enterAnim; |
| 3317 | mNextAppTransitionExit = exitAnim; |
| 3318 | } |
| 3319 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3321 | public void executeAppTransition() { |
| 3322 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3323 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3324 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3327 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3328 | if (DEBUG_APP_TRANSITIONS) { |
| 3329 | RuntimeException e = new RuntimeException("here"); |
| 3330 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3331 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3332 | + mNextAppTransition, e); |
| 3333 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3334 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | mAppTransitionReady = true; |
| 3336 | final long origId = Binder.clearCallingIdentity(); |
| 3337 | performLayoutAndPlaceSurfacesLocked(); |
| 3338 | Binder.restoreCallingIdentity(origId); |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3344 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3345 | IBinder transferFrom, boolean createIfNeeded) { |
| 3346 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3347 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3348 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3352 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3354 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3357 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3358 | 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] | 3359 | return; |
| 3360 | } |
| 3361 | |
| 3362 | // If the display is frozen, we won't do anything until the |
| 3363 | // actual window is displayed so there is no reason to put in |
| 3364 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3365 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3366 | return; |
| 3367 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3368 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | if (wtoken.startingData != null) { |
| 3370 | return; |
| 3371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3373 | if (transferFrom != null) { |
| 3374 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3375 | if (ttoken != null) { |
| 3376 | WindowState startingWindow = ttoken.startingWindow; |
| 3377 | if (startingWindow != null) { |
| 3378 | if (mStartingIconInTransition) { |
| 3379 | // In this case, the starting icon has already |
| 3380 | // been displayed, so start letting windows get |
| 3381 | // shown immediately without any more transitions. |
| 3382 | mSkipAppTransitionAnimation = true; |
| 3383 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3384 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | "Moving existing starting from " + ttoken |
| 3386 | + " to " + wtoken); |
| 3387 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3388 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | // Transfer the starting window over to the new |
| 3390 | // token. |
| 3391 | wtoken.startingData = ttoken.startingData; |
| 3392 | wtoken.startingView = ttoken.startingView; |
| 3393 | wtoken.startingWindow = startingWindow; |
| 3394 | ttoken.startingData = null; |
| 3395 | ttoken.startingView = null; |
| 3396 | ttoken.startingWindow = null; |
| 3397 | ttoken.startingMoved = true; |
| 3398 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3399 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3401 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3402 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3403 | mWindows.remove(startingWindow); |
| 3404 | ttoken.windows.remove(startingWindow); |
| 3405 | ttoken.allAppWindows.remove(startingWindow); |
| 3406 | addWindowToListInOrderLocked(startingWindow, true); |
| 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 | // Propagate other interesting state between the |
| 3409 | // tokens. If the old token is displayed, we should |
| 3410 | // immediately force the new one to be displayed. If |
| 3411 | // it is animating, we need to move that animation to |
| 3412 | // the new one. |
| 3413 | if (ttoken.allDrawn) { |
| 3414 | wtoken.allDrawn = true; |
| 3415 | } |
| 3416 | if (ttoken.firstWindowDrawn) { |
| 3417 | wtoken.firstWindowDrawn = true; |
| 3418 | } |
| 3419 | if (!ttoken.hidden) { |
| 3420 | wtoken.hidden = false; |
| 3421 | wtoken.hiddenRequested = false; |
| 3422 | wtoken.willBeHidden = false; |
| 3423 | } |
| 3424 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3425 | wtoken.clientHidden = ttoken.clientHidden; |
| 3426 | wtoken.sendAppVisibilityToClients(); |
| 3427 | } |
| 3428 | if (ttoken.animation != null) { |
| 3429 | wtoken.animation = ttoken.animation; |
| 3430 | wtoken.animating = ttoken.animating; |
| 3431 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3432 | ttoken.animation = null; |
| 3433 | ttoken.animLayerAdjustment = 0; |
| 3434 | wtoken.updateLayers(); |
| 3435 | ttoken.updateLayers(); |
| 3436 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3438 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | mLayoutNeeded = true; |
| 3440 | performLayoutAndPlaceSurfacesLocked(); |
| 3441 | Binder.restoreCallingIdentity(origId); |
| 3442 | return; |
| 3443 | } else if (ttoken.startingData != null) { |
| 3444 | // The previous app was getting ready to show a |
| 3445 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3446 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3447 | "Moving pending starting from " + ttoken |
| 3448 | + " to " + wtoken); |
| 3449 | wtoken.startingData = ttoken.startingData; |
| 3450 | ttoken.startingData = null; |
| 3451 | ttoken.startingMoved = true; |
| 3452 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3453 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3454 | // want to process the message ASAP, before any other queued |
| 3455 | // messages. |
| 3456 | mH.sendMessageAtFrontOfQueue(m); |
| 3457 | return; |
| 3458 | } |
| 3459 | } |
| 3460 | } |
| 3461 | |
| 3462 | // There is no existing starting window, and the caller doesn't |
| 3463 | // want us to create one, so that's it! |
| 3464 | if (!createIfNeeded) { |
| 3465 | return; |
| 3466 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3467 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3468 | // If this is a translucent or wallpaper window, then don't |
| 3469 | // show a starting window -- the current effect (a full-screen |
| 3470 | // opaque starting window that fades away to the real contents |
| 3471 | // when it is ready) does not work for this. |
| 3472 | if (theme != 0) { |
| 3473 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3474 | com.android.internal.R.styleable.Window); |
| 3475 | if (ent.array.getBoolean( |
| 3476 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3477 | return; |
| 3478 | } |
| 3479 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3480 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3481 | return; |
| 3482 | } |
| 3483 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3484 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3485 | return; |
| 3486 | } |
| 3487 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3488 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | mStartingIconInTransition = true; |
| 3490 | wtoken.startingData = new StartingData( |
| 3491 | pkg, theme, nonLocalizedLabel, |
| 3492 | labelRes, icon); |
| 3493 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3494 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3495 | // want to process the message ASAP, before any other queued |
| 3496 | // messages. |
| 3497 | mH.sendMessageAtFrontOfQueue(m); |
| 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | public void setAppWillBeHidden(IBinder token) { |
| 3502 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3503 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3504 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | AppWindowToken wtoken; |
| 3508 | |
| 3509 | synchronized(mWindowMap) { |
| 3510 | wtoken = findAppWindowToken(token); |
| 3511 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3512 | 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] | 3513 | return; |
| 3514 | } |
| 3515 | wtoken.willBeHidden = true; |
| 3516 | } |
| 3517 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3520 | boolean visible, int transit, boolean performLayout) { |
| 3521 | boolean delayed = false; |
| 3522 | |
| 3523 | if (wtoken.clientHidden == visible) { |
| 3524 | wtoken.clientHidden = !visible; |
| 3525 | wtoken.sendAppVisibilityToClients(); |
| 3526 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3527 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | wtoken.willBeHidden = false; |
| 3529 | if (wtoken.hidden == visible) { |
| 3530 | final int N = wtoken.allAppWindows.size(); |
| 3531 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3532 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3534 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3536 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3537 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3538 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | if (wtoken.animation == sDummyAnimation) { |
| 3540 | wtoken.animation = null; |
| 3541 | } |
| 3542 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3543 | changed = true; |
| 3544 | if (wtoken.animation != null) { |
| 3545 | delayed = runningAppAnimation = true; |
| 3546 | } |
| 3547 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3548 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | for (int i=0; i<N; i++) { |
| 3550 | WindowState win = wtoken.allAppWindows.get(i); |
| 3551 | if (win == wtoken.startingWindow) { |
| 3552 | continue; |
| 3553 | } |
| 3554 | |
| 3555 | if (win.isAnimating()) { |
| 3556 | delayed = true; |
| 3557 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3558 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3559 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3560 | //win.dump(" "); |
| 3561 | if (visible) { |
| 3562 | if (!win.isVisibleNow()) { |
| 3563 | if (!runningAppAnimation) { |
| 3564 | applyAnimationLocked(win, |
| 3565 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3566 | } |
| 3567 | changed = true; |
| 3568 | } |
| 3569 | } else if (win.isVisibleNow()) { |
| 3570 | if (!runningAppAnimation) { |
| 3571 | applyAnimationLocked(win, |
| 3572 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3573 | } |
| 3574 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3575 | KeyWaiter.RETURN_NOTHING); |
| 3576 | changed = true; |
| 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3581 | if (!visible) { |
| 3582 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3583 | } else { |
| 3584 | // If we are being set visible, and the starting window is |
| 3585 | // not yet displayed, then make sure it doesn't get displayed. |
| 3586 | WindowState swin = wtoken.startingWindow; |
| 3587 | if (swin != null && (swin.mDrawPending |
| 3588 | || swin.mCommitDrawPending)) { |
| 3589 | swin.mPolicyVisibility = false; |
| 3590 | swin.mPolicyVisibilityAfterAnim = false; |
| 3591 | } |
| 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 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3595 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3596 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3597 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3598 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3599 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3600 | if (performLayout) { |
| 3601 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3602 | performLayoutAndPlaceSurfacesLocked(); |
| 3603 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3604 | } |
| 3605 | } |
| 3606 | |
| 3607 | if (wtoken.animation != null) { |
| 3608 | delayed = true; |
| 3609 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3610 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3611 | return delayed; |
| 3612 | } |
| 3613 | |
| 3614 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3615 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3616 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3617 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | AppWindowToken wtoken; |
| 3621 | |
| 3622 | synchronized(mWindowMap) { |
| 3623 | wtoken = findAppWindowToken(token); |
| 3624 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3625 | 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] | 3626 | return; |
| 3627 | } |
| 3628 | |
| 3629 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3630 | RuntimeException e = null; |
| 3631 | if (!HIDE_STACK_CRAWLS) { |
| 3632 | e = new RuntimeException(); |
| 3633 | e.fillInStackTrace(); |
| 3634 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3635 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3636 | + "): mNextAppTransition=" + mNextAppTransition |
| 3637 | + " hidden=" + wtoken.hidden |
| 3638 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3639 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3640 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | // If we are preparing an app transition, then delay changing |
| 3642 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3643 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3644 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3645 | // Already in requested state, don't do anything more. |
| 3646 | if (wtoken.hiddenRequested != visible) { |
| 3647 | return; |
| 3648 | } |
| 3649 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3650 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3651 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3652 | TAG, "Setting dummy animation on: " + wtoken); |
| 3653 | wtoken.setDummyAnimation(); |
| 3654 | mOpeningApps.remove(wtoken); |
| 3655 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3656 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | wtoken.inPendingTransaction = true; |
| 3658 | if (visible) { |
| 3659 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | wtoken.startingDisplayed = false; |
| 3661 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3662 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3663 | // If the token is currently hidden (should be the |
| 3664 | // common case), then we need to set up to wait for |
| 3665 | // its windows to be ready. |
| 3666 | if (wtoken.hidden) { |
| 3667 | wtoken.allDrawn = false; |
| 3668 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3669 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3670 | if (wtoken.clientHidden) { |
| 3671 | // In the case where we are making an app visible |
| 3672 | // but holding off for a transition, we still need |
| 3673 | // to tell the client to make its windows visible so |
| 3674 | // they get drawn. Otherwise, we will wait on |
| 3675 | // performing the transition until all windows have |
| 3676 | // been drawn, they never will be, and we are sad. |
| 3677 | wtoken.clientHidden = false; |
| 3678 | wtoken.sendAppVisibilityToClients(); |
| 3679 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | } |
| 3681 | } else { |
| 3682 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3683 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3684 | // If the token is currently visible (should be the |
| 3685 | // common case), then set up to wait for it to be hidden. |
| 3686 | if (!wtoken.hidden) { |
| 3687 | wtoken.waitingToHide = true; |
| 3688 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3689 | } |
| 3690 | return; |
| 3691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3694 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | wtoken.updateReportedVisibilityLocked(); |
| 3696 | Binder.restoreCallingIdentity(origId); |
| 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3701 | boolean unfreezeSurfaceNow, boolean force) { |
| 3702 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3703 | 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] | 3704 | + " force=" + force); |
| 3705 | final int N = wtoken.allAppWindows.size(); |
| 3706 | boolean unfrozeWindows = false; |
| 3707 | for (int i=0; i<N; i++) { |
| 3708 | WindowState w = wtoken.allAppWindows.get(i); |
| 3709 | if (w.mAppFreezing) { |
| 3710 | w.mAppFreezing = false; |
| 3711 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3712 | w.mOrientationChanging = true; |
| 3713 | } |
| 3714 | unfrozeWindows = true; |
| 3715 | } |
| 3716 | } |
| 3717 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3718 | 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] | 3719 | wtoken.freezingScreen = false; |
| 3720 | mAppsFreezingScreen--; |
| 3721 | } |
| 3722 | if (unfreezeSurfaceNow) { |
| 3723 | if (unfrozeWindows) { |
| 3724 | mLayoutNeeded = true; |
| 3725 | performLayoutAndPlaceSurfacesLocked(); |
| 3726 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3727 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | } |
| 3729 | } |
| 3730 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3731 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3732 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3733 | int configChanges) { |
| 3734 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3735 | RuntimeException e = null; |
| 3736 | if (!HIDE_STACK_CRAWLS) { |
| 3737 | e = new RuntimeException(); |
| 3738 | e.fillInStackTrace(); |
| 3739 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3740 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3741 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3742 | + wtoken.freezingScreen, e); |
| 3743 | } |
| 3744 | if (!wtoken.hiddenRequested) { |
| 3745 | if (!wtoken.freezingScreen) { |
| 3746 | wtoken.freezingScreen = true; |
| 3747 | mAppsFreezingScreen++; |
| 3748 | if (mAppsFreezingScreen == 1) { |
| 3749 | startFreezingDisplayLocked(); |
| 3750 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3751 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3752 | 5000); |
| 3753 | } |
| 3754 | } |
| 3755 | final int N = wtoken.allAppWindows.size(); |
| 3756 | for (int i=0; i<N; i++) { |
| 3757 | WindowState w = wtoken.allAppWindows.get(i); |
| 3758 | w.mAppFreezing = true; |
| 3759 | } |
| 3760 | } |
| 3761 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3763 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3764 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3765 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3766 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3770 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3771 | 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] | 3772 | return; |
| 3773 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3774 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3775 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3776 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3777 | 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] | 3778 | return; |
| 3779 | } |
| 3780 | final long origId = Binder.clearCallingIdentity(); |
| 3781 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3782 | Binder.restoreCallingIdentity(origId); |
| 3783 | } |
| 3784 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3785 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3787 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3788 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3789 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | synchronized(mWindowMap) { |
| 3793 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3794 | if (wtoken == null || wtoken.appToken == null) { |
| 3795 | return; |
| 3796 | } |
| 3797 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3798 | 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] | 3799 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3800 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3801 | Binder.restoreCallingIdentity(origId); |
| 3802 | } |
| 3803 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3805 | public void removeAppToken(IBinder token) { |
| 3806 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3807 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3808 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | AppWindowToken wtoken = null; |
| 3812 | AppWindowToken startingToken = null; |
| 3813 | boolean delayed = false; |
| 3814 | |
| 3815 | final long origId = Binder.clearCallingIdentity(); |
| 3816 | synchronized(mWindowMap) { |
| 3817 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3818 | mTokenList.remove(basewtoken); |
| 3819 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3820 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3821 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3822 | wtoken.inPendingTransaction = false; |
| 3823 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3824 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3825 | if (mClosingApps.contains(wtoken)) { |
| 3826 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3827 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3828 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3829 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | delayed = true; |
| 3831 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3832 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3834 | + " animation=" + wtoken.animation |
| 3835 | + " animating=" + wtoken.animating); |
| 3836 | if (delayed) { |
| 3837 | // set the token aside because it has an active animation to be finished |
| 3838 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3839 | } else { |
| 3840 | // Make sure there is no animation running on this token, |
| 3841 | // so any windows associated with it will be removed as |
| 3842 | // soon as their animations are complete |
| 3843 | wtoken.animation = null; |
| 3844 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3845 | } |
| 3846 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3847 | if (mLastEnterAnimToken == wtoken) { |
| 3848 | mLastEnterAnimToken = null; |
| 3849 | mLastEnterAnimParams = null; |
| 3850 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | wtoken.removed = true; |
| 3852 | if (wtoken.startingData != null) { |
| 3853 | startingToken = wtoken; |
| 3854 | } |
| 3855 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3856 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3857 | 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] | 3858 | mFocusedApp = null; |
| 3859 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3860 | mKeyWaiter.tickle(); |
| 3861 | } |
| 3862 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3863 | 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] | 3864 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3865 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | if (!delayed && wtoken != null) { |
| 3867 | wtoken.updateReportedVisibilityLocked(); |
| 3868 | } |
| 3869 | } |
| 3870 | Binder.restoreCallingIdentity(origId); |
| 3871 | |
| 3872 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3873 | 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] | 3874 | + startingToken + ": app token removed"); |
| 3875 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3876 | mH.sendMessage(m); |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3881 | final int NW = token.windows.size(); |
| 3882 | for (int i=0; i<NW; i++) { |
| 3883 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3884 | 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] | 3885 | mWindows.remove(win); |
| 3886 | int j = win.mChildWindows.size(); |
| 3887 | while (j > 0) { |
| 3888 | j--; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3889 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3890 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3891 | "Tmp removing child window " + cwin); |
| 3892 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3893 | } |
| 3894 | } |
| 3895 | return NW > 0; |
| 3896 | } |
| 3897 | |
| 3898 | void dumpAppTokensLocked() { |
| 3899 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3900 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | } |
| 3902 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3903 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3904 | void dumpWindowsLocked() { |
| 3905 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3906 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3907 | } |
| 3908 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3909 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3910 | private int findWindowOffsetLocked(int tokenPos) { |
| 3911 | final int NW = mWindows.size(); |
| 3912 | |
| 3913 | if (tokenPos >= mAppTokens.size()) { |
| 3914 | int i = NW; |
| 3915 | while (i > 0) { |
| 3916 | i--; |
| 3917 | WindowState win = (WindowState)mWindows.get(i); |
| 3918 | if (win.getAppToken() != null) { |
| 3919 | return i+1; |
| 3920 | } |
| 3921 | } |
| 3922 | } |
| 3923 | |
| 3924 | while (tokenPos > 0) { |
| 3925 | // Find the first app token below the new position that has |
| 3926 | // a window displayed. |
| 3927 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3928 | 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] | 3929 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3930 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3931 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3932 | "Skipping token -- currently sending to bottom"); |
| 3933 | tokenPos--; |
| 3934 | continue; |
| 3935 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | int i = wtoken.windows.size(); |
| 3937 | while (i > 0) { |
| 3938 | i--; |
| 3939 | WindowState win = wtoken.windows.get(i); |
| 3940 | int j = win.mChildWindows.size(); |
| 3941 | while (j > 0) { |
| 3942 | j--; |
| 3943 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3944 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | for (int pos=NW-1; pos>=0; pos--) { |
| 3946 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3947 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | "Found child win @" + (pos+1)); |
| 3949 | return pos+1; |
| 3950 | } |
| 3951 | } |
| 3952 | } |
| 3953 | } |
| 3954 | for (int pos=NW-1; pos>=0; pos--) { |
| 3955 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3956 | 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] | 3957 | return pos+1; |
| 3958 | } |
| 3959 | } |
| 3960 | } |
| 3961 | tokenPos--; |
| 3962 | } |
| 3963 | |
| 3964 | return 0; |
| 3965 | } |
| 3966 | |
| 3967 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3968 | final int NCW = win.mChildWindows.size(); |
| 3969 | boolean added = false; |
| 3970 | for (int j=0; j<NCW; j++) { |
| 3971 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3972 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3973 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3974 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3975 | mWindows.add(index, win); |
| 3976 | index++; |
| 3977 | added = true; |
| 3978 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3979 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3980 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3981 | mWindows.add(index, cwin); |
| 3982 | index++; |
| 3983 | } |
| 3984 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3985 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3986 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | mWindows.add(index, win); |
| 3988 | index++; |
| 3989 | } |
| 3990 | return index; |
| 3991 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3993 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3994 | final int NW = token.windows.size(); |
| 3995 | for (int i=0; i<NW; i++) { |
| 3996 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3997 | } |
| 3998 | return index; |
| 3999 | } |
| 4000 | |
| 4001 | public void moveAppToken(int index, IBinder token) { |
| 4002 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4003 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4004 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4008 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4010 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4011 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4012 | 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] | 4013 | + token + " (" + wtoken + ")"); |
| 4014 | return; |
| 4015 | } |
| 4016 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4017 | 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] | 4018 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4020 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4021 | 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] | 4022 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4023 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4024 | 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] | 4025 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4026 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4027 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4029 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | mLayoutNeeded = true; |
| 4031 | performLayoutAndPlaceSurfacesLocked(); |
| 4032 | } |
| 4033 | Binder.restoreCallingIdentity(origId); |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4038 | // XXX This should be done more efficiently! |
| 4039 | // (take advantage of the fact that both lists should be |
| 4040 | // ordered in the same way.) |
| 4041 | int N = tokens.size(); |
| 4042 | for (int i=0; i<N; i++) { |
| 4043 | IBinder token = tokens.get(i); |
| 4044 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4045 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4046 | 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] | 4047 | + token + " (" + wtoken + ")"); |
| 4048 | i--; |
| 4049 | N--; |
| 4050 | } |
| 4051 | } |
| 4052 | } |
| 4053 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4054 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4055 | boolean updateFocusAndLayout) { |
| 4056 | // First remove all of the windows from the list. |
| 4057 | tmpRemoveAppWindowsLocked(wtoken); |
| 4058 | |
| 4059 | // Where to start adding? |
| 4060 | int pos = findWindowOffsetLocked(tokenPos); |
| 4061 | |
| 4062 | // And now add them back at the correct place. |
| 4063 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4064 | |
| 4065 | if (updateFocusAndLayout) { |
| 4066 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4067 | assignLayersLocked(); |
| 4068 | } |
| 4069 | mLayoutNeeded = true; |
| 4070 | performLayoutAndPlaceSurfacesLocked(); |
| 4071 | } |
| 4072 | } |
| 4073 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4075 | // First remove all of the windows from the list. |
| 4076 | final int N = tokens.size(); |
| 4077 | int i; |
| 4078 | for (i=0; i<N; i++) { |
| 4079 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4080 | if (token != null) { |
| 4081 | tmpRemoveAppWindowsLocked(token); |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | // Where to start adding? |
| 4086 | int pos = findWindowOffsetLocked(tokenPos); |
| 4087 | |
| 4088 | // And now add them back at the correct place. |
| 4089 | for (i=0; i<N; i++) { |
| 4090 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4091 | if (token != null) { |
| 4092 | pos = reAddAppWindowsLocked(pos, token); |
| 4093 | } |
| 4094 | } |
| 4095 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4096 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4097 | assignLayersLocked(); |
| 4098 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | mLayoutNeeded = true; |
| 4100 | performLayoutAndPlaceSurfacesLocked(); |
| 4101 | |
| 4102 | //dump(); |
| 4103 | } |
| 4104 | |
| 4105 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4106 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4107 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4108 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | final long origId = Binder.clearCallingIdentity(); |
| 4112 | synchronized(mWindowMap) { |
| 4113 | removeAppTokensLocked(tokens); |
| 4114 | final int N = tokens.size(); |
| 4115 | for (int i=0; i<N; i++) { |
| 4116 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4117 | if (wt != null) { |
| 4118 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4119 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4120 | mToTopApps.remove(wt); |
| 4121 | mToBottomApps.remove(wt); |
| 4122 | mToTopApps.add(wt); |
| 4123 | wt.sendingToBottom = false; |
| 4124 | wt.sendingToTop = true; |
| 4125 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4126 | } |
| 4127 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4128 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4129 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4130 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4131 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | } |
| 4133 | Binder.restoreCallingIdentity(origId); |
| 4134 | } |
| 4135 | |
| 4136 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4137 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4138 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4139 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | final long origId = Binder.clearCallingIdentity(); |
| 4143 | synchronized(mWindowMap) { |
| 4144 | removeAppTokensLocked(tokens); |
| 4145 | final int N = tokens.size(); |
| 4146 | int pos = 0; |
| 4147 | for (int i=0; i<N; i++) { |
| 4148 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4149 | if (wt != null) { |
| 4150 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4151 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4152 | mToTopApps.remove(wt); |
| 4153 | mToBottomApps.remove(wt); |
| 4154 | mToBottomApps.add(i, wt); |
| 4155 | wt.sendingToTop = false; |
| 4156 | wt.sendingToBottom = true; |
| 4157 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4158 | pos++; |
| 4159 | } |
| 4160 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4161 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4162 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4163 | moveAppWindowsLocked(tokens, 0); |
| 4164 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | } |
| 4166 | Binder.restoreCallingIdentity(origId); |
| 4167 | } |
| 4168 | |
| 4169 | // ------------------------------------------------------------- |
| 4170 | // Misc IWindowSession methods |
| 4171 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4172 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4174 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4175 | != PackageManager.PERMISSION_GRANTED) { |
| 4176 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4177 | } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4178 | synchronized (mKeyguardTokenWatcher) { |
| 4179 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4180 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4184 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | != PackageManager.PERMISSION_GRANTED) { |
| 4186 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4187 | } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4188 | synchronized (mKeyguardTokenWatcher) { |
| 4189 | mKeyguardTokenWatcher.release(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4190 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4191 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4192 | // If we are the last one to reenable the keyguard wait until |
| 4193 | // we have actaully finished reenabling until returning. |
| 4194 | // It is possible that reenableKeyguard() can be called before |
| 4195 | // the previous disableKeyguard() is handled, in which case |
| 4196 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4197 | // be called. In that case mKeyguardDisabled will be false here |
| 4198 | // and we have nothing to wait for. |
| 4199 | while (mKeyguardDisabled) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | try { |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4201 | mKeyguardTokenWatcher.wait(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | } catch (InterruptedException e) { |
| 4203 | Thread.currentThread().interrupt(); |
| 4204 | } |
| 4205 | } |
| 4206 | } |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | /** |
| 4211 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4212 | */ |
| 4213 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4214 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4215 | != PackageManager.PERMISSION_GRANTED) { |
| 4216 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4217 | } |
| 4218 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4219 | public void onKeyguardExitResult(boolean success) { |
| 4220 | try { |
| 4221 | callback.onKeyguardExitResult(success); |
| 4222 | } catch (RemoteException e) { |
| 4223 | // Client has died, we don't care. |
| 4224 | } |
| 4225 | } |
| 4226 | }); |
| 4227 | } |
| 4228 | |
| 4229 | public boolean inKeyguardRestrictedInputMode() { |
| 4230 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4231 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4232 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4233 | public void closeSystemDialogs(String reason) { |
| 4234 | synchronized(mWindowMap) { |
| 4235 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4236 | WindowState w = (WindowState)mWindows.get(i); |
| 4237 | if (w.mSurface != null) { |
| 4238 | try { |
| 4239 | w.mClient.closeSystemDialogs(reason); |
| 4240 | } catch (RemoteException e) { |
| 4241 | } |
| 4242 | } |
| 4243 | } |
| 4244 | } |
| 4245 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | static float fixScale(float scale) { |
| 4248 | if (scale < 0) scale = 0; |
| 4249 | else if (scale > 20) scale = 20; |
| 4250 | return Math.abs(scale); |
| 4251 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4253 | public void setAnimationScale(int which, float scale) { |
| 4254 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4255 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4256 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | if (scale < 0) scale = 0; |
| 4260 | else if (scale > 20) scale = 20; |
| 4261 | scale = Math.abs(scale); |
| 4262 | switch (which) { |
| 4263 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4264 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4267 | // Persist setting |
| 4268 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4269 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | public void setAnimationScales(float[] scales) { |
| 4272 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4273 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4274 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | if (scales != null) { |
| 4278 | if (scales.length >= 1) { |
| 4279 | mWindowAnimationScale = fixScale(scales[0]); |
| 4280 | } |
| 4281 | if (scales.length >= 2) { |
| 4282 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4283 | } |
| 4284 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | // Persist setting |
| 4287 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4288 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4289 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | public float getAnimationScale(int which) { |
| 4291 | switch (which) { |
| 4292 | case 0: return mWindowAnimationScale; |
| 4293 | case 1: return mTransitionAnimationScale; |
| 4294 | } |
| 4295 | return 0; |
| 4296 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4297 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | public float[] getAnimationScales() { |
| 4299 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4300 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | public int getSwitchState(int sw) { |
| 4303 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4304 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4305 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | } |
| 4307 | return KeyInputQueue.getSwitchState(sw); |
| 4308 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4311 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4312 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4313 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4314 | } |
| 4315 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4316 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | public int getScancodeState(int sw) { |
| 4319 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4320 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4321 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4322 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4323 | return mQueue.getScancodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4327 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4328 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4329 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4330 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4331 | return mQueue.getScancodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4333 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4334 | public int getTrackballScancodeState(int sw) { |
| 4335 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4336 | "getTrackballScancodeState()")) { |
| 4337 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4338 | } |
| 4339 | return mQueue.getTrackballScancodeState(sw); |
| 4340 | } |
| 4341 | |
| 4342 | public int getDPadScancodeState(int sw) { |
| 4343 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4344 | "getDPadScancodeState()")) { |
| 4345 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4346 | } |
| 4347 | return mQueue.getDPadScancodeState(sw); |
| 4348 | } |
| 4349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4350 | public int getKeycodeState(int sw) { |
| 4351 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4352 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4353 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4354 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4355 | return mQueue.getKeycodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4356 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4359 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4360 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4361 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4362 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4363 | return mQueue.getKeycodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4364 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4365 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4366 | public int getTrackballKeycodeState(int sw) { |
| 4367 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4368 | "getTrackballKeycodeState()")) { |
| 4369 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4370 | } |
| 4371 | return mQueue.getTrackballKeycodeState(sw); |
| 4372 | } |
| 4373 | |
| 4374 | public int getDPadKeycodeState(int sw) { |
| 4375 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4376 | "getDPadKeycodeState()")) { |
| 4377 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4378 | } |
| 4379 | return mQueue.getDPadKeycodeState(sw); |
| 4380 | } |
| 4381 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4382 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 4383 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4384 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | public void enableScreenAfterBoot() { |
| 4387 | synchronized(mWindowMap) { |
| 4388 | if (mSystemBooted) { |
| 4389 | return; |
| 4390 | } |
| 4391 | mSystemBooted = true; |
| 4392 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4393 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | performEnableScreen(); |
| 4395 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4396 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4397 | public void enableScreenIfNeededLocked() { |
| 4398 | if (mDisplayEnabled) { |
| 4399 | return; |
| 4400 | } |
| 4401 | if (!mSystemBooted) { |
| 4402 | return; |
| 4403 | } |
| 4404 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4405 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4406 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | public void performEnableScreen() { |
| 4408 | synchronized(mWindowMap) { |
| 4409 | if (mDisplayEnabled) { |
| 4410 | return; |
| 4411 | } |
| 4412 | if (!mSystemBooted) { |
| 4413 | return; |
| 4414 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4415 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | // Don't enable the screen until all existing windows |
| 4417 | // have been drawn. |
| 4418 | final int N = mWindows.size(); |
| 4419 | for (int i=0; i<N; i++) { |
| 4420 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4421 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4422 | return; |
| 4423 | } |
| 4424 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4426 | mDisplayEnabled = true; |
| 4427 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4428 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4429 | StringWriter sw = new StringWriter(); |
| 4430 | PrintWriter pw = new PrintWriter(sw); |
| 4431 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4432 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | } |
| 4434 | try { |
| 4435 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4436 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4437 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | Parcel data = Parcel.obtain(); |
| 4439 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4440 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4441 | data, null, 0); |
| 4442 | data.recycle(); |
| 4443 | } |
| 4444 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4445 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4446 | } |
| 4447 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4448 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4449 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4452 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4453 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4454 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | public void setInTouchMode(boolean mode) { |
| 4457 | synchronized(mWindowMap) { |
| 4458 | mInTouchMode = mode; |
| 4459 | } |
| 4460 | } |
| 4461 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4462 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4463 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4465 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4466 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | } |
| 4468 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4469 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4470 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4471 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4472 | public void setRotationUnchecked(int rotation, |
| 4473 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4474 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4476 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4477 | long origId = Binder.clearCallingIdentity(); |
| 4478 | boolean changed; |
| 4479 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4480 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4481 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4482 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4483 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | sendNewConfiguration(); |
| 4485 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4486 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | Binder.restoreCallingIdentity(origId); |
| 4488 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4489 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4490 | /** |
| 4491 | * Apply a new rotation to the screen, respecting the requests of |
| 4492 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4493 | * re-evaluate the desired rotation. |
| 4494 | * |
| 4495 | * Returns null if the rotation has been changed. In this case YOU |
| 4496 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4497 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4498 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4499 | boolean changed; |
| 4500 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4501 | rotation = mRequestedRotation; |
| 4502 | } else { |
| 4503 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4504 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4506 | 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] | 4507 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4508 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4509 | 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] | 4510 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4511 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4512 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4513 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4514 | "Rotation changed to " + rotation |
| 4515 | + " from " + mRotation |
| 4516 | + " (forceApp=" + mForcedAppOrientation |
| 4517 | + ", req=" + mRequestedRotation + ")"); |
| 4518 | mRotation = rotation; |
| 4519 | mWindowsFreezingScreen = true; |
| 4520 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4521 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4522 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4523 | mWaitingForConfig = true; |
| 4524 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4525 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4526 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | mQueue.setOrientation(rotation); |
| 4528 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4529 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4530 | } |
| 4531 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4532 | WindowState w = (WindowState)mWindows.get(i); |
| 4533 | if (w.mSurface != null) { |
| 4534 | w.mOrientationChanging = true; |
| 4535 | } |
| 4536 | } |
| 4537 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4538 | try { |
| 4539 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4540 | } catch (RemoteException e) { |
| 4541 | } |
| 4542 | } |
| 4543 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4545 | return changed; |
| 4546 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4547 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4548 | public int getRotation() { |
| 4549 | return mRotation; |
| 4550 | } |
| 4551 | |
| 4552 | public int watchRotation(IRotationWatcher watcher) { |
| 4553 | final IBinder watcherBinder = watcher.asBinder(); |
| 4554 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4555 | public void binderDied() { |
| 4556 | synchronized (mWindowMap) { |
| 4557 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4558 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4559 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4560 | if (removed != null) { |
| 4561 | removed.asBinder().unlinkToDeath(this, 0); |
| 4562 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4563 | i--; |
| 4564 | } |
| 4565 | } |
| 4566 | } |
| 4567 | } |
| 4568 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4569 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4570 | synchronized (mWindowMap) { |
| 4571 | try { |
| 4572 | watcher.asBinder().linkToDeath(dr, 0); |
| 4573 | mRotationWatchers.add(watcher); |
| 4574 | } catch (RemoteException e) { |
| 4575 | // Client died, no cleanup needed. |
| 4576 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4578 | return mRotation; |
| 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | /** |
| 4583 | * Starts the view server on the specified port. |
| 4584 | * |
| 4585 | * @param port The port to listener to. |
| 4586 | * |
| 4587 | * @return True if the server was successfully started, false otherwise. |
| 4588 | * |
| 4589 | * @see com.android.server.ViewServer |
| 4590 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4591 | */ |
| 4592 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4593 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | return false; |
| 4595 | } |
| 4596 | |
| 4597 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4598 | return false; |
| 4599 | } |
| 4600 | |
| 4601 | if (port < 1024) { |
| 4602 | return false; |
| 4603 | } |
| 4604 | |
| 4605 | if (mViewServer != null) { |
| 4606 | if (!mViewServer.isRunning()) { |
| 4607 | try { |
| 4608 | return mViewServer.start(); |
| 4609 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4610 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4611 | } |
| 4612 | } |
| 4613 | return false; |
| 4614 | } |
| 4615 | |
| 4616 | try { |
| 4617 | mViewServer = new ViewServer(this, port); |
| 4618 | return mViewServer.start(); |
| 4619 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4620 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4621 | } |
| 4622 | return false; |
| 4623 | } |
| 4624 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4625 | private boolean isSystemSecure() { |
| 4626 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4627 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4628 | } |
| 4629 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4630 | /** |
| 4631 | * Stops the view server if it exists. |
| 4632 | * |
| 4633 | * @return True if the server stopped, false if it wasn't started or |
| 4634 | * couldn't be stopped. |
| 4635 | * |
| 4636 | * @see com.android.server.ViewServer |
| 4637 | */ |
| 4638 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4639 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4640 | return false; |
| 4641 | } |
| 4642 | |
| 4643 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4644 | return false; |
| 4645 | } |
| 4646 | |
| 4647 | if (mViewServer != null) { |
| 4648 | return mViewServer.stop(); |
| 4649 | } |
| 4650 | return false; |
| 4651 | } |
| 4652 | |
| 4653 | /** |
| 4654 | * Indicates whether the view server is running. |
| 4655 | * |
| 4656 | * @return True if the server is running, false otherwise. |
| 4657 | * |
| 4658 | * @see com.android.server.ViewServer |
| 4659 | */ |
| 4660 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4661 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4662 | return false; |
| 4663 | } |
| 4664 | |
| 4665 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4666 | return false; |
| 4667 | } |
| 4668 | |
| 4669 | return mViewServer != null && mViewServer.isRunning(); |
| 4670 | } |
| 4671 | |
| 4672 | /** |
| 4673 | * Lists all availble windows in the system. The listing is written in the |
| 4674 | * specified Socket's output stream with the following syntax: |
| 4675 | * windowHashCodeInHexadecimal windowName |
| 4676 | * Each line of the ouput represents a different window. |
| 4677 | * |
| 4678 | * @param client The remote client to send the listing to. |
| 4679 | * @return False if an error occured, true otherwise. |
| 4680 | */ |
| 4681 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4682 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | return false; |
| 4684 | } |
| 4685 | |
| 4686 | boolean result = true; |
| 4687 | |
| 4688 | Object[] windows; |
| 4689 | synchronized (mWindowMap) { |
| 4690 | windows = new Object[mWindows.size()]; |
| 4691 | //noinspection unchecked |
| 4692 | windows = mWindows.toArray(windows); |
| 4693 | } |
| 4694 | |
| 4695 | BufferedWriter out = null; |
| 4696 | |
| 4697 | // Any uncaught exception will crash the system process |
| 4698 | try { |
| 4699 | OutputStream clientStream = client.getOutputStream(); |
| 4700 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4701 | |
| 4702 | final int count = windows.length; |
| 4703 | for (int i = 0; i < count; i++) { |
| 4704 | final WindowState w = (WindowState) windows[i]; |
| 4705 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4706 | out.write(' '); |
| 4707 | out.append(w.mAttrs.getTitle()); |
| 4708 | out.write('\n'); |
| 4709 | } |
| 4710 | |
| 4711 | out.write("DONE.\n"); |
| 4712 | out.flush(); |
| 4713 | } catch (Exception e) { |
| 4714 | result = false; |
| 4715 | } finally { |
| 4716 | if (out != null) { |
| 4717 | try { |
| 4718 | out.close(); |
| 4719 | } catch (IOException e) { |
| 4720 | result = false; |
| 4721 | } |
| 4722 | } |
| 4723 | } |
| 4724 | |
| 4725 | return result; |
| 4726 | } |
| 4727 | |
| 4728 | /** |
| 4729 | * Sends a command to a target window. The result of the command, if any, will be |
| 4730 | * written in the output stream of the specified socket. |
| 4731 | * |
| 4732 | * The parameters must follow this syntax: |
| 4733 | * windowHashcode extra |
| 4734 | * |
| 4735 | * Where XX is the length in characeters of the windowTitle. |
| 4736 | * |
| 4737 | * The first parameter is the target window. The window with the specified hashcode |
| 4738 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4739 | * will be delivered to the target window and as parameters to the command itself. |
| 4740 | * |
| 4741 | * @param client The remote client to sent the result, if any, to. |
| 4742 | * @param command The command to execute. |
| 4743 | * @param parameters The command parameters. |
| 4744 | * |
| 4745 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4746 | * not indicate whether the command itself was successful. |
| 4747 | */ |
| 4748 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4749 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | return false; |
| 4751 | } |
| 4752 | |
| 4753 | boolean success = true; |
| 4754 | Parcel data = null; |
| 4755 | Parcel reply = null; |
| 4756 | |
| 4757 | // Any uncaught exception will crash the system process |
| 4758 | try { |
| 4759 | // Find the hashcode of the window |
| 4760 | int index = parameters.indexOf(' '); |
| 4761 | if (index == -1) { |
| 4762 | index = parameters.length(); |
| 4763 | } |
| 4764 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4765 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4766 | |
| 4767 | // Extract the command's parameter after the window description |
| 4768 | if (index < parameters.length()) { |
| 4769 | parameters = parameters.substring(index + 1); |
| 4770 | } else { |
| 4771 | parameters = ""; |
| 4772 | } |
| 4773 | |
| 4774 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4775 | if (window == null) { |
| 4776 | return false; |
| 4777 | } |
| 4778 | |
| 4779 | data = Parcel.obtain(); |
| 4780 | data.writeInterfaceToken("android.view.IWindow"); |
| 4781 | data.writeString(command); |
| 4782 | data.writeString(parameters); |
| 4783 | data.writeInt(1); |
| 4784 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4785 | |
| 4786 | reply = Parcel.obtain(); |
| 4787 | |
| 4788 | final IBinder binder = window.mClient.asBinder(); |
| 4789 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4790 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4791 | |
| 4792 | reply.readException(); |
| 4793 | |
| 4794 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4795 | 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] | 4796 | success = false; |
| 4797 | } finally { |
| 4798 | if (data != null) { |
| 4799 | data.recycle(); |
| 4800 | } |
| 4801 | if (reply != null) { |
| 4802 | reply.recycle(); |
| 4803 | } |
| 4804 | } |
| 4805 | |
| 4806 | return success; |
| 4807 | } |
| 4808 | |
| 4809 | private WindowState findWindow(int hashCode) { |
| 4810 | if (hashCode == -1) { |
| 4811 | return getFocusedWindow(); |
| 4812 | } |
| 4813 | |
| 4814 | synchronized (mWindowMap) { |
| 4815 | final ArrayList windows = mWindows; |
| 4816 | final int count = windows.size(); |
| 4817 | |
| 4818 | for (int i = 0; i < count; i++) { |
| 4819 | WindowState w = (WindowState) windows.get(i); |
| 4820 | if (System.identityHashCode(w) == hashCode) { |
| 4821 | return w; |
| 4822 | } |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | return null; |
| 4827 | } |
| 4828 | |
| 4829 | /* |
| 4830 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4831 | * that to config-changed listeners if appropriate. |
| 4832 | */ |
| 4833 | void sendNewConfiguration() { |
| 4834 | try { |
| 4835 | mActivityManager.updateConfiguration(null); |
| 4836 | } catch (RemoteException e) { |
| 4837 | } |
| 4838 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4840 | public Configuration computeNewConfiguration() { |
| 4841 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4842 | return computeNewConfigurationLocked(); |
| 4843 | } |
| 4844 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4845 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4846 | Configuration computeNewConfigurationLocked() { |
| 4847 | Configuration config = new Configuration(); |
| 4848 | if (!computeNewConfigurationLocked(config)) { |
| 4849 | return null; |
| 4850 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4851 | return config; |
| 4852 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4853 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4854 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4855 | if (mDisplay == null) { |
| 4856 | return false; |
| 4857 | } |
| 4858 | mQueue.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 4859 | |
| 4860 | // Use the effective "visual" dimensions based on current rotation |
| 4861 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 4862 | || mRotation == Surface.ROTATION_270); |
| 4863 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 4864 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 4865 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4866 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4867 | if (dw < dh) { |
| 4868 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4869 | } else if (dw > dh) { |
| 4870 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4871 | } |
| 4872 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4873 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4874 | DisplayMetrics dm = new DisplayMetrics(); |
| 4875 | mDisplay.getMetrics(dm); |
| 4876 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4877 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4878 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4879 | // Note we only do this once because at this point we don't |
| 4880 | // expect the screen to change in this way at runtime, and want |
| 4881 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4882 | int longSize = dw; |
| 4883 | int shortSize = dh; |
| 4884 | if (longSize < shortSize) { |
| 4885 | int tmp = longSize; |
| 4886 | longSize = shortSize; |
| 4887 | shortSize = tmp; |
| 4888 | } |
| 4889 | longSize = (int)(longSize/dm.density); |
| 4890 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4891 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4892 | // These semi-magic numbers define our compatibility modes for |
| 4893 | // applications with different screens. Don't change unless you |
| 4894 | // make sure to test lots and lots of apps! |
| 4895 | if (longSize < 470) { |
| 4896 | // This is shorter than an HVGA normal density screen (which |
| 4897 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4898 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4899 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4900 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 4901 | // What size is this screen screen? |
| 4902 | if (longSize >= 800 && shortSize >= 600) { |
| 4903 | // SVGA or larger screens at medium density are the point |
| 4904 | // at which we consider it to be an extra large screen. |
| 4905 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 4906 | } else if (longSize >= 640 && shortSize >= 480) { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4907 | // VGA or larger screens at medium density are the point |
| 4908 | // at which we consider it to be a large screen. |
| 4909 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4910 | } else { |
| 4911 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4912 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4913 | // If this screen is wider than normal HVGA, or taller |
| 4914 | // than FWVGA, then for old apps we want to run in size |
| 4915 | // compatibility mode. |
| 4916 | if (shortSize > 321 || longSize > 570) { |
| 4917 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4918 | } |
| 4919 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4920 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4921 | // Is this a long screen? |
| 4922 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4923 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4924 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4925 | } else { |
| 4926 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4927 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4928 | } |
| 4929 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4930 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4931 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4932 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4933 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4934 | mPolicy.adjustConfigurationLw(config); |
| 4935 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4936 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4937 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4938 | // ------------------------------------------------------------- |
| 4939 | // Input Events and Focus Management |
| 4940 | // ------------------------------------------------------------- |
| 4941 | |
| 4942 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4943 | long curTime = SystemClock.uptimeMillis(); |
| 4944 | |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4945 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4946 | if (mLastTouchEventType == eventType && |
| 4947 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4948 | return; |
| 4949 | } |
| 4950 | mLastUserActivityCallTime = curTime; |
| 4951 | mLastTouchEventType = eventType; |
| 4952 | } |
| 4953 | |
| 4954 | if (targetWin == null |
| 4955 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4956 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4957 | } |
| 4958 | } |
| 4959 | |
| 4960 | // tells if it's a cheek event or not -- this function is stateful |
| 4961 | private static final int EVENT_NONE = 0; |
| 4962 | private static final int EVENT_UNKNOWN = 0; |
| 4963 | private static final int EVENT_CHEEK = 0; |
| 4964 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4965 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4966 | private int mEventState = EVENT_NONE; |
| 4967 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4969 | private int eventType(MotionEvent ev) { |
| 4970 | float size = ev.getSize(); |
| 4971 | switch (ev.getAction()) { |
| 4972 | case MotionEvent.ACTION_DOWN: |
| 4973 | mEventSize = size; |
| 4974 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4975 | case MotionEvent.ACTION_UP: |
| 4976 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4977 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4978 | case MotionEvent.ACTION_MOVE: |
| 4979 | final int N = ev.getHistorySize(); |
| 4980 | if (size > mEventSize) mEventSize = size; |
| 4981 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4982 | for (int i=0; i<N; i++) { |
| 4983 | size = ev.getHistoricalSize(i); |
| 4984 | if (size > mEventSize) mEventSize = size; |
| 4985 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4986 | } |
| 4987 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4988 | return TOUCH_EVENT; |
| 4989 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4990 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4991 | } |
| 4992 | default: |
| 4993 | // not good |
| 4994 | return OTHER_EVENT; |
| 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | /** |
| 4999 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5000 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5001 | private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5002 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5003 | "dispatchPointer " + ev); |
| 5004 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5005 | if (MEASURE_LATENCY) { |
| 5006 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 5007 | } |
| 5008 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5009 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5010 | ev, true, false, pid, uid); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5011 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5012 | if (MEASURE_LATENCY) { |
| 5013 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 5014 | } |
| 5015 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5016 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5018 | if (action == MotionEvent.ACTION_UP) { |
| 5019 | // let go of our target |
| 5020 | mKeyWaiter.mMotionTarget = null; |
| 5021 | mPowerManager.logPointerUpEvent(); |
| 5022 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 5023 | mPowerManager.logPointerDownEvent(); |
| 5024 | } |
| 5025 | |
| 5026 | if (targetObj == null) { |
| 5027 | // In this case we are either dropping the event, or have received |
| 5028 | // a move or up without a down. It is common to receive move |
| 5029 | // events in such a way, since this means the user is moving the |
| 5030 | // pointer without actually pressing down. All other cases should |
| 5031 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5032 | if (action != MotionEvent.ACTION_MOVE) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5033 | 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] | 5034 | } |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5035 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5036 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5037 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5038 | if (qev != null) { |
| 5039 | mQueue.recycleEvent(qev); |
| 5040 | } |
| 5041 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5042 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5043 | } |
| 5044 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5045 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5046 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5047 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5048 | if (qev != null) { |
| 5049 | mQueue.recycleEvent(qev); |
| 5050 | } |
| 5051 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5052 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5053 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5054 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5055 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5057 | final long eventTime = ev.getEventTime(); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5058 | final long eventTimeNano = ev.getEventTimeNano(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5059 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5060 | //Slog.i(TAG, "Sending " + ev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | |
| 5062 | if (uid != 0 && uid != target.mSession.mUid) { |
| 5063 | if (mContext.checkPermission( |
| 5064 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5065 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5066 | 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] | 5067 | + pid + " uid " + uid + " to window " + target |
| 5068 | + " owned by uid " + target.mSession.mUid); |
| 5069 | if (qev != null) { |
| 5070 | mQueue.recycleEvent(qev); |
| 5071 | } |
| 5072 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5073 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5074 | } |
| 5075 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5076 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5077 | if (MEASURE_LATENCY) { |
| 5078 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5079 | } |
| 5080 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5081 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5082 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 5083 | //target wants to ignore fat touch events |
| 5084 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 5085 | //explicit flag to return without processing event further |
| 5086 | boolean returnFlag = false; |
| 5087 | if((action == MotionEvent.ACTION_DOWN)) { |
| 5088 | mFatTouch = false; |
| 5089 | if(cheekPress) { |
| 5090 | mFatTouch = true; |
| 5091 | returnFlag = true; |
| 5092 | } |
| 5093 | } else { |
| 5094 | if(action == MotionEvent.ACTION_UP) { |
| 5095 | if(mFatTouch) { |
| 5096 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 5097 | mFatTouch = false; |
| 5098 | returnFlag = true; |
| 5099 | } else if(cheekPress) { |
| 5100 | //cancel the earlier event |
| 5101 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5102 | action = MotionEvent.ACTION_CANCEL; |
| 5103 | } |
| 5104 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 5105 | if(mFatTouch) { |
| 5106 | //two cases here |
| 5107 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5108 | //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] | 5109 | returnFlag = true; |
| 5110 | } else if(cheekPress) { |
| 5111 | //valid down followed by invalid moves |
| 5112 | //an invalid move have to cancel earlier action |
| 5113 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5114 | action = MotionEvent.ACTION_CANCEL; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5115 | 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] | 5116 | //note that the subsequent invalid moves will not get here |
| 5117 | mFatTouch = true; |
| 5118 | } |
| 5119 | } |
| 5120 | } //else if action |
| 5121 | if(returnFlag) { |
| 5122 | //recycle que, ev |
| 5123 | if (qev != null) { |
| 5124 | mQueue.recycleEvent(qev); |
| 5125 | } |
| 5126 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5127 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5128 | } |
| 5129 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5130 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 5131 | // Enable this for testing the "right" value |
| 5132 | if (false && action == MotionEvent.ACTION_DOWN) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5133 | int max_events_per_sec = 35; |
| 5134 | try { |
| 5135 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 5136 | .get("windowsmgr.max_events_per_sec")); |
| 5137 | if (max_events_per_sec < 1) { |
| 5138 | max_events_per_sec = 35; |
| 5139 | } |
| 5140 | } catch (NumberFormatException e) { |
| 5141 | } |
| 5142 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 5143 | } |
| 5144 | |
| 5145 | /* |
| 5146 | * Throttle events to minimize CPU usage when there's a flood of events |
| 5147 | * e.g. constant contact with the screen |
| 5148 | */ |
| 5149 | if (action == MotionEvent.ACTION_MOVE) { |
| 5150 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 5151 | long now = SystemClock.uptimeMillis(); |
| 5152 | if (now < nextEventTime) { |
| 5153 | try { |
| 5154 | Thread.sleep(nextEventTime - now); |
| 5155 | } catch (InterruptedException e) { |
| 5156 | } |
| 5157 | mLastTouchEventTime = nextEventTime; |
| 5158 | } else { |
| 5159 | mLastTouchEventTime = now; |
| 5160 | } |
| 5161 | } |
| 5162 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5163 | if (MEASURE_LATENCY) { |
| 5164 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5165 | } |
| 5166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5167 | synchronized(mWindowMap) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5168 | if (!target.isVisibleLw()) { |
| 5169 | // During this motion dispatch, the target window has become |
| 5170 | // invisible. |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5171 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5172 | if (qev != null) { |
| 5173 | mQueue.recycleEvent(qev); |
| 5174 | } |
| 5175 | ev.recycle(); |
| 5176 | return INJECT_SUCCEEDED; |
| 5177 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5178 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 5180 | mKeyWaiter.bindTargetWindowLocked(target, |
| 5181 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 5182 | ev = null; |
| 5183 | } else { |
| 5184 | if (action == MotionEvent.ACTION_DOWN) { |
| 5185 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 5186 | if (out != null) { |
| 5187 | MotionEvent oev = MotionEvent.obtain(ev); |
| 5188 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 5189 | do { |
| 5190 | final Rect frame = out.mFrame; |
| 5191 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5192 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5193 | out.mClient.dispatchPointer(oev, eventTime, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5194 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5195 | 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] | 5196 | } |
| 5197 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 5198 | out = out.mNextOutsideTouch; |
| 5199 | } while (out != null); |
| 5200 | mKeyWaiter.mOutsideTouchTargets = null; |
| 5201 | } |
| 5202 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5203 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5204 | dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5205 | |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5206 | final Rect frame = target.mFrame; |
| 5207 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5208 | mKeyWaiter.bindTargetWindowLocked(target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5209 | } |
| 5210 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5212 | // finally offset the event to the target's coordinate system and |
| 5213 | // dispatch the event. |
| 5214 | try { |
| 5215 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5216 | Slog.v(TAG, "Delivering pointer " + qev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5217 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5218 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5219 | if (MEASURE_LATENCY) { |
| 5220 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5221 | } |
| 5222 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5223 | target.mClient.dispatchPointer(ev, eventTime, true); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5224 | |
| 5225 | if (MEASURE_LATENCY) { |
| 5226 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5227 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5228 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5230 | Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5231 | mKeyWaiter.mMotionTarget = null; |
| 5232 | try { |
| 5233 | removeWindow(target.mSession, target.mClient); |
| 5234 | } catch (java.util.NoSuchElementException ex) { |
| 5235 | // This will happen if the window has already been |
| 5236 | // removed. |
| 5237 | } |
| 5238 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5239 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5240 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5242 | /** |
| 5243 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5244 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5245 | private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5246 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5247 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5249 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5250 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5251 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5252 | Slog.w(TAG, "No focus window, dropping trackball: " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5253 | if (qev != null) { |
| 5254 | mQueue.recycleEvent(qev); |
| 5255 | } |
| 5256 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5257 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5258 | } |
| 5259 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 5260 | if (qev != null) { |
| 5261 | mQueue.recycleEvent(qev); |
| 5262 | } |
| 5263 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5264 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5267 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5269 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5270 | if (mContext.checkPermission( |
| 5271 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5272 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5273 | 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] | 5274 | + pid + " uid " + uid + " to window " + focus |
| 5275 | + " owned by uid " + focus.mSession.mUid); |
| 5276 | if (qev != null) { |
| 5277 | mQueue.recycleEvent(qev); |
| 5278 | } |
| 5279 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5280 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | } |
| 5282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5284 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5286 | synchronized(mWindowMap) { |
| 5287 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5288 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5289 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5290 | // We don't deliver movement events to the client, we hold |
| 5291 | // them and wait for them to call back. |
| 5292 | ev = null; |
| 5293 | } else { |
| 5294 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5295 | } |
| 5296 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5297 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5299 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5300 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5301 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5302 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5303 | try { |
| 5304 | removeWindow(focus.mSession, focus.mClient); |
| 5305 | } catch (java.util.NoSuchElementException ex) { |
| 5306 | // This will happen if the window has already been |
| 5307 | // removed. |
| 5308 | } |
| 5309 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5310 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5311 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5312 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5313 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5314 | /** |
| 5315 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5316 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5317 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5318 | if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | |
| 5320 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5321 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5322 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5323 | Slog.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5324 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5325 | } |
| 5326 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5327 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5328 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5329 | |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5330 | // Okay we have finished waiting for the last event to be processed. |
| 5331 | // First off, if this is a repeat event, check to see if there is |
| 5332 | // a corresponding up event in the queue. If there is, we will |
| 5333 | // just drop the repeat, because it makes no sense to repeat after |
| 5334 | // the user has released a key. (This is especially important for |
| 5335 | // long presses.) |
| 5336 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5337 | return INJECT_SUCCEEDED; |
| 5338 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5340 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5341 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5342 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5343 | TAG, "Dispatching to " + focus + ": " + event); |
| 5344 | |
| 5345 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5346 | if (mContext.checkPermission( |
| 5347 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5348 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5349 | 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] | 5350 | + pid + " uid " + uid + " to window " + focus |
| 5351 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5352 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5353 | } |
| 5354 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5356 | synchronized(mWindowMap) { |
| 5357 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5358 | } |
| 5359 | |
| 5360 | // NOSHIP extra state logging |
| 5361 | mKeyWaiter.recordDispatchState(event, focus); |
| 5362 | // END NOSHIP |
| 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 | try { |
| 5365 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5366 | Slog.v(TAG, "Delivering key " + event.getKeyCode() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5367 | + " to " + focus); |
| 5368 | } |
| 5369 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5370 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5371 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5372 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5373 | try { |
| 5374 | removeWindow(focus.mSession, focus.mClient); |
| 5375 | } catch (java.util.NoSuchElementException ex) { |
| 5376 | // This will happen if the window has already been |
| 5377 | // removed. |
| 5378 | } |
| 5379 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5380 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5381 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5384 | public void pauseKeyDispatching(IBinder _token) { |
| 5385 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5386 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5387 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | synchronized (mWindowMap) { |
| 5391 | WindowToken token = mTokenMap.get(_token); |
| 5392 | if (token != null) { |
| 5393 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5394 | } |
| 5395 | } |
| 5396 | } |
| 5397 | |
| 5398 | public void resumeKeyDispatching(IBinder _token) { |
| 5399 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5400 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5401 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5402 | } |
| 5403 | |
| 5404 | synchronized (mWindowMap) { |
| 5405 | WindowToken token = mTokenMap.get(_token); |
| 5406 | if (token != null) { |
| 5407 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5408 | } |
| 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | public void setEventDispatching(boolean enabled) { |
| 5413 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5414 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5415 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | synchronized (mWindowMap) { |
| 5419 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5420 | } |
| 5421 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5422 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5423 | /** |
| 5424 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5425 | * |
| 5426 | * @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] | 5427 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5428 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5429 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5430 | */ |
| 5431 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5432 | long downTime = ev.getDownTime(); |
| 5433 | long eventTime = ev.getEventTime(); |
| 5434 | |
| 5435 | int action = ev.getAction(); |
| 5436 | int code = ev.getKeyCode(); |
| 5437 | int repeatCount = ev.getRepeatCount(); |
| 5438 | int metaState = ev.getMetaState(); |
| 5439 | int deviceId = ev.getDeviceId(); |
| 5440 | int scancode = ev.getScanCode(); |
| 5441 | |
| 5442 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5443 | if (downTime == 0) downTime = eventTime; |
| 5444 | |
| 5445 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5446 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5447 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5448 | final int pid = Binder.getCallingPid(); |
| 5449 | final int uid = Binder.getCallingUid(); |
| 5450 | final long ident = Binder.clearCallingIdentity(); |
| 5451 | final int result = dispatchKey(newEvent, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5452 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5453 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5454 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5455 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5456 | switch (result) { |
| 5457 | case INJECT_NO_PERMISSION: |
| 5458 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5459 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5460 | case INJECT_SUCCEEDED: |
| 5461 | return true; |
| 5462 | } |
| 5463 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | /** |
| 5467 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5468 | * |
| 5469 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5470 | * {@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] | 5471 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5472 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5473 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5474 | */ |
| 5475 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5476 | final int pid = Binder.getCallingPid(); |
| 5477 | final int uid = Binder.getCallingUid(); |
| 5478 | final long ident = Binder.clearCallingIdentity(); |
| 5479 | final int result = dispatchPointer(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5480 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5481 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5482 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5483 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5484 | switch (result) { |
| 5485 | case INJECT_NO_PERMISSION: |
| 5486 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5487 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5488 | case INJECT_SUCCEEDED: |
| 5489 | return true; |
| 5490 | } |
| 5491 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5492 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5494 | /** |
| 5495 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5496 | * |
| 5497 | * @param ev A motion event describing the trackball action. (As noted in |
| 5498 | * {@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] | 5499 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5500 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5501 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5502 | */ |
| 5503 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5504 | final int pid = Binder.getCallingPid(); |
| 5505 | final int uid = Binder.getCallingUid(); |
| 5506 | final long ident = Binder.clearCallingIdentity(); |
| 5507 | final int result = dispatchTrackball(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5508 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5509 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5510 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5511 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5512 | switch (result) { |
| 5513 | case INJECT_NO_PERMISSION: |
| 5514 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5515 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5516 | case INJECT_SUCCEEDED: |
| 5517 | return true; |
| 5518 | } |
| 5519 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5520 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5522 | private WindowState getFocusedWindow() { |
| 5523 | synchronized (mWindowMap) { |
| 5524 | return getFocusedWindowLocked(); |
| 5525 | } |
| 5526 | } |
| 5527 | |
| 5528 | private WindowState getFocusedWindowLocked() { |
| 5529 | return mCurrentFocus; |
| 5530 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | /** |
| 5533 | * This class holds the state for dispatching key events. This state |
| 5534 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 5535 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 5536 | * but not the other way around. |
| 5537 | */ |
| 5538 | final class KeyWaiter { |
| 5539 | // NOSHIP debugging |
| 5540 | public class DispatchState { |
| 5541 | private KeyEvent event; |
| 5542 | private WindowState focus; |
| 5543 | private long time; |
| 5544 | private WindowState lastWin; |
| 5545 | private IBinder lastBinder; |
| 5546 | private boolean finished; |
| 5547 | private boolean gotFirstWindow; |
| 5548 | private boolean eventDispatching; |
| 5549 | private long timeToSwitch; |
| 5550 | private boolean wasFrozen; |
| 5551 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5552 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5554 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5555 | focus = theFocus; |
| 5556 | event = theEvent; |
| 5557 | time = System.currentTimeMillis(); |
| 5558 | // snapshot KeyWaiter state |
| 5559 | lastWin = mLastWin; |
| 5560 | lastBinder = mLastBinder; |
| 5561 | finished = mFinished; |
| 5562 | gotFirstWindow = mGotFirstWindow; |
| 5563 | eventDispatching = mEventDispatching; |
| 5564 | timeToSwitch = mTimeToSwitch; |
| 5565 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5566 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5567 | // cache the paused state at ctor time as well |
| 5568 | if (theFocus == null || theFocus.mToken == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5569 | focusPaused = false; |
| 5570 | } else { |
| 5571 | focusPaused = theFocus.mToken.paused; |
| 5572 | } |
| 5573 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | public String toString() { |
| 5576 | return "{{" + event + " to " + focus + " @ " + time |
| 5577 | + " lw=" + lastWin + " lb=" + lastBinder |
| 5578 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 5579 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5580 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| Christopher Tate | 46d4525 | 2010-02-09 15:48:57 -0800 | [diff] [blame] | 5581 | + " mcf=" + curFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | } |
| 5583 | }; |
| 5584 | private DispatchState mDispatchState = null; |
| 5585 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5586 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 5587 | } |
| 5588 | // END NOSHIP |
| 5589 | |
| 5590 | public static final int RETURN_NOTHING = 0; |
| 5591 | public static final int RETURN_PENDING_POINTER = 1; |
| 5592 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5594 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 5595 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5596 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5597 | private WindowState mLastWin = null; |
| 5598 | private IBinder mLastBinder = null; |
| 5599 | private boolean mFinished = true; |
| 5600 | private boolean mGotFirstWindow = false; |
| 5601 | private boolean mEventDispatching = true; |
| 5602 | private long mTimeToSwitch = 0; |
| 5603 | /* package */ boolean mWasFrozen = false; |
| 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 | // Target of Motion events |
| 5606 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5608 | // Windows above the target who would like to receive an "outside" |
| 5609 | // touch event for any down events outside of them. |
| 5610 | WindowState mOutsideTouchTargets; |
| 5611 | |
| 5612 | /** |
| 5613 | * Wait for the last event dispatch to complete, then find the next |
| 5614 | * target that should receive the given event and wait for that one |
| 5615 | * to be ready to receive it. |
| 5616 | */ |
| 5617 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5618 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5619 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5620 | long startTime = SystemClock.uptimeMillis(); |
| 5621 | long keyDispatchingTimeout = 5 * 1000; |
| 5622 | long waitedFor = 0; |
| 5623 | |
| 5624 | while (true) { |
| 5625 | // Figure out which window we care about. It is either the |
| 5626 | // last window we are waiting to have process the event or, |
| 5627 | // if none, then the next window we think the event should go |
| 5628 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5629 | // it may change before we lock. Thus we must check it again. |
| 5630 | WindowState targetWin = mLastWin; |
| 5631 | boolean targetIsNew = targetWin == null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5632 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5634 | ", mLastWin=" + mLastWin); |
| 5635 | if (targetIsNew) { |
| 5636 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5637 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5638 | if (target == SKIP_TARGET_TOKEN) { |
| 5639 | // The user has pressed a special key, and we are |
| 5640 | // dropping all pending events before it. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5641 | if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5642 | + " " + nextMotion); |
| 5643 | return null; |
| 5644 | } |
| 5645 | if (target == CONSUMED_EVENT_TOKEN) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5646 | if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5647 | + " " + nextMotion); |
| 5648 | return target; |
| 5649 | } |
| 5650 | targetWin = (WindowState)target; |
| 5651 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5652 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | AppWindowToken targetApp = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5655 | // Now: is it okay to send the next event to this window? |
| 5656 | synchronized (this) { |
| 5657 | // First: did we come here based on the last window not |
| 5658 | // being null, but it changed by the time we got here? |
| 5659 | // If so, try again. |
| 5660 | if (!targetIsNew && mLastWin == null) { |
| 5661 | continue; |
| 5662 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5663 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5664 | // We never dispatch events if not finished with the |
| 5665 | // last one, or the display is frozen. |
| 5666 | if (mFinished && !mDisplayFrozen) { |
| 5667 | // If event dispatching is disabled, then we |
| 5668 | // just consume the events. |
| 5669 | if (!mEventDispatching) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5670 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5671 | "Skipping event; dispatching disabled: " |
| 5672 | + nextKey + " " + nextMotion); |
| 5673 | return null; |
| 5674 | } |
| 5675 | if (targetWin != null) { |
| 5676 | // If this is a new target, and that target is not |
| 5677 | // paused or unresponsive, then all looks good to |
| 5678 | // handle the event. |
| 5679 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5680 | return targetWin; |
| 5681 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5682 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5683 | // If we didn't find a target window, and there is no |
| 5684 | // focused app window, then just eat the events. |
| 5685 | } else if (mFocusedApp == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5686 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5687 | "Skipping event; no focused app: " |
| 5688 | + nextKey + " " + nextMotion); |
| 5689 | return null; |
| 5690 | } |
| 5691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5692 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5693 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5694 | TAG, "Waiting for last key in " + mLastBinder |
| 5695 | + " target=" + targetWin |
| 5696 | + " mFinished=" + mFinished |
| 5697 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5698 | + " targetIsNew=" + targetIsNew |
| 5699 | + " paused=" |
| 5700 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5701 | + " mFocusedApp=" + mFocusedApp |
| 5702 | + " mCurrentFocus=" + mCurrentFocus); |
| 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 | targetApp = targetWin != null |
| 5705 | ? targetWin.mAppToken : mFocusedApp; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5706 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5707 | long curTimeout = keyDispatchingTimeout; |
| 5708 | if (mTimeToSwitch != 0) { |
| 5709 | long now = SystemClock.uptimeMillis(); |
| 5710 | if (mTimeToSwitch <= now) { |
| 5711 | // If an app switch key has been pressed, and we have |
| 5712 | // waited too long for the current app to finish |
| 5713 | // processing keys, then wait no more! |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 5714 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | continue; |
| 5716 | } |
| 5717 | long switchTimeout = mTimeToSwitch - now; |
| 5718 | if (curTimeout > switchTimeout) { |
| 5719 | curTimeout = switchTimeout; |
| 5720 | } |
| 5721 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5722 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5723 | try { |
| 5724 | // after that continue |
| 5725 | // processing keys, so we don't get stuck. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5726 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5727 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5728 | wait(curTimeout); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5729 | if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5730 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5731 | + startTime + " switchTime=" + mTimeToSwitch |
| 5732 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5733 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5734 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | } catch (InterruptedException e) { |
| 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | // If we were frozen during configuration change, restart the |
| 5740 | // timeout checks from now; otherwise look at whether we timed |
| 5741 | // out before awakening. |
| 5742 | if (mWasFrozen) { |
| 5743 | waitedFor = 0; |
| 5744 | mWasFrozen = false; |
| 5745 | } else { |
| 5746 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5747 | } |
| 5748 | |
| 5749 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5750 | IApplicationToken at = null; |
| 5751 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5752 | Slog.w(TAG, "Key dispatching timed out sending to " + |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 5754 | : "<null>: no window ready for key dispatch")); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5755 | // NOSHIP debugging |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5756 | Slog.w(TAG, "Previous dispatch state: " + mDispatchState); |
| 5757 | Slog.w(TAG, "Current dispatch state: " + |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 5758 | new DispatchState(nextKey, targetWin)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5759 | // END NOSHIP |
| 5760 | //dump(); |
| 5761 | if (targetWin != null) { |
| 5762 | at = targetWin.getAppToken(); |
| 5763 | } else if (targetApp != null) { |
| 5764 | at = targetApp.appToken; |
| 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | boolean abort = true; |
| 5769 | if (at != null) { |
| 5770 | try { |
| 5771 | long timeout = at.getKeyDispatchingTimeout(); |
| 5772 | if (timeout > waitedFor) { |
| 5773 | // we did not wait the proper amount of time for this application. |
| 5774 | // set the timeout to be the real timeout and wait again. |
| 5775 | keyDispatchingTimeout = timeout - waitedFor; |
| 5776 | continue; |
| 5777 | } else { |
| 5778 | abort = at.keyDispatchingTimedOut(); |
| 5779 | } |
| 5780 | } catch (RemoteException ex) { |
| 5781 | } |
| 5782 | } |
| 5783 | |
| 5784 | synchronized (this) { |
| 5785 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5786 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5787 | if (mLastWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5788 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | "Window " + mLastWin + |
| 5790 | " timed out on key input"); |
| 5791 | if (mLastWin.mToken.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5792 | Slog.w(TAG, "Un-pausing dispatching to this window"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5793 | mLastWin.mToken.paused = false; |
| 5794 | } |
| 5795 | } |
| 5796 | if (mMotionTarget == targetWin) { |
| 5797 | mMotionTarget = null; |
| 5798 | } |
| 5799 | mLastWin = null; |
| 5800 | mLastBinder = null; |
| 5801 | if (failIfTimeout || targetWin == null) { |
| 5802 | return null; |
| 5803 | } |
| 5804 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5805 | 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] | 5806 | startTime = SystemClock.uptimeMillis(); |
| 5807 | } |
| 5808 | } |
| 5809 | } |
| 5810 | } |
| 5811 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5812 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5813 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5814 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5815 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5816 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | if (nextKey != null) { |
| 5819 | // Find the target window for a normal key event. |
| 5820 | final int keycode = nextKey.getKeyCode(); |
| 5821 | final int repeatCount = nextKey.getRepeatCount(); |
| 5822 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5823 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5824 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5826 | if (callingUid == 0 || |
| 5827 | mContext.checkPermission( |
| 5828 | android.Manifest.permission.INJECT_EVENTS, |
| 5829 | callingPid, callingUid) |
| 5830 | == PackageManager.PERMISSION_GRANTED) { |
| 5831 | mPolicy.interceptKeyTi(null, keycode, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5832 | nextKey.getMetaState(), down, repeatCount, |
| 5833 | nextKey.getFlags()); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5834 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5835 | Slog.w(TAG, "Event timeout during app switch: dropping " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5836 | + nextKey); |
| 5837 | return SKIP_TARGET_TOKEN; |
| 5838 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5840 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5841 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5842 | WindowState focus = null; |
| 5843 | synchronized(mWindowMap) { |
| 5844 | focus = getFocusedWindowLocked(); |
| 5845 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5846 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5847 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5848 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5849 | if (callingUid == 0 || |
| 5850 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5851 | mContext.checkPermission( |
| 5852 | android.Manifest.permission.INJECT_EVENTS, |
| 5853 | callingPid, callingUid) |
| 5854 | == PackageManager.PERMISSION_GRANTED) { |
| 5855 | if (mPolicy.interceptKeyTi(focus, |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5856 | keycode, nextKey.getMetaState(), down, repeatCount, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5857 | nextKey.getFlags())) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5858 | return CONSUMED_EVENT_TOKEN; |
| 5859 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5861 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5862 | return focus; |
| 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 | } else if (!isPointerEvent) { |
| 5865 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5866 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5867 | 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] | 5868 | + nextMotion); |
| 5869 | return SKIP_TARGET_TOKEN; |
| 5870 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | WindowState focus = null; |
| 5873 | synchronized(mWindowMap) { |
| 5874 | focus = getFocusedWindowLocked(); |
| 5875 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5876 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5877 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5878 | return focus; |
| 5879 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5881 | if (nextMotion == null) { |
| 5882 | return SKIP_TARGET_TOKEN; |
| 5883 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5885 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5886 | KeyEvent.KEYCODE_UNKNOWN); |
| 5887 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5888 | 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] | 5889 | + nextMotion); |
| 5890 | return SKIP_TARGET_TOKEN; |
| 5891 | } |
| 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 | // Find the target window for a pointer event. |
| 5894 | int action = nextMotion.getAction(); |
| 5895 | final float xf = nextMotion.getX(); |
| 5896 | final float yf = nextMotion.getY(); |
| 5897 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5898 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | final boolean screenWasOff = qev != null |
| 5900 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5902 | WindowState target = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5903 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5904 | synchronized(mWindowMap) { |
| 5905 | synchronized (this) { |
| 5906 | if (action == MotionEvent.ACTION_DOWN) { |
| 5907 | if (mMotionTarget != null) { |
| 5908 | // this is weird, we got a pen down, but we thought it was |
| 5909 | // already down! |
| 5910 | // XXX: We should probably send an ACTION_UP to the current |
| 5911 | // target. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5912 | 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] | 5913 | + mMotionTarget); |
| 5914 | mMotionTarget = null; |
| 5915 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5916 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5917 | // ACTION_DOWN is special, because we need to lock next events to |
| 5918 | // the window we'll land onto. |
| 5919 | final int x = (int)xf; |
| 5920 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5921 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5922 | final ArrayList windows = mWindows; |
| 5923 | final int N = windows.size(); |
| 5924 | WindowState topErrWindow = null; |
| 5925 | final Rect tmpRect = mTempRect; |
| 5926 | for (int i=N-1; i>=0; i--) { |
| 5927 | WindowState child = (WindowState)windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5928 | //Slog.i(TAG, "Checking dispatch to: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5929 | final int flags = child.mAttrs.flags; |
| 5930 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5931 | if (topErrWindow == null) { |
| 5932 | topErrWindow = child; |
| 5933 | } |
| 5934 | } |
| 5935 | if (!child.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5936 | //Slog.i(TAG, "Not visible!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5937 | continue; |
| 5938 | } |
| 5939 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5940 | //Slog.i(TAG, "Not touchable!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5941 | if ((flags & WindowManager.LayoutParams |
| 5942 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5943 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5944 | mOutsideTouchTargets = child; |
| 5945 | } |
| 5946 | continue; |
| 5947 | } |
| 5948 | tmpRect.set(child.mFrame); |
| 5949 | if (child.mTouchableInsets == ViewTreeObserver |
| 5950 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5951 | // The touch is inside of the window if it is |
| 5952 | // inside the frame, AND the content part of that |
| 5953 | // frame that was given by the application. |
| 5954 | tmpRect.left += child.mGivenContentInsets.left; |
| 5955 | tmpRect.top += child.mGivenContentInsets.top; |
| 5956 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5957 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5958 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5959 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5960 | // The touch is inside of the window if it is |
| 5961 | // inside the frame, AND the visible part of that |
| 5962 | // frame that was given by the application. |
| 5963 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5964 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5965 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5966 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5967 | } |
| 5968 | final int touchFlags = flags & |
| 5969 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5970 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5971 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5972 | //Slog.i(TAG, "Using this target!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5973 | if (!screenWasOff || (flags & |
| 5974 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5975 | mMotionTarget = child; |
| 5976 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5977 | //Slog.i(TAG, "Waking, skip!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5978 | mMotionTarget = null; |
| 5979 | } |
| 5980 | break; |
| 5981 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5983 | if ((flags & WindowManager.LayoutParams |
| 5984 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5985 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5986 | mOutsideTouchTargets = child; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5987 | //Slog.i(TAG, "Adding to outside target list: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | // if there's an error window but it's not accepting |
| 5992 | // focus (typically because it is not yet visible) just |
| 5993 | // wait for it -- any other focused window may in fact |
| 5994 | // be in ANR state. |
| 5995 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5996 | mMotionTarget = null; |
| 5997 | } |
| 5998 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5999 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6000 | target = mMotionTarget; |
| 6001 | } |
| 6002 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6003 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6004 | wakeupIfNeeded(target, eventType(nextMotion)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6006 | // Pointer events are a little different -- if there isn't a |
| 6007 | // target found for any event, then just drop it. |
| 6008 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 6009 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6010 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6011 | boolean checkShouldDispatchKey(int keycode) { |
| 6012 | synchronized (this) { |
| 6013 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 6014 | mTimeToSwitch = 0; |
| 6015 | return true; |
| 6016 | } |
| 6017 | if (mTimeToSwitch != 0 |
| 6018 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 6019 | return false; |
| 6020 | } |
| 6021 | return true; |
| 6022 | } |
| 6023 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6024 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6025 | void bindTargetWindowLocked(WindowState win, |
| 6026 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6027 | synchronized (this) { |
| 6028 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 6029 | } |
| 6030 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6031 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6032 | void bindTargetWindowLocked(WindowState win) { |
| 6033 | synchronized (this) { |
| 6034 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | void bindTargetWindowLockedLocked(WindowState win, |
| 6039 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6040 | mLastWin = win; |
| 6041 | mLastBinder = win.mClient.asBinder(); |
| 6042 | mFinished = false; |
| 6043 | if (pendingMotion != null) { |
| 6044 | final Session s = win.mSession; |
| 6045 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 6046 | releasePendingPointerLocked(s); |
| 6047 | s.mPendingPointerMove = pendingMotion; |
| 6048 | s.mPendingPointerWindow = win; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6049 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6050 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 6051 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 6052 | releasePendingTrackballLocked(s); |
| 6053 | s.mPendingTrackballMove = pendingMotion; |
| 6054 | s.mPendingTrackballWindow = win; |
| 6055 | } |
| 6056 | } |
| 6057 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6058 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6059 | void releasePendingPointerLocked(Session s) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6060 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6061 | "releasePendingPointer " + s.mPendingPointerMove); |
| 6062 | if (s.mPendingPointerMove != null) { |
| 6063 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 6064 | s.mPendingPointerMove = null; |
| 6065 | } |
| 6066 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6067 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6068 | void releasePendingTrackballLocked(Session s) { |
| 6069 | if (s.mPendingTrackballMove != null) { |
| 6070 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 6071 | s.mPendingTrackballMove = null; |
| 6072 | } |
| 6073 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6074 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6075 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 6076 | int returnWhat) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6077 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6078 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 6079 | |
| 6080 | if (client == null) { |
| 6081 | return null; |
| 6082 | } |
| 6083 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6084 | MotionEvent res = null; |
| 6085 | QueuedEvent qev = null; |
| 6086 | WindowState win = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6087 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6088 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6089 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6090 | TAG, "finishedKey: client=" + client.asBinder() |
| 6091 | + ", force=" + force + ", last=" + mLastBinder |
| 6092 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 6093 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6094 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 6095 | qev = session.mPendingPointerMove; |
| 6096 | win = session.mPendingPointerWindow; |
| 6097 | session.mPendingPointerMove = null; |
| 6098 | session.mPendingPointerWindow = null; |
| 6099 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 6100 | qev = session.mPendingTrackballMove; |
| 6101 | win = session.mPendingTrackballWindow; |
| 6102 | session.mPendingTrackballMove = null; |
| 6103 | session.mPendingTrackballWindow = null; |
| 6104 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6105 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6106 | if (mLastBinder == client.asBinder()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6107 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6108 | TAG, "finishedKey: last paused=" |
| 6109 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 6110 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 6111 | || !mEventDispatching)) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6112 | doFinishedKeyLocked(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | } else { |
| 6114 | // Make sure to wake up anyone currently waiting to |
| 6115 | // dispatch a key, so they can re-evaluate their |
| 6116 | // current situation. |
| 6117 | mFinished = true; |
| 6118 | notifyAll(); |
| 6119 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6120 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6121 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6122 | if (qev != null) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6123 | res = (MotionEvent)qev.event; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6124 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6125 | "Returning pending motion: " + res); |
| 6126 | mQueue.recycleEvent(qev); |
| 6127 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6128 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 6129 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6130 | } |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6131 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6132 | |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6133 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6134 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 6135 | dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6136 | } |
| 6137 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6138 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6139 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | void tickle() { |
| 6143 | synchronized (this) { |
| 6144 | notifyAll(); |
| 6145 | } |
| 6146 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6147 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6148 | void handleNewWindowLocked(WindowState newWindow) { |
| 6149 | if (!newWindow.canReceiveKeys()) { |
| 6150 | return; |
| 6151 | } |
| 6152 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6153 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6154 | TAG, "New key dispatch window: win=" |
| 6155 | + newWindow.mClient.asBinder() |
| 6156 | + ", last=" + mLastBinder |
| 6157 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6158 | + "), finished=" + mFinished + ", paused=" |
| 6159 | + newWindow.mToken.paused); |
| 6160 | |
| 6161 | // Displaying a window implicitly causes dispatching to |
| 6162 | // be unpaused. (This is to protect against bugs if someone |
| 6163 | // pauses dispatching but forgets to resume.) |
| 6164 | newWindow.mToken.paused = false; |
| 6165 | |
| 6166 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6167 | |
| 6168 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6169 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | "New SYSTEM_ERROR window; resetting state"); |
| 6171 | mLastWin = null; |
| 6172 | mLastBinder = null; |
| 6173 | mMotionTarget = null; |
| 6174 | mFinished = true; |
| 6175 | } else if (mLastWin != null) { |
| 6176 | // If the new window is above the window we are |
| 6177 | // waiting on, then stop waiting and let key dispatching |
| 6178 | // start on the new guy. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6179 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | TAG, "Last win layer=" + mLastWin.mLayer |
| 6181 | + ", new win layer=" + newWindow.mLayer); |
| 6182 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6183 | // The new window is above the old; finish pending input to the last |
| 6184 | // window and start directing it to the new one. |
| 6185 | mLastWin.mToken.paused = false; |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6186 | doFinishedKeyLocked(false); // does a notifyAll() |
| 6187 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | } |
| 6189 | } |
| 6190 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6191 | // Now that we've put a new window state in place, make the event waiter |
| 6192 | // take notice and retarget its attentions. |
| 6193 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | void pauseDispatchingLocked(WindowToken token) { |
| 6198 | synchronized (this) |
| 6199 | { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6200 | if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6201 | token.paused = true; |
| 6202 | |
| 6203 | /* |
| 6204 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 6205 | mPaused = true; |
| 6206 | } else { |
| 6207 | if (mLastWin == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6208 | 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] | 6209 | } else if (mFinished) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6210 | 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] | 6211 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6212 | 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] | 6213 | } |
| 6214 | } |
| 6215 | */ |
| 6216 | } |
| 6217 | } |
| 6218 | |
| 6219 | void resumeDispatchingLocked(WindowToken token) { |
| 6220 | synchronized (this) { |
| 6221 | if (token.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6222 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6223 | TAG, "Resuming WindowToken " + token |
| 6224 | + ", last=" + mLastBinder |
| 6225 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6226 | + "), finished=" + mFinished + ", paused=" |
| 6227 | + token.paused); |
| 6228 | token.paused = false; |
| 6229 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6230 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6231 | } else { |
| 6232 | notifyAll(); |
| 6233 | } |
| 6234 | } |
| 6235 | } |
| 6236 | } |
| 6237 | |
| 6238 | void setEventDispatchingLocked(boolean enabled) { |
| 6239 | synchronized (this) { |
| 6240 | mEventDispatching = enabled; |
| 6241 | notifyAll(); |
| 6242 | } |
| 6243 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6245 | void appSwitchComing() { |
| 6246 | synchronized (this) { |
| 6247 | // Don't wait for more than .5 seconds for app to finish |
| 6248 | // processing the pending events. |
| 6249 | long now = SystemClock.uptimeMillis() + 500; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6250 | if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 6252 | mTimeToSwitch = now; |
| 6253 | } |
| 6254 | notifyAll(); |
| 6255 | } |
| 6256 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6257 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6258 | private final void doFinishedKeyLocked(boolean force) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6259 | if (mLastWin != null) { |
| 6260 | releasePendingPointerLocked(mLastWin.mSession); |
| 6261 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6262 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6263 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6264 | if (force || mLastWin == null || !mLastWin.mToken.paused |
| 6265 | || !mLastWin.isVisibleLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6266 | // If the current window has been paused, we aren't -really- |
| 6267 | // finished... so let the waiters still wait. |
| 6268 | mLastWin = null; |
| 6269 | mLastBinder = null; |
| 6270 | } |
| 6271 | mFinished = true; |
| 6272 | notifyAll(); |
| 6273 | } |
| 6274 | } |
| 6275 | |
| 6276 | private class KeyQ extends KeyInputQueue |
| 6277 | implements KeyInputQueue.FilterCallback { |
| 6278 | PowerManager.WakeLock mHoldingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6280 | KeyQ() { |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6281 | super(mContext, WindowManagerService.this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6282 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 6283 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 6284 | "KEEP_SCREEN_ON_FLAG"); |
| 6285 | mHoldingScreen.setReferenceCounted(false); |
| 6286 | } |
| 6287 | |
| 6288 | @Override |
| 6289 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6290 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6291 | return true; |
| 6292 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6294 | switch (event.type) { |
| 6295 | case RawInputEvent.EV_KEY: { |
| 6296 | // XXX begin hack |
| 6297 | if (DEBUG) { |
| 6298 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6299 | if (event.value != 0) { |
| 6300 | // G down |
| 6301 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6302 | } |
| 6303 | return false; |
| 6304 | } |
| 6305 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6306 | if (event.value != 0) { |
| 6307 | //dump(); |
| 6308 | } |
| 6309 | return false; |
| 6310 | } |
| 6311 | } |
| 6312 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6313 | |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6314 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6315 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6316 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6318 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6319 | mPowerManager.goToSleep(event.when); |
| 6320 | } |
| 6321 | |
| 6322 | if (screenIsOff) { |
| 6323 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6324 | } |
| 6325 | if (screenIsDim) { |
| 6326 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6327 | } |
| 6328 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6329 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6330 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6331 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6334 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6335 | filterQueue(this); |
| 6336 | mKeyWaiter.appSwitchComing(); |
| 6337 | } |
| 6338 | return true; |
| 6339 | } else { |
| 6340 | return false; |
| 6341 | } |
| 6342 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6344 | case RawInputEvent.EV_REL: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6345 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6346 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6347 | if (screenIsOff) { |
| 6348 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6349 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6350 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | return false; |
| 6352 | } |
| 6353 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6354 | } |
| 6355 | if (screenIsDim) { |
| 6356 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6357 | } |
| 6358 | return true; |
| 6359 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6360 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | case RawInputEvent.EV_ABS: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6362 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6363 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6364 | if (screenIsOff) { |
| 6365 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6366 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6367 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6368 | return false; |
| 6369 | } |
| 6370 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6371 | } |
| 6372 | if (screenIsDim) { |
| 6373 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6374 | } |
| 6375 | return true; |
| 6376 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6377 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | default: |
| 6379 | return true; |
| 6380 | } |
| 6381 | } |
| 6382 | |
| 6383 | public int filterEvent(QueuedEvent ev) { |
| 6384 | switch (ev.classType) { |
| 6385 | case RawInputEvent.CLASS_KEYBOARD: |
| 6386 | KeyEvent ke = (KeyEvent)ev.event; |
| 6387 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6388 | Slog.w(TAG, "Dropping movement key during app switch: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6390 | return FILTER_REMOVE; |
| 6391 | } |
| 6392 | return FILTER_ABORT; |
| 6393 | default: |
| 6394 | return FILTER_KEEP; |
| 6395 | } |
| 6396 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6397 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | /** |
| 6399 | * Must be called with the main window manager lock held. |
| 6400 | */ |
| 6401 | void setHoldScreenLocked(boolean holding) { |
| 6402 | boolean state = mHoldingScreen.isHeld(); |
| 6403 | if (holding != state) { |
| 6404 | if (holding) { |
| 6405 | mHoldingScreen.acquire(); |
| 6406 | } else { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6407 | mPolicy.screenOnStoppedLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6408 | mHoldingScreen.release(); |
| 6409 | } |
| 6410 | } |
| 6411 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6412 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6413 | |
| 6414 | public boolean detectSafeMode() { |
| 6415 | mSafeMode = mPolicy.detectSafeMode(); |
| 6416 | return mSafeMode; |
| 6417 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6418 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | public void systemReady() { |
| 6420 | mPolicy.systemReady(); |
| 6421 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6422 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6423 | private final class InputDispatcherThread extends Thread { |
| 6424 | // Time to wait when there is nothing to do: 9999 seconds. |
| 6425 | static final int LONG_WAIT=9999*1000; |
| 6426 | |
| 6427 | public InputDispatcherThread() { |
| 6428 | super("InputDispatcher"); |
| 6429 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6430 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6431 | @Override |
| 6432 | public void run() { |
| 6433 | while (true) { |
| 6434 | try { |
| 6435 | process(); |
| 6436 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6437 | Slog.e(TAG, "Exception in input dispatcher", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6438 | } |
| 6439 | } |
| 6440 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6442 | private void process() { |
| 6443 | android.os.Process.setThreadPriority( |
| 6444 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6446 | // The last key event we saw |
| 6447 | KeyEvent lastKey = null; |
| 6448 | |
| 6449 | // Last keydown time for auto-repeating keys |
| 6450 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 6451 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6452 | long downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6454 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6455 | int keyRepeatCount = 0; |
| 6456 | |
| 6457 | // Need to report that configuration has changed? |
| 6458 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6460 | while (true) { |
| 6461 | long curTime = SystemClock.uptimeMillis(); |
| 6462 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6463 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6464 | TAG, "Waiting for next key: now=" + curTime |
| 6465 | + ", repeat @ " + nextKeyTime); |
| 6466 | |
| 6467 | // Retrieve next event, waiting only as long as the next |
| 6468 | // repeat timeout. If the configuration has changed, then |
| 6469 | // don't wait at all -- we'll report the change as soon as |
| 6470 | // we have processed all events. |
| 6471 | QueuedEvent ev = mQueue.getEvent( |
| 6472 | (int)((!configChanged && curTime < nextKeyTime) |
| 6473 | ? (nextKeyTime-curTime) : 0)); |
| 6474 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6475 | if (DEBUG_INPUT && ev != null) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6476 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 6477 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6478 | if (MEASURE_LATENCY) { |
| 6479 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 6480 | } |
| 6481 | |
| Mike Lockwood | 3d0ea72 | 2009-10-21 22:58:29 -0400 | [diff] [blame] | 6482 | if (lastKey != null && !mPolicy.allowKeyRepeat()) { |
| 6483 | // cancel key repeat at the request of the policy. |
| 6484 | lastKey = null; |
| 6485 | downTime = 0; |
| 6486 | lastKeyTime = curTime; |
| 6487 | nextKeyTime = curTime + LONG_WAIT; |
| 6488 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6489 | try { |
| 6490 | if (ev != null) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6491 | curTime = SystemClock.uptimeMillis(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6492 | int eventType; |
| 6493 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 6494 | eventType = eventType((MotionEvent)ev.event); |
| 6495 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 6496 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 6497 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 6498 | } else { |
| 6499 | eventType = LocalPowerManager.OTHER_EVENT; |
| 6500 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6501 | try { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6502 | if ((curTime - mLastBatteryStatsCallTime) |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6503 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6504 | mLastBatteryStatsCallTime = curTime; |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6505 | mBatteryStats.noteInputEvent(); |
| 6506 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6507 | } catch (RemoteException e) { |
| 6508 | // Ignore |
| 6509 | } |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6510 | |
| Mike Lockwood | 5db4240 | 2009-11-30 14:51:51 -0500 | [diff] [blame] | 6511 | if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) { |
| 6512 | // do not wake screen in this case |
| 6513 | } else if (eventType != TOUCH_EVENT |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6514 | && eventType != LONG_TOUCH_EVENT |
| 6515 | && eventType != CHEEK_EVENT) { |
| 6516 | mPowerManager.userActivity(curTime, false, |
| 6517 | eventType, false); |
| 6518 | } else if (mLastTouchEventType != eventType |
| 6519 | || (curTime - mLastUserActivityCallTime) |
| 6520 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 6521 | mLastUserActivityCallTime = curTime; |
| 6522 | mLastTouchEventType = eventType; |
| 6523 | mPowerManager.userActivity(curTime, false, |
| 6524 | eventType, false); |
| 6525 | } |
| 6526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6527 | switch (ev.classType) { |
| 6528 | case RawInputEvent.CLASS_KEYBOARD: |
| 6529 | KeyEvent ke = (KeyEvent)ev.event; |
| 6530 | if (ke.isDown()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6531 | lastKeyTime = curTime; |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6532 | if (lastKey != null && |
| 6533 | ke.getKeyCode() == lastKey.getKeyCode()) { |
| 6534 | keyRepeatCount++; |
| 6535 | // Arbitrary long timeout to block |
| 6536 | // repeating here since we know that |
| 6537 | // the device driver takes care of it. |
| 6538 | nextKeyTime = lastKeyTime + LONG_WAIT; |
| The Android Open Source Project | 2a9ae01 | 2010-05-12 12:33:35 -0700 | [diff] [blame] | 6539 | if (DEBUG_INPUT) Slog.v( |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6540 | TAG, "Received repeated key down"); |
| 6541 | } else { |
| 6542 | downTime = curTime; |
| 6543 | keyRepeatCount = 0; |
| 6544 | nextKeyTime = lastKeyTime |
| 6545 | + ViewConfiguration.getLongPressTimeout(); |
| The Android Open Source Project | 2a9ae01 | 2010-05-12 12:33:35 -0700 | [diff] [blame] | 6546 | if (DEBUG_INPUT) Slog.v( |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6547 | TAG, "Received key down: first repeat @ " |
| 6548 | + nextKeyTime); |
| 6549 | } |
| 6550 | lastKey = ke; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6551 | } else { |
| 6552 | lastKey = null; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6553 | downTime = 0; |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6554 | keyRepeatCount = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6555 | // Arbitrary long timeout. |
| 6556 | lastKeyTime = curTime; |
| 6557 | nextKeyTime = curTime + LONG_WAIT; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6558 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6559 | TAG, "Received key up: ignore repeat @ " |
| 6560 | + nextKeyTime); |
| 6561 | } |
| Kristian Dreher | 133bfdf | 2010-02-23 08:50:58 +0100 | [diff] [blame] | 6562 | if (keyRepeatCount > 0) { |
| 6563 | dispatchKey(KeyEvent.changeTimeRepeat(ke, |
| 6564 | ke.getEventTime(), keyRepeatCount), 0, 0); |
| 6565 | } else { |
| 6566 | dispatchKey(ke, 0, 0); |
| 6567 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6568 | mQueue.recycleEvent(ev); |
| 6569 | break; |
| 6570 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6571 | //Slog.i(TAG, "Read next event " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6572 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 6573 | break; |
| 6574 | case RawInputEvent.CLASS_TRACKBALL: |
| 6575 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 6576 | break; |
| 6577 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 6578 | configChanged = true; |
| 6579 | break; |
| 6580 | default: |
| 6581 | mQueue.recycleEvent(ev); |
| 6582 | break; |
| 6583 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6584 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6585 | } else if (configChanged) { |
| 6586 | configChanged = false; |
| 6587 | sendNewConfiguration(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6589 | } else if (lastKey != null) { |
| 6590 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6592 | // Timeout occurred while key was down. If it is at or |
| 6593 | // past the key repeat time, dispatch the repeat. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6594 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6595 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 6596 | + ", now=" + curTime); |
| 6597 | if (curTime < nextKeyTime) { |
| 6598 | continue; |
| 6599 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6600 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | lastKeyTime = nextKeyTime; |
| 6602 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 6603 | keyRepeatCount++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6604 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6605 | TAG, "Key repeat: count=" + keyRepeatCount |
| 6606 | + ", next @ " + nextKeyTime); |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6607 | KeyEvent newEvent; |
| 6608 | if (downTime != 0 && (downTime |
| 6609 | + ViewConfiguration.getLongPressTimeout()) |
| 6610 | <= curTime) { |
| 6611 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6612 | curTime, keyRepeatCount, |
| 6613 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6614 | downTime = 0; |
| 6615 | } else { |
| 6616 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6617 | curTime, keyRepeatCount); |
| 6618 | } |
| 6619 | dispatchKey(newEvent, 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | } else { |
| 6622 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | lastKeyTime = curTime; |
| 6625 | nextKeyTime = curTime + LONG_WAIT; |
| 6626 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6627 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6628 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6629 | Slog.e(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6630 | "Input thread received uncaught exception: " + e, e); |
| 6631 | } |
| 6632 | } |
| 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | // ------------------------------------------------------------- |
| 6637 | // Client Session State |
| 6638 | // ------------------------------------------------------------- |
| 6639 | |
| 6640 | private final class Session extends IWindowSession.Stub |
| 6641 | implements IBinder.DeathRecipient { |
| 6642 | final IInputMethodClient mClient; |
| 6643 | final IInputContext mInputContext; |
| 6644 | final int mUid; |
| 6645 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6646 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | SurfaceSession mSurfaceSession; |
| 6648 | int mNumWindow = 0; |
| 6649 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6650 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6651 | /** |
| 6652 | * Current pointer move event being dispatched to client window... must |
| 6653 | * hold key lock to access. |
| 6654 | */ |
| 6655 | QueuedEvent mPendingPointerMove; |
| 6656 | WindowState mPendingPointerWindow; |
| 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 | /** |
| 6659 | * Current trackball move event being dispatched to client window... must |
| 6660 | * hold key lock to access. |
| 6661 | */ |
| 6662 | QueuedEvent mPendingTrackballMove; |
| 6663 | WindowState mPendingTrackballWindow; |
| 6664 | |
| 6665 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6666 | mClient = client; |
| 6667 | mInputContext = inputContext; |
| 6668 | mUid = Binder.getCallingUid(); |
| 6669 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6670 | StringBuilder sb = new StringBuilder(); |
| 6671 | sb.append("Session{"); |
| 6672 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6673 | sb.append(" uid "); |
| 6674 | sb.append(mUid); |
| 6675 | sb.append("}"); |
| 6676 | mStringName = sb.toString(); |
| 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 | synchronized (mWindowMap) { |
| 6679 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6680 | IBinder b = ServiceManager.getService( |
| 6681 | Context.INPUT_METHOD_SERVICE); |
| 6682 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6683 | } |
| 6684 | } |
| 6685 | long ident = Binder.clearCallingIdentity(); |
| 6686 | try { |
| 6687 | // Note: it is safe to call in to the input method manager |
| 6688 | // here because we are not holding our lock. |
| 6689 | if (mInputMethodManager != null) { |
| 6690 | mInputMethodManager.addClient(client, inputContext, |
| 6691 | mUid, mPid); |
| 6692 | } else { |
| 6693 | client.setUsingInputMethod(false); |
| 6694 | } |
| 6695 | client.asBinder().linkToDeath(this, 0); |
| 6696 | } catch (RemoteException e) { |
| 6697 | // The caller has died, so we can just forget about this. |
| 6698 | try { |
| 6699 | if (mInputMethodManager != null) { |
| 6700 | mInputMethodManager.removeClient(client); |
| 6701 | } |
| 6702 | } catch (RemoteException ee) { |
| 6703 | } |
| 6704 | } finally { |
| 6705 | Binder.restoreCallingIdentity(ident); |
| 6706 | } |
| 6707 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6709 | @Override |
| 6710 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6711 | throws RemoteException { |
| 6712 | try { |
| 6713 | return super.onTransact(code, data, reply, flags); |
| 6714 | } catch (RuntimeException e) { |
| 6715 | // Log all 'real' exceptions thrown to the caller |
| 6716 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6717 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6718 | } |
| 6719 | throw e; |
| 6720 | } |
| 6721 | } |
| 6722 | |
| 6723 | public void binderDied() { |
| 6724 | // Note: it is safe to call in to the input method manager |
| 6725 | // here because we are not holding our lock. |
| 6726 | try { |
| 6727 | if (mInputMethodManager != null) { |
| 6728 | mInputMethodManager.removeClient(mClient); |
| 6729 | } |
| 6730 | } catch (RemoteException e) { |
| 6731 | } |
| 6732 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6733 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | mClientDead = true; |
| 6735 | killSessionLocked(); |
| 6736 | } |
| 6737 | } |
| 6738 | |
| 6739 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6740 | int viewVisibility, Rect outContentInsets) { |
| 6741 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6742 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6743 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6744 | public void remove(IWindow window) { |
| 6745 | removeWindow(this, window); |
| 6746 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6747 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6748 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6749 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6750 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6751 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6752 | return relayoutWindow(this, window, attrs, |
| 6753 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6754 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6755 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6757 | public void setTransparentRegion(IWindow window, Region region) { |
| 6758 | setTransparentRegionWindow(this, window, region); |
| 6759 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6760 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6761 | public void setInsets(IWindow window, int touchableInsets, |
| 6762 | Rect contentInsets, Rect visibleInsets) { |
| 6763 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6764 | visibleInsets); |
| 6765 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6767 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6768 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6769 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6770 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6771 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6772 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | TAG, "IWindow finishDrawing called for " + window); |
| 6774 | finishDrawingWindow(this, window); |
| 6775 | } |
| 6776 | |
| 6777 | public void finishKey(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6778 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6779 | TAG, "IWindow finishKey called for " + window); |
| 6780 | mKeyWaiter.finishedKey(this, window, false, |
| 6781 | KeyWaiter.RETURN_NOTHING); |
| 6782 | } |
| 6783 | |
| 6784 | public MotionEvent getPendingPointerMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6785 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6786 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6787 | return mKeyWaiter.finishedKey(this, window, false, |
| 6788 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6789 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6790 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6792 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6793 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6794 | return mKeyWaiter.finishedKey(this, window, false, |
| 6795 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6796 | } |
| 6797 | |
| 6798 | public void setInTouchMode(boolean mode) { |
| 6799 | synchronized(mWindowMap) { |
| 6800 | mInTouchMode = mode; |
| 6801 | } |
| 6802 | } |
| 6803 | |
| 6804 | public boolean getInTouchMode() { |
| 6805 | synchronized(mWindowMap) { |
| 6806 | return mInTouchMode; |
| 6807 | } |
| 6808 | } |
| 6809 | |
| 6810 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6811 | boolean always) { |
| 6812 | synchronized(mWindowMap) { |
| 6813 | long ident = Binder.clearCallingIdentity(); |
| 6814 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6815 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6816 | windowForClientLocked(this, window, true), |
| 6817 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6818 | } finally { |
| 6819 | Binder.restoreCallingIdentity(ident); |
| 6820 | } |
| 6821 | } |
| 6822 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6823 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6824 | 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] | 6825 | synchronized(mWindowMap) { |
| 6826 | long ident = Binder.clearCallingIdentity(); |
| 6827 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6828 | setWindowWallpaperPositionLocked( |
| 6829 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6830 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6831 | } finally { |
| 6832 | Binder.restoreCallingIdentity(ident); |
| 6833 | } |
| 6834 | } |
| 6835 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6836 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6837 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6838 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6839 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6840 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6841 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6842 | int z, Bundle extras, boolean sync) { |
| 6843 | synchronized(mWindowMap) { |
| 6844 | long ident = Binder.clearCallingIdentity(); |
| 6845 | try { |
| 6846 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6847 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6848 | action, x, y, z, extras, sync); |
| 6849 | } finally { |
| 6850 | Binder.restoreCallingIdentity(ident); |
| 6851 | } |
| 6852 | } |
| 6853 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6854 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6855 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6856 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6857 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6859 | void windowAddedLocked() { |
| 6860 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6861 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6862 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6863 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6864 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6865 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | mSessions.add(this); |
| 6867 | } |
| 6868 | mNumWindow++; |
| 6869 | } |
| 6870 | |
| 6871 | void windowRemovedLocked() { |
| 6872 | mNumWindow--; |
| 6873 | killSessionLocked(); |
| 6874 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6875 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6876 | void killSessionLocked() { |
| 6877 | if (mNumWindow <= 0 && mClientDead) { |
| 6878 | mSessions.remove(this); |
| 6879 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6880 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6881 | TAG, "Last window removed from " + this |
| 6882 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6883 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6884 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6885 | try { |
| 6886 | mSurfaceSession.kill(); |
| 6887 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6888 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6889 | + mSurfaceSession + " in session " + this |
| 6890 | + ": " + e.toString()); |
| 6891 | } |
| 6892 | mSurfaceSession = null; |
| 6893 | } |
| 6894 | } |
| 6895 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6897 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6898 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6899 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6900 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6901 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6902 | pw.print(prefix); |
| 6903 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6904 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6905 | } |
| 6906 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6907 | pw.print(prefix); |
| 6908 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6909 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6910 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6911 | } |
| 6912 | |
| 6913 | @Override |
| 6914 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6915 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6916 | } |
| 6917 | } |
| 6918 | |
| 6919 | // ------------------------------------------------------------- |
| 6920 | // Client Window State |
| 6921 | // ------------------------------------------------------------- |
| 6922 | |
| 6923 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6924 | final Session mSession; |
| 6925 | final IWindow mClient; |
| 6926 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6927 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6928 | AppWindowToken mAppToken; |
| 6929 | AppWindowToken mTargetAppToken; |
| 6930 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6931 | final DeathRecipient mDeathRecipient; |
| 6932 | final WindowState mAttachedWindow; |
| 6933 | final ArrayList mChildWindows = new ArrayList(); |
| 6934 | final int mBaseLayer; |
| 6935 | final int mSubLayer; |
| 6936 | final boolean mLayoutAttached; |
| 6937 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6938 | final boolean mIsWallpaper; |
| 6939 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | int mViewVisibility; |
| 6941 | boolean mPolicyVisibility = true; |
| 6942 | boolean mPolicyVisibilityAfterAnim = true; |
| 6943 | boolean mAppFreezing; |
| 6944 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6945 | boolean mReportDestroySurface; |
| 6946 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | boolean mAttachedHidden; // is our parent window hidden? |
| 6948 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6949 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | int mRequestedWidth; |
| 6951 | int mRequestedHeight; |
| 6952 | int mLastRequestedWidth; |
| 6953 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6954 | int mLayer; |
| 6955 | int mAnimLayer; |
| 6956 | int mLastLayer; |
| 6957 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6958 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6959 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6960 | |
| 6961 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6962 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6963 | int mLayoutSeq = -1; |
| 6964 | |
| 6965 | Configuration mConfiguration = null; |
| 6966 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6967 | // Actual frame shown on-screen (may be modified by animation) |
| 6968 | final Rect mShownFrame = new Rect(); |
| 6969 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6970 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6971 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6972 | * Set when we have changed the size of the surface, to know that |
| 6973 | * we must tell them application to resize (and thus redraw itself). |
| 6974 | */ |
| 6975 | boolean mSurfaceResized; |
| 6976 | |
| 6977 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | * Insets that determine the actually visible area |
| 6979 | */ |
| 6980 | final Rect mVisibleInsets = new Rect(); |
| 6981 | final Rect mLastVisibleInsets = new Rect(); |
| 6982 | boolean mVisibleInsetsChanged; |
| 6983 | |
| 6984 | /** |
| 6985 | * Insets that are covered by system windows |
| 6986 | */ |
| 6987 | final Rect mContentInsets = new Rect(); |
| 6988 | final Rect mLastContentInsets = new Rect(); |
| 6989 | boolean mContentInsetsChanged; |
| 6990 | |
| 6991 | /** |
| 6992 | * Set to true if we are waiting for this window to receive its |
| 6993 | * given internal insets before laying out other windows based on it. |
| 6994 | */ |
| 6995 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6997 | /** |
| 6998 | * These are the content insets that were given during layout for |
| 6999 | * this window, to be applied to windows behind it. |
| 7000 | */ |
| 7001 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7002 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7003 | /** |
| 7004 | * These are the visible insets that were given during layout for |
| 7005 | * this window, to be applied to windows behind it. |
| 7006 | */ |
| 7007 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7008 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7009 | /** |
| 7010 | * Flag indicating whether the touchable region should be adjusted by |
| 7011 | * the visible insets; if false the area outside the visible insets is |
| 7012 | * NOT touchable, so we must use those to adjust the frame during hit |
| 7013 | * tests. |
| 7014 | */ |
| 7015 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7016 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7017 | // Current transformation being applied. |
| 7018 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 7019 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 7020 | float mHScale=1, mVScale=1; |
| 7021 | float mLastHScale=1, mLastVScale=1; |
| 7022 | final Matrix mTmpMatrix = new Matrix(); |
| 7023 | |
| 7024 | // "Real" frame that the application sees. |
| 7025 | final Rect mFrame = new Rect(); |
| 7026 | final Rect mLastFrame = new Rect(); |
| 7027 | |
| 7028 | final Rect mContainingFrame = new Rect(); |
| 7029 | final Rect mDisplayFrame = new Rect(); |
| 7030 | final Rect mContentFrame = new Rect(); |
| 7031 | final Rect mVisibleFrame = new Rect(); |
| 7032 | |
| 7033 | float mShownAlpha = 1; |
| 7034 | float mAlpha = 1; |
| 7035 | float mLastAlpha = 1; |
| 7036 | |
| 7037 | // Set to true if, when the window gets displayed, it should perform |
| 7038 | // an enter animation. |
| 7039 | boolean mEnterAnimationPending; |
| 7040 | |
| 7041 | // Currently running animation. |
| 7042 | boolean mAnimating; |
| 7043 | boolean mLocalAnimating; |
| 7044 | Animation mAnimation; |
| 7045 | boolean mAnimationIsEntrance; |
| 7046 | boolean mHasTransformation; |
| 7047 | boolean mHasLocalTransformation; |
| 7048 | final Transformation mTransformation = new Transformation(); |
| 7049 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7050 | // If a window showing a wallpaper: the requested offset for the |
| 7051 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 7052 | float mWallpaperX = -1; |
| 7053 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7054 | |
| 7055 | // If a window showing a wallpaper: what fraction of the offset |
| 7056 | // range corresponds to a full virtual screen. |
| 7057 | float mWallpaperXStep = -1; |
| 7058 | float mWallpaperYStep = -1; |
| 7059 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7060 | // Wallpaper windows: pixels offset based on above variables. |
| 7061 | int mXOffset; |
| 7062 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7063 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7064 | // This is set after IWindowSession.relayout() has been called at |
| 7065 | // least once for the window. It allows us to detect the situation |
| 7066 | // where we don't yet have a surface, but should have one soon, so |
| 7067 | // we can give the window focus before waiting for the relayout. |
| 7068 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | // This is set after the Surface has been created but before the |
| 7071 | // window has been drawn. During this time the surface is hidden. |
| 7072 | boolean mDrawPending; |
| 7073 | |
| 7074 | // This is set after the window has finished drawing for the first |
| 7075 | // time but before its surface is shown. The surface will be |
| 7076 | // displayed when the next layout is run. |
| 7077 | boolean mCommitDrawPending; |
| 7078 | |
| 7079 | // This is set during the time after the window's drawing has been |
| 7080 | // committed, and before its surface is actually shown. It is used |
| 7081 | // to delay showing the surface until all windows in a token are ready |
| 7082 | // to be shown. |
| 7083 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7084 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7085 | // Set when the window has been shown in the screen the first time. |
| 7086 | boolean mHasDrawn; |
| 7087 | |
| 7088 | // Currently running an exit animation? |
| 7089 | boolean mExiting; |
| 7090 | |
| 7091 | // Currently on the mDestroySurface list? |
| 7092 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7093 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | // Completely remove from window manager after exit animation? |
| 7095 | boolean mRemoveOnExit; |
| 7096 | |
| 7097 | // Set when the orientation is changing and this window has not yet |
| 7098 | // been updated for the new orientation. |
| 7099 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7100 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7101 | // Is this window now (or just being) removed? |
| 7102 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7103 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7104 | // For debugging, this is the last information given to the surface flinger. |
| 7105 | boolean mSurfaceShown; |
| 7106 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 7107 | int mSurfaceLayer; |
| 7108 | float mSurfaceAlpha; |
| 7109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7110 | WindowState(Session s, IWindow c, WindowToken token, |
| 7111 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 7112 | int viewVisibility) { |
| 7113 | mSession = s; |
| 7114 | mClient = c; |
| 7115 | mToken = token; |
| 7116 | mAttrs.copyFrom(a); |
| 7117 | mViewVisibility = viewVisibility; |
| 7118 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 7119 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7120 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7121 | TAG, "Window " + this + " client=" + c.asBinder() |
| 7122 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 7123 | try { |
| 7124 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 7125 | } catch (RemoteException e) { |
| 7126 | mDeathRecipient = null; |
| 7127 | mAttachedWindow = null; |
| 7128 | mLayoutAttached = false; |
| 7129 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7130 | mIsWallpaper = false; |
| 7131 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7132 | mBaseLayer = 0; |
| 7133 | mSubLayer = 0; |
| 7134 | return; |
| 7135 | } |
| 7136 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7137 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7138 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7139 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7140 | // The multiplier here is to reserve space for multiple |
| 7141 | // windows in the same type layer. |
| 7142 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7143 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7144 | + TYPE_LAYER_OFFSET; |
| 7145 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7146 | mAttachedWindow = attachedWindow; |
| 7147 | mAttachedWindow.mChildWindows.add(this); |
| 7148 | mLayoutAttached = mAttrs.type != |
| 7149 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7150 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7151 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7152 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7153 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7154 | } else { |
| 7155 | // The multiplier here is to reserve space for multiple |
| 7156 | // windows in the same type layer. |
| 7157 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7158 | * TYPE_LAYER_MULTIPLIER |
| 7159 | + TYPE_LAYER_OFFSET; |
| 7160 | mSubLayer = 0; |
| 7161 | mAttachedWindow = null; |
| 7162 | mLayoutAttached = false; |
| 7163 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7164 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7165 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7166 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | WindowState appWin = this; |
| 7170 | while (appWin.mAttachedWindow != null) { |
| 7171 | appWin = mAttachedWindow; |
| 7172 | } |
| 7173 | WindowToken appToken = appWin.mToken; |
| 7174 | while (appToken.appWindowToken == null) { |
| 7175 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7176 | if (parent == null || appToken == parent) { |
| 7177 | break; |
| 7178 | } |
| 7179 | appToken = parent; |
| 7180 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7181 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7182 | mAppToken = appToken.appWindowToken; |
| 7183 | |
| 7184 | mSurface = null; |
| 7185 | mRequestedWidth = 0; |
| 7186 | mRequestedHeight = 0; |
| 7187 | mLastRequestedWidth = 0; |
| 7188 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7189 | mXOffset = 0; |
| 7190 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | mLayer = 0; |
| 7192 | mAnimLayer = 0; |
| 7193 | mLastLayer = 0; |
| 7194 | } |
| 7195 | |
| 7196 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7197 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7198 | TAG, "Attaching " + this + " token=" + mToken |
| 7199 | + ", list=" + mToken.windows); |
| 7200 | mSession.windowAddedLocked(); |
| 7201 | } |
| 7202 | |
| 7203 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7204 | mHaveFrame = true; |
| 7205 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7206 | final Rect container = mContainingFrame; |
| 7207 | container.set(pf); |
| 7208 | |
| 7209 | final Rect display = mDisplayFrame; |
| 7210 | display.set(df); |
| 7211 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7212 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7213 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7214 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7215 | display.intersect(mCompatibleScreenFrame); |
| 7216 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7217 | } |
| 7218 | |
| 7219 | final int pw = container.right - container.left; |
| 7220 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7221 | |
| 7222 | int w,h; |
| 7223 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7224 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7225 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7226 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7227 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7228 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7229 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7230 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7231 | final Rect content = mContentFrame; |
| 7232 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7233 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7234 | final Rect visible = mVisibleFrame; |
| 7235 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7236 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7237 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7238 | final int fw = frame.width(); |
| 7239 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7241 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7242 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7243 | |
| 7244 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7245 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7246 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7247 | |
| 7248 | //System.out.println("Out: " + mFrame); |
| 7249 | |
| 7250 | // Now make sure the window fits in the overall display. |
| 7251 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7253 | // Make sure the content and visible frames are inside of the |
| 7254 | // final window frame. |
| 7255 | if (content.left < frame.left) content.left = frame.left; |
| 7256 | if (content.top < frame.top) content.top = frame.top; |
| 7257 | if (content.right > frame.right) content.right = frame.right; |
| 7258 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7259 | if (visible.left < frame.left) visible.left = frame.left; |
| 7260 | if (visible.top < frame.top) visible.top = frame.top; |
| 7261 | if (visible.right > frame.right) visible.right = frame.right; |
| 7262 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7263 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7264 | final Rect contentInsets = mContentInsets; |
| 7265 | contentInsets.left = content.left-frame.left; |
| 7266 | contentInsets.top = content.top-frame.top; |
| 7267 | contentInsets.right = frame.right-content.right; |
| 7268 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7269 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7270 | final Rect visibleInsets = mVisibleInsets; |
| 7271 | visibleInsets.left = visible.left-frame.left; |
| 7272 | visibleInsets.top = visible.top-frame.top; |
| 7273 | visibleInsets.right = frame.right-visible.right; |
| 7274 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7275 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7276 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7277 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7278 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7279 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7280 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7281 | if (localLOGV) { |
| 7282 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7283 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7284 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | + mRequestedWidth + ", mRequestedheight=" |
| 7286 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7287 | + "): frame=" + mFrame.toShortString() |
| 7288 | + " ci=" + contentInsets.toShortString() |
| 7289 | + " vi=" + visibleInsets.toShortString()); |
| 7290 | //} |
| 7291 | } |
| 7292 | } |
| 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 | public Rect getFrameLw() { |
| 7295 | return mFrame; |
| 7296 | } |
| 7297 | |
| 7298 | public Rect getShownFrameLw() { |
| 7299 | return mShownFrame; |
| 7300 | } |
| 7301 | |
| 7302 | public Rect getDisplayFrameLw() { |
| 7303 | return mDisplayFrame; |
| 7304 | } |
| 7305 | |
| 7306 | public Rect getContentFrameLw() { |
| 7307 | return mContentFrame; |
| 7308 | } |
| 7309 | |
| 7310 | public Rect getVisibleFrameLw() { |
| 7311 | return mVisibleFrame; |
| 7312 | } |
| 7313 | |
| 7314 | public boolean getGivenInsetsPendingLw() { |
| 7315 | return mGivenInsetsPending; |
| 7316 | } |
| 7317 | |
| 7318 | public Rect getGivenContentInsetsLw() { |
| 7319 | return mGivenContentInsets; |
| 7320 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7321 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7322 | public Rect getGivenVisibleInsetsLw() { |
| 7323 | return mGivenVisibleInsets; |
| 7324 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7326 | public WindowManager.LayoutParams getAttrs() { |
| 7327 | return mAttrs; |
| 7328 | } |
| 7329 | |
| 7330 | public int getSurfaceLayer() { |
| 7331 | return mLayer; |
| 7332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | public IApplicationToken getAppToken() { |
| 7335 | return mAppToken != null ? mAppToken.appToken : null; |
| 7336 | } |
| 7337 | |
| 7338 | public boolean hasAppShownWindows() { |
| 7339 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7340 | } |
| 7341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7343 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | TAG, "Setting animation in " + this + ": " + anim); |
| 7345 | mAnimating = false; |
| 7346 | mLocalAnimating = false; |
| 7347 | mAnimation = anim; |
| 7348 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7349 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7350 | } |
| 7351 | |
| 7352 | public void clearAnimation() { |
| 7353 | if (mAnimation != null) { |
| 7354 | mAnimating = true; |
| 7355 | mLocalAnimating = false; |
| 7356 | mAnimation = null; |
| 7357 | } |
| 7358 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7359 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7360 | Surface createSurfaceLocked() { |
| 7361 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7362 | mReportDestroySurface = false; |
| 7363 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7364 | mDrawPending = true; |
| 7365 | mCommitDrawPending = false; |
| 7366 | mReadyToShow = false; |
| 7367 | if (mAppToken != null) { |
| 7368 | mAppToken.allDrawn = false; |
| 7369 | } |
| 7370 | |
| 7371 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7372 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7373 | flags |= Surface.PUSH_BUFFERS; |
| 7374 | } |
| 7375 | |
| 7376 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7377 | flags |= Surface.SECURE; |
| 7378 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7379 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7380 | TAG, "Creating surface in session " |
| 7381 | + mSession.mSurfaceSession + " window " + this |
| 7382 | + " w=" + mFrame.width() |
| 7383 | + " h=" + mFrame.height() + " format=" |
| 7384 | + mAttrs.format + " flags=" + flags); |
| 7385 | |
| 7386 | int w = mFrame.width(); |
| 7387 | int h = mFrame.height(); |
| 7388 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7389 | // for a scaled surface, we always want the requested |
| 7390 | // size. |
| 7391 | w = mRequestedWidth; |
| 7392 | h = mRequestedHeight; |
| 7393 | } |
| 7394 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7395 | // Something is wrong and SurfaceFlinger will not like this, |
| 7396 | // try to revert to sane values |
| 7397 | if (w <= 0) w = 1; |
| 7398 | if (h <= 0) h = 1; |
| 7399 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7400 | mSurfaceShown = false; |
| 7401 | mSurfaceLayer = 0; |
| 7402 | mSurfaceAlpha = 1; |
| 7403 | mSurfaceX = 0; |
| 7404 | mSurfaceY = 0; |
| 7405 | mSurfaceW = w; |
| 7406 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7407 | try { |
| 7408 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7409 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7410 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7411 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7412 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7413 | + mSurface + " IN SESSION " |
| 7414 | + mSession.mSurfaceSession |
| 7415 | + ": pid=" + mSession.mPid + " format=" |
| 7416 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7417 | + Integer.toHexString(flags) |
| 7418 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7419 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7420 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7421 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7422 | return null; |
| 7423 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7424 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7425 | return null; |
| 7426 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7427 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7428 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7429 | TAG, "Got surface: " + mSurface |
| 7430 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7431 | + ", animLayer=" + mAnimLayer); |
| 7432 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7433 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7434 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 7435 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 7436 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7437 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | } |
| 7439 | Surface.openTransaction(); |
| 7440 | try { |
| 7441 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7442 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7443 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7444 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7445 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7446 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7447 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7448 | mSurface.hide(); |
| 7449 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7450 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7451 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7452 | Surface.SURFACE_DITHER); |
| 7453 | } |
| 7454 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7455 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7456 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7457 | } |
| 7458 | mLastHidden = true; |
| 7459 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7460 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7461 | Surface.closeTransaction(); |
| 7462 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7463 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | TAG, "Created surface " + this); |
| 7465 | } |
| 7466 | return mSurface; |
| 7467 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7468 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7469 | void destroySurfaceLocked() { |
| 7470 | // Window is no longer on-screen, so can no longer receive |
| 7471 | // key events... if we were waiting for it to finish |
| 7472 | // handling a key event, the wait is over! |
| 7473 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 7474 | KeyWaiter.RETURN_NOTHING); |
| 7475 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7476 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 7477 | |
| 7478 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7479 | mAppToken.startingDisplayed = false; |
| 7480 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7481 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7482 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7483 | mDrawPending = false; |
| 7484 | mCommitDrawPending = false; |
| 7485 | mReadyToShow = false; |
| 7486 | |
| 7487 | int i = mChildWindows.size(); |
| 7488 | while (i > 0) { |
| 7489 | i--; |
| 7490 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7491 | c.mAttachedHidden = true; |
| 7492 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7493 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7494 | if (mReportDestroySurface) { |
| 7495 | mReportDestroySurface = false; |
| 7496 | mSurfacePendingDestroy = true; |
| 7497 | try { |
| 7498 | mClient.dispatchGetNewSurface(); |
| 7499 | // We'll really destroy on the next time around. |
| 7500 | return; |
| 7501 | } catch (RemoteException e) { |
| 7502 | } |
| 7503 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7505 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7506 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7507 | RuntimeException e = null; |
| 7508 | if (!HIDE_STACK_CRAWLS) { |
| 7509 | e = new RuntimeException(); |
| 7510 | e.fillInStackTrace(); |
| 7511 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7512 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7513 | + mSurface + ", session " + mSession, e); |
| 7514 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7515 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7516 | RuntimeException e = null; |
| 7517 | if (!HIDE_STACK_CRAWLS) { |
| 7518 | e = new RuntimeException(); |
| 7519 | e.fillInStackTrace(); |
| 7520 | } |
| 7521 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7522 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7523 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7524 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7525 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | + " surface " + mSurface + " session " + mSession |
| 7527 | + ": " + e.toString()); |
| 7528 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7529 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7530 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7531 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7532 | } |
| 7533 | } |
| 7534 | |
| 7535 | boolean finishDrawingLocked() { |
| 7536 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7537 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7538 | TAG, "finishDrawingLocked: " + mSurface); |
| 7539 | mCommitDrawPending = true; |
| 7540 | mDrawPending = false; |
| 7541 | return true; |
| 7542 | } |
| 7543 | return false; |
| 7544 | } |
| 7545 | |
| 7546 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7547 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7548 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7549 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7550 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7551 | } |
| 7552 | mCommitDrawPending = false; |
| 7553 | mReadyToShow = true; |
| 7554 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7555 | final AppWindowToken atoken = mAppToken; |
| 7556 | if (atoken == null || atoken.allDrawn || starting) { |
| 7557 | performShowLocked(); |
| 7558 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7559 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | } |
| 7561 | |
| 7562 | // This must be called while inside a transaction. |
| 7563 | boolean performShowLocked() { |
| 7564 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7565 | RuntimeException e = null; |
| 7566 | if (!HIDE_STACK_CRAWLS) { |
| 7567 | e = new RuntimeException(); |
| 7568 | e.fillInStackTrace(); |
| 7569 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7570 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7571 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7572 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7573 | } |
| 7574 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7575 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7576 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7577 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7578 | + " during animation: policyVis=" + mPolicyVisibility |
| 7579 | + " attHidden=" + mAttachedHidden |
| 7580 | + " tok.hiddenRequested=" |
| 7581 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7582 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7584 | + " animating=" + mAnimating |
| 7585 | + " tok animating=" |
| 7586 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7587 | if (!showSurfaceRobustlyLocked(this)) { |
| 7588 | return false; |
| 7589 | } |
| 7590 | mLastAlpha = -1; |
| 7591 | mHasDrawn = true; |
| 7592 | mLastHidden = false; |
| 7593 | mReadyToShow = false; |
| 7594 | enableScreenIfNeededLocked(); |
| 7595 | |
| 7596 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7598 | int i = mChildWindows.size(); |
| 7599 | while (i > 0) { |
| 7600 | i--; |
| 7601 | WindowState c = (WindowState)mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7602 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7603 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7604 | if (c.mSurface != null) { |
| 7605 | c.performShowLocked(); |
| 7606 | // It hadn't been shown, which means layout not |
| 7607 | // performed on it, so now we want to make sure to |
| 7608 | // do a layout. If called from within the transaction |
| 7609 | // loop, this will cause it to restart with a new |
| 7610 | // layout. |
| 7611 | mLayoutNeeded = true; |
| 7612 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | } |
| 7614 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7615 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7616 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7617 | && mAppToken != null) { |
| 7618 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7619 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7620 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7621 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7622 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7624 | // If this initial window is animating, stop it -- we |
| 7625 | // will do an animation to reveal it from behind the |
| 7626 | // starting window, so there is no need for it to also |
| 7627 | // be doing its own stuff. |
| 7628 | if (mAnimation != null) { |
| 7629 | mAnimation = null; |
| 7630 | // Make sure we clean up the animation. |
| 7631 | mAnimating = true; |
| 7632 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7633 | mFinishedStarting.add(mAppToken); |
| 7634 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7635 | } |
| 7636 | mAppToken.updateReportedVisibilityLocked(); |
| 7637 | } |
| 7638 | } |
| 7639 | return true; |
| 7640 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7641 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7642 | // This must be called while inside a transaction. Returns true if |
| 7643 | // there is more animation to run. |
| 7644 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7645 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7646 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7647 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7649 | mHasTransformation = true; |
| 7650 | mHasLocalTransformation = true; |
| 7651 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7652 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7653 | TAG, "Starting animation in " + this + |
| 7654 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7655 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7656 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7657 | mAnimation.setStartTime(currentTime); |
| 7658 | mLocalAnimating = true; |
| 7659 | mAnimating = true; |
| 7660 | } |
| 7661 | mTransformation.clear(); |
| 7662 | final boolean more = mAnimation.getTransformation( |
| 7663 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7664 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7665 | TAG, "Stepped animation in " + this + |
| 7666 | ": more=" + more + ", xform=" + mTransformation); |
| 7667 | if (more) { |
| 7668 | // we're not done! |
| 7669 | return true; |
| 7670 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7671 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7672 | TAG, "Finished animation in " + this + |
| 7673 | " @ " + currentTime); |
| 7674 | mAnimation = null; |
| 7675 | //WindowManagerService.this.dump(); |
| 7676 | } |
| 7677 | mHasLocalTransformation = false; |
| 7678 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7679 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7680 | // When our app token is animating, we kind-of pretend like |
| 7681 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7682 | // part of this check means that we will only do this if |
| 7683 | // our window is not currently exiting, or it is not |
| 7684 | // locally animating itself. The idea being that one that |
| 7685 | // is exiting and doing a local animation should be removed |
| 7686 | // once that animation is done. |
| 7687 | mAnimating = true; |
| 7688 | mHasTransformation = true; |
| 7689 | mTransformation.clear(); |
| 7690 | return false; |
| 7691 | } else if (mHasTransformation) { |
| 7692 | // Little trick to get through the path below to act like |
| 7693 | // we have finished an animation. |
| 7694 | mAnimating = true; |
| 7695 | } else if (isAnimating()) { |
| 7696 | mAnimating = true; |
| 7697 | } |
| 7698 | } else if (mAnimation != null) { |
| 7699 | // If the display is frozen, and there is a pending animation, |
| 7700 | // clear it and make sure we run the cleanup code. |
| 7701 | mAnimating = true; |
| 7702 | mLocalAnimating = true; |
| 7703 | mAnimation = null; |
| 7704 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7705 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7706 | if (!mAnimating && !mLocalAnimating) { |
| 7707 | return false; |
| 7708 | } |
| 7709 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7710 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7711 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7712 | + ", reportedVisible=" |
| 7713 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | mAnimating = false; |
| 7716 | mLocalAnimating = false; |
| 7717 | mAnimation = null; |
| 7718 | mAnimLayer = mLayer; |
| 7719 | if (mIsImWindow) { |
| 7720 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7721 | } else if (mIsWallpaper) { |
| 7722 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7724 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7725 | + " anim layer: " + mAnimLayer); |
| 7726 | mHasTransformation = false; |
| 7727 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7728 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7729 | if (DEBUG_VISIBILITY) { |
| 7730 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7731 | + mPolicyVisibilityAfterAnim); |
| 7732 | } |
| 7733 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7734 | if (!mPolicyVisibility) { |
| 7735 | if (mCurrentFocus == this) { |
| 7736 | mFocusMayChange = true; |
| 7737 | } |
| 7738 | // Window is no longer visible -- make sure if we were waiting |
| 7739 | // for it to be displayed before enabling the display, that |
| 7740 | // we allow the display to be enabled now. |
| 7741 | enableScreenIfNeededLocked(); |
| 7742 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7743 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7744 | mTransformation.clear(); |
| 7745 | if (mHasDrawn |
| 7746 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7747 | && mAppToken != null |
| 7748 | && mAppToken.firstWindowDrawn |
| 7749 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7750 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7751 | + mToken + ": first real window done animating"); |
| 7752 | mFinishedStarting.add(mAppToken); |
| 7753 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7754 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7755 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7756 | finishExit(); |
| 7757 | |
| 7758 | if (mAppToken != null) { |
| 7759 | mAppToken.updateReportedVisibilityLocked(); |
| 7760 | } |
| 7761 | |
| 7762 | return false; |
| 7763 | } |
| 7764 | |
| 7765 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7766 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7767 | TAG, "finishExit in " + this |
| 7768 | + ": exiting=" + mExiting |
| 7769 | + " remove=" + mRemoveOnExit |
| 7770 | + " windowAnimating=" + isWindowAnimating()); |
| 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 | final int N = mChildWindows.size(); |
| 7773 | for (int i=0; i<N; i++) { |
| 7774 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 7775 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7776 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7777 | if (!mExiting) { |
| 7778 | return; |
| 7779 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7781 | if (isWindowAnimating()) { |
| 7782 | return; |
| 7783 | } |
| 7784 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7785 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7786 | TAG, "Exit animation finished in " + this |
| 7787 | + ": remove=" + mRemoveOnExit); |
| 7788 | if (mSurface != null) { |
| 7789 | mDestroySurface.add(this); |
| 7790 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7791 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7792 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7793 | try { |
| 7794 | mSurface.hide(); |
| 7795 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7796 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7797 | } |
| 7798 | mLastHidden = true; |
| 7799 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7800 | } |
| 7801 | mExiting = false; |
| 7802 | if (mRemoveOnExit) { |
| 7803 | mPendingRemove.add(this); |
| 7804 | mRemoveOnExit = false; |
| 7805 | } |
| 7806 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7807 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7808 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7809 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7810 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7811 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7812 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7813 | return true; |
| 7814 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7815 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7816 | void computeShownFrameLocked() { |
| 7817 | final boolean selfTransformation = mHasLocalTransformation; |
| 7818 | Transformation attachedTransformation = |
| 7819 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7820 | ? mAttachedWindow.mTransformation : null; |
| 7821 | Transformation appTransformation = |
| 7822 | (mAppToken != null && mAppToken.hasTransformation) |
| 7823 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7824 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7825 | // Wallpapers are animated based on the "real" window they |
| 7826 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7827 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7828 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7829 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7830 | mWallpaperTarget.mAnimation != null && |
| 7831 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7832 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7833 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7834 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7835 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7836 | } |
| 7837 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7838 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7839 | mWallpaperTarget.mAppToken.animation != null && |
| 7840 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7841 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7842 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7843 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7844 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7845 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7846 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7847 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7848 | if (selfTransformation || attachedTransformation != null |
| 7849 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7850 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7851 | final Rect frame = mFrame; |
| 7852 | final float tmpFloats[] = mTmpFloats; |
| 7853 | final Matrix tmpMatrix = mTmpMatrix; |
| 7854 | |
| 7855 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7856 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7857 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7858 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7859 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7860 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7861 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7862 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7863 | } |
| 7864 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7865 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7866 | } |
| 7867 | |
| 7868 | // "convert" it into SurfaceFlinger's format |
| 7869 | // (a 2x2 matrix + an offset) |
| 7870 | // Here we must not transform the position of the surface |
| 7871 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7872 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7874 | tmpMatrix.getValues(tmpFloats); |
| 7875 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7876 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7877 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7878 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7879 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7880 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7881 | int w = frame.width(); |
| 7882 | int h = frame.height(); |
| 7883 | mShownFrame.set(x, y, x+w, y+h); |
| 7884 | |
| 7885 | // Now set the alpha... but because our current hardware |
| 7886 | // can't do alpha transformation on a non-opaque surface, |
| 7887 | // turn it off if we are running an animation that is also |
| 7888 | // transforming since it is more important to have that |
| 7889 | // animation be smooth. |
| 7890 | mShownAlpha = mAlpha; |
| 7891 | if (!mLimitedAlphaCompositing |
| 7892 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7893 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7894 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7895 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7896 | if (selfTransformation) { |
| 7897 | mShownAlpha *= mTransformation.getAlpha(); |
| 7898 | } |
| 7899 | if (attachedTransformation != null) { |
| 7900 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7901 | } |
| 7902 | if (appTransformation != null) { |
| 7903 | mShownAlpha *= appTransformation.getAlpha(); |
| 7904 | } |
| 7905 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7906 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7907 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7908 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7909 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7910 | TAG, "Continuing animation in " + this + |
| 7911 | ": " + mShownFrame + |
| 7912 | ", alpha=" + mTransformation.getAlpha()); |
| 7913 | return; |
| 7914 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7916 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7917 | if (mXOffset != 0 || mYOffset != 0) { |
| 7918 | mShownFrame.offset(mXOffset, mYOffset); |
| 7919 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7920 | mShownAlpha = mAlpha; |
| 7921 | mDsDx = 1; |
| 7922 | mDtDx = 0; |
| 7923 | mDsDy = 0; |
| 7924 | mDtDy = 1; |
| 7925 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7926 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7927 | /** |
| 7928 | * Is this window visible? It is not visible if there is no |
| 7929 | * surface, or we are in the process of running an exit animation |
| 7930 | * that will remove the surface, or its app token has been hidden. |
| 7931 | */ |
| 7932 | public boolean isVisibleLw() { |
| 7933 | final AppWindowToken atoken = mAppToken; |
| 7934 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7935 | && (atoken == null || !atoken.hiddenRequested) |
| 7936 | && !mExiting && !mDestroying; |
| 7937 | } |
| 7938 | |
| 7939 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7940 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7941 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7942 | * things like window flags that impact the keyguard. |
| 7943 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7944 | * for this "hidden behind keyguard" state rather than overloading |
| 7945 | * mPolicyVisibility. Ungh. |
| 7946 | */ |
| 7947 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7948 | final AppWindowToken atoken = mAppToken; |
| 7949 | return mSurface != null && !mAttachedHidden |
| 7950 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7951 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7952 | && !mExiting && !mDestroying; |
| 7953 | } |
| 7954 | |
| 7955 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7956 | * Is this window visible, ignoring its app token? It is not visible |
| 7957 | * if there is no surface, or we are in the process of running an exit animation |
| 7958 | * that will remove the surface. |
| 7959 | */ |
| 7960 | public boolean isWinVisibleLw() { |
| 7961 | final AppWindowToken atoken = mAppToken; |
| 7962 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7963 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7964 | && !mExiting && !mDestroying; |
| 7965 | } |
| 7966 | |
| 7967 | /** |
| 7968 | * The same as isVisible(), but follows the current hidden state of |
| 7969 | * the associated app token, not the pending requested hidden state. |
| 7970 | */ |
| 7971 | boolean isVisibleNow() { |
| 7972 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7973 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | } |
| 7975 | |
| 7976 | /** |
| 7977 | * Same as isVisible(), but we also count it as visible between the |
| 7978 | * call to IWindowSession.add() and the first relayout(). |
| 7979 | */ |
| 7980 | boolean isVisibleOrAdding() { |
| 7981 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7982 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7983 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7984 | && mPolicyVisibility && !mAttachedHidden |
| 7985 | && (atoken == null || !atoken.hiddenRequested) |
| 7986 | && !mExiting && !mDestroying; |
| 7987 | } |
| 7988 | |
| 7989 | /** |
| 7990 | * Is this window currently on-screen? It is on-screen either if it |
| 7991 | * is visible or it is currently running an animation before no longer |
| 7992 | * being visible. |
| 7993 | */ |
| 7994 | boolean isOnScreen() { |
| 7995 | final AppWindowToken atoken = mAppToken; |
| 7996 | if (atoken != null) { |
| 7997 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7998 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7999 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8000 | } else { |
| 8001 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8002 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8003 | } |
| 8004 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8006 | /** |
| 8007 | * Like isOnScreen(), but we don't return true if the window is part |
| 8008 | * of a transition that has not yet been started. |
| 8009 | */ |
| 8010 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8011 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8012 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8013 | return false; |
| 8014 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8015 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8016 | final boolean animating = atoken != null |
| 8017 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8018 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8019 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 8020 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8021 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8022 | } |
| 8023 | |
| 8024 | /** Is the window or its container currently animating? */ |
| 8025 | boolean isAnimating() { |
| 8026 | final WindowState attached = mAttachedWindow; |
| 8027 | final AppWindowToken atoken = mAppToken; |
| 8028 | return mAnimation != null |
| 8029 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8030 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8031 | (atoken.animation != null |
| 8032 | || atoken.inPendingTransaction)); |
| 8033 | } |
| 8034 | |
| 8035 | /** Is this window currently animating? */ |
| 8036 | boolean isWindowAnimating() { |
| 8037 | return mAnimation != null; |
| 8038 | } |
| 8039 | |
| 8040 | /** |
| 8041 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 8042 | * been drawn. |
| 8043 | */ |
| 8044 | public boolean isDisplayedLw() { |
| 8045 | final AppWindowToken atoken = mAppToken; |
| 8046 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8047 | && !mDrawPending && !mCommitDrawPending |
| 8048 | && ((!mAttachedHidden && |
| 8049 | (atoken == null || !atoken.hiddenRequested)) |
| 8050 | || mAnimating); |
| 8051 | } |
| 8052 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8053 | /** |
| 8054 | * Returns true if the window has a surface that it has drawn a |
| 8055 | * complete UI in to. |
| 8056 | */ |
| 8057 | public boolean isDrawnLw() { |
| 8058 | final AppWindowToken atoken = mAppToken; |
| 8059 | return mSurface != null && !mDestroying |
| 8060 | && !mDrawPending && !mCommitDrawPending; |
| 8061 | } |
| 8062 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8063 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 8064 | boolean shownFrame, boolean onlyOpaque) { |
| 8065 | if (mSurface == null) { |
| 8066 | return false; |
| 8067 | } |
| 8068 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 8069 | return false; |
| 8070 | } |
| 8071 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 8072 | return false; |
| 8073 | } |
| 8074 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8075 | |
| 8076 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8077 | return frame.left <= mCompatibleScreenFrame.left && |
| 8078 | frame.top <= mCompatibleScreenFrame.top && |
| 8079 | frame.right >= mCompatibleScreenFrame.right && |
| 8080 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 8081 | } else { |
| 8082 | return frame.left <= 0 && frame.top <= 0 |
| 8083 | && frame.right >= screenWidth |
| 8084 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8085 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8086 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8087 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8088 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8089 | * Return true if the window is opaque and fully drawn. This indicates |
| 8090 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8091 | */ |
| 8092 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8093 | return (mAttrs.format == PixelFormat.OPAQUE |
| 8094 | || mAttrs.type == TYPE_WALLPAPER) |
| 8095 | && mSurface != null && mAnimation == null |
| 8096 | && (mAppToken == null || mAppToken.animation == null) |
| 8097 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8098 | } |
| 8099 | |
| 8100 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 8101 | return |
| 8102 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8103 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 8104 | // only if it's visible |
| 8105 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8106 | // and only if the application fills the compatible screen |
| 8107 | mFrame.left <= mCompatibleScreenFrame.left && |
| 8108 | mFrame.top <= mCompatibleScreenFrame.top && |
| 8109 | mFrame.right >= mCompatibleScreenFrame.right && |
| 8110 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8111 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8112 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8113 | } |
| 8114 | |
| 8115 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 8116 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8117 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8118 | } |
| 8119 | |
| 8120 | void removeLocked() { |
| 8121 | if (mAttachedWindow != null) { |
| 8122 | mAttachedWindow.mChildWindows.remove(this); |
| 8123 | } |
| 8124 | destroySurfaceLocked(); |
| 8125 | mSession.windowRemovedLocked(); |
| 8126 | try { |
| 8127 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8128 | } catch (RuntimeException e) { |
| 8129 | // Ignore if it has already been removed (usually because |
| 8130 | // we are doing this as part of processing a death note.) |
| 8131 | } |
| 8132 | } |
| 8133 | |
| 8134 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8135 | public void binderDied() { |
| 8136 | try { |
| 8137 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8138 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8139 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8140 | if (win != null) { |
| 8141 | removeWindowLocked(mSession, win); |
| 8142 | } |
| 8143 | } |
| 8144 | } catch (IllegalArgumentException ex) { |
| 8145 | // This will happen if the window has already been |
| 8146 | // removed. |
| 8147 | } |
| 8148 | } |
| 8149 | } |
| 8150 | |
| 8151 | /** Returns true if this window desires key events. */ |
| 8152 | public final boolean canReceiveKeys() { |
| 8153 | return isVisibleOrAdding() |
| 8154 | && (mViewVisibility == View.VISIBLE) |
| 8155 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8156 | } |
| 8157 | |
| 8158 | public boolean hasDrawnLw() { |
| 8159 | return mHasDrawn; |
| 8160 | } |
| 8161 | |
| 8162 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8163 | return showLw(doAnimation, true); |
| 8164 | } |
| 8165 | |
| 8166 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8167 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8168 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8169 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8170 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8171 | if (doAnimation) { |
| 8172 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8173 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8174 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8175 | doAnimation = false; |
| 8176 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8177 | // Check for the case where we are currently visible and |
| 8178 | // not animating; we do not want to do animation at such a |
| 8179 | // point to become visible when we already are. |
| 8180 | doAnimation = false; |
| 8181 | } |
| 8182 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8183 | mPolicyVisibility = true; |
| 8184 | mPolicyVisibilityAfterAnim = true; |
| 8185 | if (doAnimation) { |
| 8186 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8187 | } |
| 8188 | if (requestAnim) { |
| 8189 | requestAnimationLocked(0); |
| 8190 | } |
| 8191 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8192 | } |
| 8193 | |
| 8194 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8195 | return hideLw(doAnimation, true); |
| 8196 | } |
| 8197 | |
| 8198 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8199 | if (doAnimation) { |
| 8200 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8201 | doAnimation = false; |
| 8202 | } |
| 8203 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8204 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8205 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8206 | if (!current) { |
| 8207 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8208 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8209 | if (doAnimation) { |
| 8210 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8211 | if (mAnimation == null) { |
| 8212 | doAnimation = false; |
| 8213 | } |
| 8214 | } |
| 8215 | if (doAnimation) { |
| 8216 | mPolicyVisibilityAfterAnim = false; |
| 8217 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8218 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8219 | mPolicyVisibilityAfterAnim = false; |
| 8220 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8221 | // Window is no longer visible -- make sure if we were waiting |
| 8222 | // for it to be displayed before enabling the display, that |
| 8223 | // we allow the display to be enabled now. |
| 8224 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8225 | if (mCurrentFocus == this) { |
| 8226 | mFocusMayChange = true; |
| 8227 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8228 | } |
| 8229 | if (requestAnim) { |
| 8230 | requestAnimationLocked(0); |
| 8231 | } |
| 8232 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8233 | } |
| 8234 | |
| 8235 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8236 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8237 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8238 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8239 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8240 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8241 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8242 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8243 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8244 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8245 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8246 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8247 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8248 | } |
| 8249 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8250 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8251 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8252 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8253 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8254 | pw.print("="); pw.print(mAnimLayer); |
| 8255 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8256 | if (mSurface != null) { |
| 8257 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8258 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8259 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8260 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8261 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8262 | pw.print(","); pw.print(mSurfaceY); |
| 8263 | pw.print(") "); pw.print(mSurfaceW); |
| 8264 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8265 | } |
| 8266 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8267 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8268 | if (mAppToken != null) { |
| 8269 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8270 | } |
| 8271 | if (mTargetAppToken != null) { |
| 8272 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8273 | } |
| 8274 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8275 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8276 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8277 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8278 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8279 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8280 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8281 | pw.print(mPolicyVisibility); |
| 8282 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8283 | pw.print(mPolicyVisibilityAfterAnim); |
| 8284 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8285 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8286 | if (!mRelayoutCalled) { |
| 8287 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8288 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8289 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8290 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8291 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8292 | if (mXOffset != 0 || mYOffset != 0) { |
| 8293 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8294 | pw.print(" y="); pw.println(mYOffset); |
| 8295 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8296 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8297 | mGivenContentInsets.printShortString(pw); |
| 8298 | pw.print(" mGivenVisibleInsets="); |
| 8299 | mGivenVisibleInsets.printShortString(pw); |
| 8300 | pw.println(); |
| 8301 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8302 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8303 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8304 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8305 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8306 | pw.print(prefix); pw.print("mShownFrame="); |
| 8307 | mShownFrame.printShortString(pw); |
| 8308 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8309 | pw.println(); |
| 8310 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8311 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8312 | pw.println(); |
| 8313 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8314 | mContainingFrame.printShortString(pw); |
| 8315 | pw.print(" mDisplayFrame="); |
| 8316 | mDisplayFrame.printShortString(pw); |
| 8317 | pw.println(); |
| 8318 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8319 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8320 | pw.println(); |
| 8321 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8322 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8323 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8324 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8325 | pw.println(); |
| 8326 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8327 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8328 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8329 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8330 | } |
| 8331 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8332 | || mAnimation != null) { |
| 8333 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8334 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8335 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8336 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8337 | } |
| 8338 | if (mHasTransformation || mHasLocalTransformation) { |
| 8339 | pw.print(prefix); pw.print("XForm: has="); |
| 8340 | pw.print(mHasTransformation); |
| 8341 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8342 | pw.print(" "); mTransformation.printShortString(pw); |
| 8343 | pw.println(); |
| 8344 | } |
| 8345 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8346 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8347 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8348 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8349 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8350 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8351 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8352 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8353 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8354 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8355 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8356 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8357 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8358 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8359 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8360 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8361 | if (mHScale != 1 || mVScale != 1) { |
| 8362 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8363 | pw.print(" mVScale="); pw.println(mVScale); |
| 8364 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8365 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8366 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8367 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8368 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8369 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8370 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8371 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8372 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8373 | } |
| 8374 | |
| 8375 | @Override |
| 8376 | public String toString() { |
| 8377 | return "Window{" |
| 8378 | + Integer.toHexString(System.identityHashCode(this)) |
| 8379 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 8380 | } |
| 8381 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8382 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8383 | // ------------------------------------------------------------- |
| 8384 | // Window Token State |
| 8385 | // ------------------------------------------------------------- |
| 8386 | |
| 8387 | class WindowToken { |
| 8388 | // The actual token. |
| 8389 | final IBinder token; |
| 8390 | |
| 8391 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8392 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8393 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8394 | // Set if this token was explicitly added by a client, so should |
| 8395 | // not be removed when all windows are removed. |
| 8396 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8397 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8398 | // For printing. |
| 8399 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8401 | // If this is an AppWindowToken, this is non-null. |
| 8402 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8404 | // All of the windows associated with this token. |
| 8405 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8406 | |
| 8407 | // Is key dispatching paused for this token? |
| 8408 | boolean paused = false; |
| 8409 | |
| 8410 | // Should this token's windows be hidden? |
| 8411 | boolean hidden; |
| 8412 | |
| 8413 | // Temporary for finding which tokens no longer have visible windows. |
| 8414 | boolean hasVisible; |
| 8415 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8416 | // Set to true when this token is in a pending transaction where it |
| 8417 | // will be shown. |
| 8418 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8419 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8420 | // Set to true when this token is in a pending transaction where it |
| 8421 | // will be hidden. |
| 8422 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8423 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8424 | // Set to true when this token is in a pending transaction where its |
| 8425 | // windows will be put to the bottom of the list. |
| 8426 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8427 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8428 | // Set to true when this token is in a pending transaction where its |
| 8429 | // windows will be put to the top of the list. |
| 8430 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8433 | token = _token; |
| 8434 | windowType = type; |
| 8435 | explicit = _explicit; |
| 8436 | } |
| 8437 | |
| 8438 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8439 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8440 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8441 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8442 | pw.print(" hidden="); pw.print(hidden); |
| 8443 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8444 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8445 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8446 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8447 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8448 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8449 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8450 | } |
| 8451 | |
| 8452 | @Override |
| 8453 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8454 | if (stringName == null) { |
| 8455 | StringBuilder sb = new StringBuilder(); |
| 8456 | sb.append("WindowToken{"); |
| 8457 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8458 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8459 | stringName = sb.toString(); |
| 8460 | } |
| 8461 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8462 | } |
| 8463 | }; |
| 8464 | |
| 8465 | class AppWindowToken extends WindowToken { |
| 8466 | // Non-null only for application tokens. |
| 8467 | final IApplicationToken appToken; |
| 8468 | |
| 8469 | // All of the windows and child windows that are included in this |
| 8470 | // application token. Note this list is NOT sorted! |
| 8471 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8472 | |
| 8473 | int groupId = -1; |
| 8474 | boolean appFullscreen; |
| 8475 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8476 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8477 | // These are used for determining when all windows associated with |
| 8478 | // an activity have been drawn, so they can be made visible together |
| 8479 | // at the same time. |
| 8480 | int lastTransactionSequence = mTransactionSequence-1; |
| 8481 | int numInterestingWindows; |
| 8482 | int numDrawnWindows; |
| 8483 | boolean inPendingTransaction; |
| 8484 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8485 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8486 | // Is this token going to be hidden in a little while? If so, it |
| 8487 | // won't be taken into account for setting the screen orientation. |
| 8488 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8490 | // Is this window's surface needed? This is almost like hidden, except |
| 8491 | // it will sometimes be true a little earlier: when the token has |
| 8492 | // been shown, but is still waiting for its app transition to execute |
| 8493 | // before making its windows shown. |
| 8494 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8496 | // Have we told the window clients to hide themselves? |
| 8497 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8498 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8499 | // Last visibility state we reported to the app token. |
| 8500 | boolean reportedVisible; |
| 8501 | |
| 8502 | // Set to true when the token has been removed from the window mgr. |
| 8503 | boolean removed; |
| 8504 | |
| 8505 | // Have we been asked to have this token keep the screen frozen? |
| 8506 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8507 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8508 | boolean animating; |
| 8509 | Animation animation; |
| 8510 | boolean hasTransformation; |
| 8511 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8512 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8513 | // Offset to the window of all layers in the token, for use by |
| 8514 | // AppWindowToken animations. |
| 8515 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8516 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8517 | // Information about an application starting window if displayed. |
| 8518 | StartingData startingData; |
| 8519 | WindowState startingWindow; |
| 8520 | View startingView; |
| 8521 | boolean startingDisplayed; |
| 8522 | boolean startingMoved; |
| 8523 | boolean firstWindowDrawn; |
| 8524 | |
| 8525 | AppWindowToken(IApplicationToken _token) { |
| 8526 | super(_token.asBinder(), |
| 8527 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8528 | appWindowToken = this; |
| 8529 | appToken = _token; |
| 8530 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8532 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8533 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8534 | TAG, "Setting animation in " + this + ": " + anim); |
| 8535 | animation = anim; |
| 8536 | animating = false; |
| 8537 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8538 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8539 | int zorder = anim.getZAdjustment(); |
| 8540 | int adj = 0; |
| 8541 | if (zorder == Animation.ZORDER_TOP) { |
| 8542 | adj = TYPE_LAYER_OFFSET; |
| 8543 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8544 | adj = -TYPE_LAYER_OFFSET; |
| 8545 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8547 | if (animLayerAdjustment != adj) { |
| 8548 | animLayerAdjustment = adj; |
| 8549 | updateLayers(); |
| 8550 | } |
| 8551 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8552 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8553 | public void setDummyAnimation() { |
| 8554 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8555 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8556 | TAG, "Setting dummy animation in " + this); |
| 8557 | animation = sDummyAnimation; |
| 8558 | } |
| 8559 | } |
| 8560 | |
| 8561 | public void clearAnimation() { |
| 8562 | if (animation != null) { |
| 8563 | animation = null; |
| 8564 | animating = true; |
| 8565 | } |
| 8566 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8568 | void updateLayers() { |
| 8569 | final int N = allAppWindows.size(); |
| 8570 | final int adj = animLayerAdjustment; |
| 8571 | for (int i=0; i<N; i++) { |
| 8572 | WindowState w = allAppWindows.get(i); |
| 8573 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8574 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8575 | + w.mAnimLayer); |
| 8576 | if (w == mInputMethodTarget) { |
| 8577 | setInputMethodAnimLayerAdjustment(adj); |
| 8578 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8579 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8580 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8581 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8582 | } |
| 8583 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8584 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8585 | void sendAppVisibilityToClients() { |
| 8586 | final int N = allAppWindows.size(); |
| 8587 | for (int i=0; i<N; i++) { |
| 8588 | WindowState win = allAppWindows.get(i); |
| 8589 | if (win == startingWindow && clientHidden) { |
| 8590 | // Don't hide the starting window. |
| 8591 | continue; |
| 8592 | } |
| 8593 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8594 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8595 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8596 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8597 | } catch (RemoteException e) { |
| 8598 | } |
| 8599 | } |
| 8600 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8602 | void showAllWindowsLocked() { |
| 8603 | final int NW = allAppWindows.size(); |
| 8604 | for (int i=0; i<NW; i++) { |
| 8605 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8606 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8607 | "performing show on: " + w); |
| 8608 | w.performShowLocked(); |
| 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 | // This must be called while inside a transaction. |
| 8613 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8614 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8615 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8616 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8617 | if (animation == sDummyAnimation) { |
| 8618 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8619 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | // when it is really time to animate, this will be set to |
| 8621 | // a real animation and the next call will execute normally. |
| 8622 | return false; |
| 8623 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8625 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8626 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8627 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8628 | TAG, "Starting animation in " + this + |
| 8629 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8630 | + " scale=" + mTransitionAnimationScale |
| 8631 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8632 | animation.initialize(dw, dh, dw, dh); |
| 8633 | animation.setStartTime(currentTime); |
| 8634 | animating = true; |
| 8635 | } |
| 8636 | transformation.clear(); |
| 8637 | final boolean more = animation.getTransformation( |
| 8638 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8639 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8640 | TAG, "Stepped animation in " + this + |
| 8641 | ": more=" + more + ", xform=" + transformation); |
| 8642 | if (more) { |
| 8643 | // we're done! |
| 8644 | hasTransformation = true; |
| 8645 | return true; |
| 8646 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8647 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8648 | TAG, "Finished animation in " + this + |
| 8649 | " @ " + currentTime); |
| 8650 | animation = null; |
| 8651 | } |
| 8652 | } else if (animation != null) { |
| 8653 | // If the display is frozen, and there is a pending animation, |
| 8654 | // clear it and make sure we run the cleanup code. |
| 8655 | animating = true; |
| 8656 | animation = null; |
| 8657 | } |
| 8658 | |
| 8659 | hasTransformation = false; |
| 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 | if (!animating) { |
| 8662 | return false; |
| 8663 | } |
| 8664 | |
| 8665 | clearAnimation(); |
| 8666 | animating = false; |
| 8667 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8668 | moveInputMethodWindowsIfNeededLocked(true); |
| 8669 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8670 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8671 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8672 | TAG, "Animation done in " + this |
| 8673 | + ": reportedVisible=" + reportedVisible); |
| 8674 | |
| 8675 | transformation.clear(); |
| 8676 | if (animLayerAdjustment != 0) { |
| 8677 | animLayerAdjustment = 0; |
| 8678 | updateLayers(); |
| 8679 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8681 | final int N = windows.size(); |
| 8682 | for (int i=0; i<N; i++) { |
| 8683 | ((WindowState)windows.get(i)).finishExit(); |
| 8684 | } |
| 8685 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8686 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8687 | return false; |
| 8688 | } |
| 8689 | |
| 8690 | void updateReportedVisibilityLocked() { |
| 8691 | if (appToken == null) { |
| 8692 | return; |
| 8693 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8694 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8695 | int numInteresting = 0; |
| 8696 | int numVisible = 0; |
| 8697 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8698 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8699 | 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] | 8700 | final int N = allAppWindows.size(); |
| 8701 | for (int i=0; i<N; i++) { |
| 8702 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8703 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8704 | || win.mViewVisibility != View.VISIBLE |
| 8705 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8706 | continue; |
| 8707 | } |
| 8708 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8709 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8710 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8711 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8712 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8713 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8714 | + " pv=" + win.mPolicyVisibility |
| 8715 | + " dp=" + win.mDrawPending |
| 8716 | + " cdp=" + win.mCommitDrawPending |
| 8717 | + " ah=" + win.mAttachedHidden |
| 8718 | + " th=" |
| 8719 | + (win.mAppToken != null |
| 8720 | ? win.mAppToken.hiddenRequested : false) |
| 8721 | + " a=" + win.mAnimating); |
| 8722 | } |
| 8723 | } |
| 8724 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8725 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8726 | if (!win.isAnimating()) { |
| 8727 | numVisible++; |
| 8728 | } |
| 8729 | nowGone = false; |
| 8730 | } else if (win.isAnimating()) { |
| 8731 | nowGone = false; |
| 8732 | } |
| 8733 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8734 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8735 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8736 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8737 | + numInteresting + " visible=" + numVisible); |
| 8738 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8739 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8740 | TAG, "Visibility changed in " + this |
| 8741 | + ": vis=" + nowVisible); |
| 8742 | reportedVisible = nowVisible; |
| 8743 | Message m = mH.obtainMessage( |
| 8744 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8745 | nowVisible ? 1 : 0, |
| 8746 | nowGone ? 1 : 0, |
| 8747 | this); |
| 8748 | mH.sendMessage(m); |
| 8749 | } |
| 8750 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8751 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8752 | WindowState findMainWindow() { |
| 8753 | int j = windows.size(); |
| 8754 | while (j > 0) { |
| 8755 | j--; |
| 8756 | WindowState win = windows.get(j); |
| 8757 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8758 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8759 | return win; |
| 8760 | } |
| 8761 | } |
| 8762 | return null; |
| 8763 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8764 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8765 | void dump(PrintWriter pw, String prefix) { |
| 8766 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8767 | if (appToken != null) { |
| 8768 | pw.print(prefix); pw.println("app=true"); |
| 8769 | } |
| 8770 | if (allAppWindows.size() > 0) { |
| 8771 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8772 | } |
| 8773 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8774 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8775 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8776 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8777 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8778 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8779 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8780 | if (paused || freezingScreen) { |
| 8781 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8782 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8783 | } |
| 8784 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8785 | || inPendingTransaction || allDrawn) { |
| 8786 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8787 | pw.print(numInterestingWindows); |
| 8788 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8789 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8790 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8791 | } |
| 8792 | if (animating || animation != null) { |
| 8793 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8794 | pw.print(" animation="); pw.println(animation); |
| 8795 | } |
| 8796 | if (animLayerAdjustment != 0) { |
| 8797 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8798 | } |
| 8799 | if (hasTransformation) { |
| 8800 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8801 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8802 | pw.println(); |
| 8803 | } |
| 8804 | if (startingData != null || removed || firstWindowDrawn) { |
| 8805 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8806 | pw.print(" removed="); pw.print(removed); |
| 8807 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8808 | } |
| 8809 | if (startingWindow != null || startingView != null |
| 8810 | || startingDisplayed || startingMoved) { |
| 8811 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8812 | pw.print(" startingView="); pw.print(startingView); |
| 8813 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8814 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8815 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8816 | } |
| 8817 | |
| 8818 | @Override |
| 8819 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8820 | if (stringName == null) { |
| 8821 | StringBuilder sb = new StringBuilder(); |
| 8822 | sb.append("AppWindowToken{"); |
| 8823 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8824 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8825 | stringName = sb.toString(); |
| 8826 | } |
| 8827 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8828 | } |
| 8829 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8830 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8831 | // ------------------------------------------------------------- |
| 8832 | // DummyAnimation |
| 8833 | // ------------------------------------------------------------- |
| 8834 | |
| 8835 | // This is an animation that does nothing: it just immediately finishes |
| 8836 | // itself every time it is called. It is used as a stub animation in cases |
| 8837 | // where we want to synchronize multiple things that may be animating. |
| 8838 | static final class DummyAnimation extends Animation { |
| 8839 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8840 | return false; |
| 8841 | } |
| 8842 | } |
| 8843 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8844 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8845 | // ------------------------------------------------------------- |
| 8846 | // Async Handler |
| 8847 | // ------------------------------------------------------------- |
| 8848 | |
| 8849 | static final class StartingData { |
| 8850 | final String pkg; |
| 8851 | final int theme; |
| 8852 | final CharSequence nonLocalizedLabel; |
| 8853 | final int labelRes; |
| 8854 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8856 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8857 | int _labelRes, int _icon) { |
| 8858 | pkg = _pkg; |
| 8859 | theme = _theme; |
| 8860 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8861 | labelRes = _labelRes; |
| 8862 | icon = _icon; |
| 8863 | } |
| 8864 | } |
| 8865 | |
| 8866 | private final class H extends Handler { |
| 8867 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8868 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8869 | public static final int ANIMATE = 4; |
| 8870 | public static final int ADD_STARTING = 5; |
| 8871 | public static final int REMOVE_STARTING = 6; |
| 8872 | public static final int FINISHED_STARTING = 7; |
| 8873 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8874 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8875 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8876 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8877 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8878 | public static final int FORCE_GC = 15; |
| 8879 | public static final int ENABLE_SCREEN = 16; |
| 8880 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8881 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8883 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8885 | public H() { |
| 8886 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8887 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8888 | @Override |
| 8889 | public void handleMessage(Message msg) { |
| 8890 | switch (msg.what) { |
| 8891 | case REPORT_FOCUS_CHANGE: { |
| 8892 | WindowState lastFocus; |
| 8893 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8894 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8895 | synchronized(mWindowMap) { |
| 8896 | lastFocus = mLastFocus; |
| 8897 | newFocus = mCurrentFocus; |
| 8898 | if (lastFocus == newFocus) { |
| 8899 | // Focus is not changing, so nothing to do. |
| 8900 | return; |
| 8901 | } |
| 8902 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8903 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8904 | // + " to " + newFocus); |
| 8905 | if (newFocus != null && lastFocus != null |
| 8906 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8907 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8908 | mLosingFocus.add(lastFocus); |
| 8909 | lastFocus = null; |
| 8910 | } |
| 8911 | } |
| 8912 | |
| 8913 | if (lastFocus != newFocus) { |
| 8914 | //System.out.println("Changing focus from " + lastFocus |
| 8915 | // + " to " + newFocus); |
| 8916 | if (newFocus != null) { |
| 8917 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8918 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8919 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8920 | } catch (RemoteException e) { |
| 8921 | // Ignore if process has died. |
| 8922 | } |
| 8923 | } |
| 8924 | |
| 8925 | if (lastFocus != null) { |
| 8926 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8927 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8929 | } catch (RemoteException e) { |
| 8930 | // Ignore if process has died. |
| 8931 | } |
| 8932 | } |
| 8933 | } |
| 8934 | } break; |
| 8935 | |
| 8936 | case REPORT_LOSING_FOCUS: { |
| 8937 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8938 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8939 | synchronized(mWindowMap) { |
| 8940 | losers = mLosingFocus; |
| 8941 | mLosingFocus = new ArrayList<WindowState>(); |
| 8942 | } |
| 8943 | |
| 8944 | final int N = losers.size(); |
| 8945 | for (int i=0; i<N; i++) { |
| 8946 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8947 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8948 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8949 | } catch (RemoteException e) { |
| 8950 | // Ignore if process has died. |
| 8951 | } |
| 8952 | } |
| 8953 | } break; |
| 8954 | |
| 8955 | case ANIMATE: { |
| 8956 | synchronized(mWindowMap) { |
| 8957 | mAnimationPending = false; |
| 8958 | performLayoutAndPlaceSurfacesLocked(); |
| 8959 | } |
| 8960 | } break; |
| 8961 | |
| 8962 | case ADD_STARTING: { |
| 8963 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8964 | final StartingData sd = wtoken.startingData; |
| 8965 | |
| 8966 | if (sd == null) { |
| 8967 | // Animation has been canceled... do nothing. |
| 8968 | return; |
| 8969 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8970 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8971 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8972 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8973 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8974 | View view = null; |
| 8975 | try { |
| 8976 | view = mPolicy.addStartingWindow( |
| 8977 | wtoken.token, sd.pkg, |
| 8978 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8979 | sd.icon); |
| 8980 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8981 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8982 | } |
| 8983 | |
| 8984 | if (view != null) { |
| 8985 | boolean abort = false; |
| 8986 | |
| 8987 | synchronized(mWindowMap) { |
| 8988 | if (wtoken.removed || wtoken.startingData == null) { |
| 8989 | // If the window was successfully added, then |
| 8990 | // we need to remove it. |
| 8991 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8992 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8993 | "Aborted starting " + wtoken |
| 8994 | + ": removed=" + wtoken.removed |
| 8995 | + " startingData=" + wtoken.startingData); |
| 8996 | wtoken.startingWindow = null; |
| 8997 | wtoken.startingData = null; |
| 8998 | abort = true; |
| 8999 | } |
| 9000 | } else { |
| 9001 | wtoken.startingView = view; |
| 9002 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9003 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9004 | "Added starting " + wtoken |
| 9005 | + ": startingWindow=" |
| 9006 | + wtoken.startingWindow + " startingView=" |
| 9007 | + wtoken.startingView); |
| 9008 | } |
| 9009 | |
| 9010 | if (abort) { |
| 9011 | try { |
| 9012 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 9013 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9014 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9015 | } |
| 9016 | } |
| 9017 | } |
| 9018 | } break; |
| 9019 | |
| 9020 | case REMOVE_STARTING: { |
| 9021 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9022 | IBinder token = null; |
| 9023 | View view = null; |
| 9024 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9025 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9026 | + wtoken + ": startingWindow=" |
| 9027 | + wtoken.startingWindow + " startingView=" |
| 9028 | + wtoken.startingView); |
| 9029 | if (wtoken.startingWindow != null) { |
| 9030 | view = wtoken.startingView; |
| 9031 | token = wtoken.token; |
| 9032 | wtoken.startingData = null; |
| 9033 | wtoken.startingView = null; |
| 9034 | wtoken.startingWindow = null; |
| 9035 | } |
| 9036 | } |
| 9037 | if (view != null) { |
| 9038 | try { |
| 9039 | mPolicy.removeStartingWindow(token, view); |
| 9040 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9041 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9042 | } |
| 9043 | } |
| 9044 | } break; |
| 9045 | |
| 9046 | case FINISHED_STARTING: { |
| 9047 | IBinder token = null; |
| 9048 | View view = null; |
| 9049 | while (true) { |
| 9050 | synchronized (mWindowMap) { |
| 9051 | final int N = mFinishedStarting.size(); |
| 9052 | if (N <= 0) { |
| 9053 | break; |
| 9054 | } |
| 9055 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9056 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9057 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9058 | "Finished starting " + wtoken |
| 9059 | + ": startingWindow=" + wtoken.startingWindow |
| 9060 | + " startingView=" + wtoken.startingView); |
| 9061 | |
| 9062 | if (wtoken.startingWindow == null) { |
| 9063 | continue; |
| 9064 | } |
| 9065 | |
| 9066 | view = wtoken.startingView; |
| 9067 | token = wtoken.token; |
| 9068 | wtoken.startingData = null; |
| 9069 | wtoken.startingView = null; |
| 9070 | wtoken.startingWindow = null; |
| 9071 | } |
| 9072 | |
| 9073 | try { |
| 9074 | mPolicy.removeStartingWindow(token, view); |
| 9075 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9076 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9077 | } |
| 9078 | } |
| 9079 | } break; |
| 9080 | |
| 9081 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9082 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9083 | |
| 9084 | boolean nowVisible = msg.arg1 != 0; |
| 9085 | boolean nowGone = msg.arg2 != 0; |
| 9086 | |
| 9087 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9088 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9089 | TAG, "Reporting visible in " + wtoken |
| 9090 | + " visible=" + nowVisible |
| 9091 | + " gone=" + nowGone); |
| 9092 | if (nowVisible) { |
| 9093 | wtoken.appToken.windowsVisible(); |
| 9094 | } else { |
| 9095 | wtoken.appToken.windowsGone(); |
| 9096 | } |
| 9097 | } catch (RemoteException ex) { |
| 9098 | } |
| 9099 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9100 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9101 | case WINDOW_FREEZE_TIMEOUT: { |
| 9102 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9103 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9104 | int i = mWindows.size(); |
| 9105 | while (i > 0) { |
| 9106 | i--; |
| 9107 | WindowState w = (WindowState)mWindows.get(i); |
| 9108 | if (w.mOrientationChanging) { |
| 9109 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9110 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9111 | } |
| 9112 | } |
| 9113 | performLayoutAndPlaceSurfacesLocked(); |
| 9114 | } |
| 9115 | break; |
| 9116 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9117 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9118 | case HOLD_SCREEN_CHANGED: { |
| 9119 | Session oldHold; |
| 9120 | Session newHold; |
| 9121 | synchronized (mWindowMap) { |
| 9122 | oldHold = mLastReportedHold; |
| 9123 | newHold = (Session)msg.obj; |
| 9124 | mLastReportedHold = newHold; |
| 9125 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9126 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9127 | if (oldHold != newHold) { |
| 9128 | try { |
| 9129 | if (oldHold != null) { |
| 9130 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 9131 | "window", |
| 9132 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9133 | } |
| 9134 | if (newHold != null) { |
| 9135 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 9136 | "window", |
| 9137 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9138 | } |
| 9139 | } catch (RemoteException e) { |
| 9140 | } |
| 9141 | } |
| 9142 | break; |
| 9143 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9144 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9145 | case APP_TRANSITION_TIMEOUT: { |
| 9146 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9147 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9148 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9149 | "*** APP TRANSITION TIMEOUT"); |
| 9150 | mAppTransitionReady = true; |
| 9151 | mAppTransitionTimeout = true; |
| 9152 | performLayoutAndPlaceSurfacesLocked(); |
| 9153 | } |
| 9154 | } |
| 9155 | break; |
| 9156 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9157 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9158 | case PERSIST_ANIMATION_SCALE: { |
| 9159 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9160 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9161 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9162 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9163 | break; |
| 9164 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9165 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9166 | case FORCE_GC: { |
| 9167 | synchronized(mWindowMap) { |
| 9168 | if (mAnimationPending) { |
| 9169 | // If we are animating, don't do the gc now but |
| 9170 | // delay a bit so we don't interrupt the animation. |
| 9171 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9172 | 2000); |
| 9173 | return; |
| 9174 | } |
| 9175 | // If we are currently rotating the display, it will |
| 9176 | // schedule a new message when done. |
| 9177 | if (mDisplayFrozen) { |
| 9178 | return; |
| 9179 | } |
| 9180 | mFreezeGcPending = 0; |
| 9181 | } |
| 9182 | Runtime.getRuntime().gc(); |
| 9183 | break; |
| 9184 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9186 | case ENABLE_SCREEN: { |
| 9187 | performEnableScreen(); |
| 9188 | break; |
| 9189 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9190 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9191 | case APP_FREEZE_TIMEOUT: { |
| 9192 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9193 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9194 | int i = mAppTokens.size(); |
| 9195 | while (i > 0) { |
| 9196 | i--; |
| 9197 | AppWindowToken tok = mAppTokens.get(i); |
| 9198 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9199 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9200 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9201 | } |
| 9202 | } |
| 9203 | } |
| 9204 | break; |
| 9205 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9206 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9207 | case SEND_NEW_CONFIGURATION: { |
| 9208 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9209 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9210 | break; |
| 9211 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9213 | } |
| 9214 | } |
| 9215 | } |
| 9216 | |
| 9217 | // ------------------------------------------------------------- |
| 9218 | // IWindowManager API |
| 9219 | // ------------------------------------------------------------- |
| 9220 | |
| 9221 | public IWindowSession openSession(IInputMethodClient client, |
| 9222 | IInputContext inputContext) { |
| 9223 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9224 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 9225 | return new Session(client, inputContext); |
| 9226 | } |
| 9227 | |
| 9228 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9229 | synchronized (mWindowMap) { |
| 9230 | // The focus for the client is the window immediately below |
| 9231 | // where we would place the input method window. |
| 9232 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9233 | WindowState imFocus; |
| 9234 | if (idx > 0) { |
| 9235 | imFocus = (WindowState)mWindows.get(idx-1); |
| 9236 | if (imFocus != null) { |
| 9237 | if (imFocus.mSession.mClient != null && |
| 9238 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9239 | return true; |
| 9240 | } |
| 9241 | } |
| 9242 | } |
| 9243 | } |
| 9244 | return false; |
| 9245 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9247 | // ------------------------------------------------------------- |
| 9248 | // Internals |
| 9249 | // ------------------------------------------------------------- |
| 9250 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9251 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9252 | boolean throwOnError) { |
| 9253 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9254 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9255 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9256 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9257 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9258 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9259 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9260 | TAG, "Looking up client " + client + ": " + win); |
| 9261 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9262 | RuntimeException ex = new IllegalArgumentException( |
| 9263 | "Requested window " + client + " does not exist"); |
| 9264 | if (throwOnError) { |
| 9265 | throw ex; |
| 9266 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9267 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9268 | return null; |
| 9269 | } |
| 9270 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9271 | RuntimeException ex = new IllegalArgumentException( |
| 9272 | "Requested window " + client + " is in session " + |
| 9273 | win.mSession + ", not " + session); |
| 9274 | if (throwOnError) { |
| 9275 | throw ex; |
| 9276 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9277 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9278 | return null; |
| 9279 | } |
| 9280 | |
| 9281 | return win; |
| 9282 | } |
| 9283 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9284 | final void rebuildAppWindowListLocked() { |
| 9285 | int NW = mWindows.size(); |
| 9286 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9287 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9288 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9289 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9290 | // First remove all existing app windows. |
| 9291 | i=0; |
| 9292 | while (i < NW) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9293 | WindowState w = (WindowState)mWindows.get(i); |
| 9294 | if (w.mAppToken != null) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9295 | WindowState win = (WindowState)mWindows.remove(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9296 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9297 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9298 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9299 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9300 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9301 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9302 | && lastWallpaper == i-1) { |
| 9303 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9304 | } |
| 9305 | i++; |
| 9306 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9307 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9308 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9309 | // so skip them before adding app tokens. |
| 9310 | lastWallpaper++; |
| 9311 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9312 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9313 | // First add all of the exiting app tokens... these are no longer |
| 9314 | // in the main app list, but still have windows shown. We put them |
| 9315 | // in the back because now that the animation is over we no longer |
| 9316 | // will care about them. |
| 9317 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9318 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9319 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9320 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9321 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9322 | // And add in the still active app tokens in Z order. |
| 9323 | NT = mAppTokens.size(); |
| 9324 | for (int j=0; j<NT; j++) { |
| 9325 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9326 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9327 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9328 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9329 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9330 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9331 | + " windows but added " + i); |
| 9332 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9333 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9334 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9335 | private final void assignLayersLocked() { |
| 9336 | int N = mWindows.size(); |
| 9337 | int curBaseLayer = 0; |
| 9338 | int curLayer = 0; |
| 9339 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9340 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9341 | for (i=0; i<N; i++) { |
| 9342 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9343 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9344 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9346 | w.mLayer = curLayer; |
| 9347 | } else { |
| 9348 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9349 | w.mLayer = curLayer; |
| 9350 | } |
| 9351 | if (w.mTargetAppToken != null) { |
| 9352 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9353 | } else if (w.mAppToken != null) { |
| 9354 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9355 | } else { |
| 9356 | w.mAnimLayer = w.mLayer; |
| 9357 | } |
| 9358 | if (w.mIsImWindow) { |
| 9359 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9360 | } else if (w.mIsWallpaper) { |
| 9361 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9362 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9363 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9364 | + w.mAnimLayer); |
| 9365 | //System.out.println( |
| 9366 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9367 | } |
| 9368 | } |
| 9369 | |
| 9370 | private boolean mInLayout = false; |
| 9371 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9372 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9373 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9374 | throw new RuntimeException("Recursive call!"); |
| 9375 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9376 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9377 | return; |
| 9378 | } |
| 9379 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9380 | if (mWaitingForConfig) { |
| 9381 | // Our configuration has changed (most likely rotation), but we |
| 9382 | // don't yet have the complete configuration to report to |
| 9383 | // applications. Don't do any window layout until we have it. |
| 9384 | return; |
| 9385 | } |
| 9386 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9387 | boolean recoveringMemory = false; |
| 9388 | if (mForceRemoves != null) { |
| 9389 | recoveringMemory = true; |
| 9390 | // Wait a little it for things to settle down, and off we go. |
| 9391 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9392 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9393 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | removeWindowInnerLocked(ws.mSession, ws); |
| 9395 | } |
| 9396 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9397 | 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] | 9398 | Object tmp = new Object(); |
| 9399 | synchronized (tmp) { |
| 9400 | try { |
| 9401 | tmp.wait(250); |
| 9402 | } catch (InterruptedException e) { |
| 9403 | } |
| 9404 | } |
| 9405 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9406 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9407 | mInLayout = true; |
| 9408 | try { |
| 9409 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9410 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9411 | int i = mPendingRemove.size()-1; |
| 9412 | if (i >= 0) { |
| 9413 | while (i >= 0) { |
| 9414 | WindowState w = mPendingRemove.get(i); |
| 9415 | removeWindowInnerLocked(w.mSession, w); |
| 9416 | i--; |
| 9417 | } |
| 9418 | mPendingRemove.clear(); |
| 9419 | |
| 9420 | mInLayout = false; |
| 9421 | assignLayersLocked(); |
| 9422 | mLayoutNeeded = true; |
| 9423 | performLayoutAndPlaceSurfacesLocked(); |
| 9424 | |
| 9425 | } else { |
| 9426 | mInLayout = false; |
| 9427 | if (mLayoutNeeded) { |
| 9428 | requestAnimationLocked(0); |
| 9429 | } |
| 9430 | } |
| 9431 | } catch (RuntimeException e) { |
| 9432 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9433 | 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] | 9434 | } |
| 9435 | } |
| 9436 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9437 | private final int performLayoutLockedInner() { |
| 9438 | if (!mLayoutNeeded) { |
| 9439 | return 0; |
| 9440 | } |
| 9441 | |
| 9442 | mLayoutNeeded = false; |
| 9443 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9444 | final int dw = mDisplay.getWidth(); |
| 9445 | final int dh = mDisplay.getHeight(); |
| 9446 | |
| 9447 | final int N = mWindows.size(); |
| 9448 | int i; |
| 9449 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9450 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9451 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9452 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9453 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9454 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9455 | int seq = mLayoutSeq+1; |
| 9456 | if (seq < 0) seq = 0; |
| 9457 | mLayoutSeq = seq; |
| 9458 | |
| 9459 | // First perform layout of any root windows (not attached |
| 9460 | // to another window). |
| 9461 | int topAttached = -1; |
| 9462 | for (i = N-1; i >= 0; i--) { |
| 9463 | WindowState win = (WindowState) mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9464 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9465 | // Don't do layout of a window if it is not visible, or |
| 9466 | // soon won't be visible, to avoid wasting time and funky |
| 9467 | // changes while a window is animating away. |
| 9468 | final AppWindowToken atoken = win.mAppToken; |
| 9469 | final boolean gone = win.mViewVisibility == View.GONE |
| 9470 | || !win.mRelayoutCalled |
| 9471 | || win.mRootToken.hidden |
| 9472 | || (atoken != null && atoken.hiddenRequested) |
| 9473 | || win.mAttachedHidden |
| 9474 | || win.mExiting || win.mDestroying; |
| 9475 | |
| 9476 | if (!win.mLayoutAttached) { |
| 9477 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 9478 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9479 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9480 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 9481 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9482 | + win.mRelayoutCalled + " hidden=" |
| 9483 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9484 | + (atoken != null && atoken.hiddenRequested) |
| 9485 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9486 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9487 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9488 | // If this view is GONE, then skip it -- keep the current |
| 9489 | // frame, and let the caller know so they can ignore it |
| 9490 | // if they want. (We do the normal layout for INVISIBLE |
| 9491 | // windows, since that means "perform layout as normal, |
| 9492 | // just don't display"). |
| 9493 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9494 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9495 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9496 | win.mLayoutSeq = seq; |
| 9497 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9498 | + win.mFrame + " mContainingFrame=" |
| 9499 | + win.mContainingFrame + " mDisplayFrame=" |
| 9500 | + win.mDisplayFrame); |
| 9501 | } else { |
| 9502 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9503 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9504 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9506 | |
| 9507 | // Now perform layout of attached windows, which usually |
| 9508 | // depend on the position of the window they are attached to. |
| 9509 | // XXX does not deal with windows that are attached to windows |
| 9510 | // that are themselves attached. |
| 9511 | for (i = topAttached; i >= 0; i--) { |
| 9512 | WindowState win = (WindowState) mWindows.get(i); |
| 9513 | |
| 9514 | // If this view is GONE, then skip it -- keep the current |
| 9515 | // frame, and let the caller know so they can ignore it |
| 9516 | // if they want. (We do the normal layout for INVISIBLE |
| 9517 | // windows, since that means "perform layout as normal, |
| 9518 | // just don't display"). |
| 9519 | if (win.mLayoutAttached) { |
| 9520 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9521 | + " mHaveFrame=" + win.mHaveFrame |
| 9522 | + " mViewVisibility=" + win.mViewVisibility |
| 9523 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 9524 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9525 | || !win.mHaveFrame) { |
| 9526 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9527 | win.mLayoutSeq = seq; |
| 9528 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9529 | + win.mFrame + " mContainingFrame=" |
| 9530 | + win.mContainingFrame + " mDisplayFrame=" |
| 9531 | + win.mDisplayFrame); |
| 9532 | } |
| 9533 | } |
| 9534 | } |
| 9535 | |
| 9536 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9537 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9539 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9540 | boolean recoveringMemory) { |
| 9541 | final long currentTime = SystemClock.uptimeMillis(); |
| 9542 | final int dw = mDisplay.getWidth(); |
| 9543 | final int dh = mDisplay.getHeight(); |
| 9544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9545 | int i; |
| 9546 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9547 | if (mFocusMayChange) { |
| 9548 | mFocusMayChange = false; |
| 9549 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9550 | } |
| 9551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9552 | if (mFxSession == null) { |
| 9553 | mFxSession = new SurfaceSession(); |
| 9554 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9555 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9556 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9557 | |
| 9558 | // Initialize state of exiting tokens. |
| 9559 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9560 | mExitingTokens.get(i).hasVisible = false; |
| 9561 | } |
| 9562 | |
| 9563 | // Initialize state of exiting applications. |
| 9564 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9565 | mExitingAppTokens.get(i).hasVisible = false; |
| 9566 | } |
| 9567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9568 | boolean orientationChangeComplete = true; |
| 9569 | Session holdScreen = null; |
| 9570 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9571 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9572 | boolean focusDisplayed = false; |
| 9573 | boolean animating = false; |
| 9574 | |
| 9575 | Surface.openTransaction(); |
| 9576 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9577 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9578 | int repeats = 0; |
| 9579 | int changes = 0; |
| 9580 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9581 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9582 | repeats++; |
| 9583 | if (repeats > 6) { |
| 9584 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9585 | mLayoutNeeded = false; |
| 9586 | break; |
| 9587 | } |
| 9588 | |
| 9589 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9590 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9591 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9592 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9593 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9594 | assignLayersLocked(); |
| 9595 | mLayoutNeeded = true; |
| 9596 | } |
| 9597 | } |
| 9598 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9599 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9600 | if (updateOrientationFromAppTokensLocked()) { |
| 9601 | mLayoutNeeded = true; |
| 9602 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9603 | } |
| 9604 | } |
| 9605 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9606 | mLayoutNeeded = true; |
| 9607 | } |
| 9608 | } |
| 9609 | |
| 9610 | // FIRST LOOP: Perform a layout, if needed. |
| 9611 | if (repeats < 4) { |
| 9612 | changes = performLayoutLockedInner(); |
| 9613 | if (changes != 0) { |
| 9614 | continue; |
| 9615 | } |
| 9616 | } else { |
| 9617 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9618 | changes = 0; |
| 9619 | } |
| 9620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9621 | final int transactionSequence = ++mTransactionSequence; |
| 9622 | |
| 9623 | // Update animations of all applications, including those |
| 9624 | // associated with exiting/removed apps |
| 9625 | boolean tokensAnimating = false; |
| 9626 | final int NAT = mAppTokens.size(); |
| 9627 | for (i=0; i<NAT; i++) { |
| 9628 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9629 | tokensAnimating = true; |
| 9630 | } |
| 9631 | } |
| 9632 | final int NEAT = mExitingAppTokens.size(); |
| 9633 | for (i=0; i<NEAT; i++) { |
| 9634 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9635 | tokensAnimating = true; |
| 9636 | } |
| 9637 | } |
| 9638 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9639 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9640 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9641 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9642 | + transactionSequence + " tokensAnimating=" |
| 9643 | + tokensAnimating); |
| 9644 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9645 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9646 | |
| 9647 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9648 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9649 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9650 | |
| 9651 | mPolicy.beginAnimationLw(dw, dh); |
| 9652 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9653 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9655 | for (i=N-1; i>=0; i--) { |
| 9656 | WindowState w = (WindowState)mWindows.get(i); |
| 9657 | |
| 9658 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9659 | |
| 9660 | if (w.mSurface != null) { |
| 9661 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9662 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9663 | if ((w.mAttrs.flags |
| 9664 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9665 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9666 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9667 | wallpaperMayChange = true; |
| 9668 | } |
| 9669 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9670 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9671 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9672 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9673 | animating = true; |
| 9674 | //w.dump(" "); |
| 9675 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9676 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9677 | wallpaperMayChange = true; |
| 9678 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9679 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9680 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9681 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9682 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9683 | "Animation done that could impact force hide: " |
| 9684 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9685 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9686 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9687 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9688 | forceHiding = true; |
| 9689 | } |
| 9690 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9691 | boolean changed; |
| 9692 | if (forceHiding) { |
| 9693 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9694 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9695 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9696 | } else { |
| 9697 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9698 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9699 | "Now policy shown: " + w); |
| 9700 | if (changed) { |
| 9701 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9702 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9703 | // Assume we will need to animate. If |
| 9704 | // we don't (because the wallpaper will |
| 9705 | // stay with the lock screen), then we will |
| 9706 | // clean up later. |
| 9707 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9708 | if (a != null) { |
| 9709 | w.setAnimation(a); |
| 9710 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9711 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9712 | if (mCurrentFocus == null || |
| 9713 | mCurrentFocus.mLayer < w.mLayer) { |
| 9714 | // We are showing on to of the current |
| 9715 | // focus, so re-evaluate focus to make |
| 9716 | // sure it is correct. |
| 9717 | mFocusMayChange = true; |
| 9718 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9719 | } |
| 9720 | } |
| 9721 | if (changed && (attrs.flags |
| 9722 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9723 | wallpaperMayChange = true; |
| 9724 | } |
| 9725 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9726 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9727 | mPolicy.animatingWindowLw(w, attrs); |
| 9728 | } |
| 9729 | |
| 9730 | final AppWindowToken atoken = w.mAppToken; |
| 9731 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9732 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9733 | atoken.lastTransactionSequence = transactionSequence; |
| 9734 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9735 | atoken.startingDisplayed = false; |
| 9736 | } |
| 9737 | if ((w.isOnScreen() || w.mAttrs.type |
| 9738 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9739 | && !w.mExiting && !w.mDestroying) { |
| 9740 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9741 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9742 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9743 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9744 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9745 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9746 | + " pv=" + w.mPolicyVisibility |
| 9747 | + " dp=" + w.mDrawPending |
| 9748 | + " cdp=" + w.mCommitDrawPending |
| 9749 | + " ah=" + w.mAttachedHidden |
| 9750 | + " th=" + atoken.hiddenRequested |
| 9751 | + " a=" + w.mAnimating); |
| 9752 | } |
| 9753 | } |
| 9754 | if (w != atoken.startingWindow) { |
| 9755 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9756 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9757 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9758 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9759 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9760 | "tokenMayBeDrawn: " + atoken |
| 9761 | + " freezingScreen=" + atoken.freezingScreen |
| 9762 | + " mAppFreezing=" + w.mAppFreezing); |
| 9763 | tokenMayBeDrawn = true; |
| 9764 | } |
| 9765 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9766 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9767 | atoken.startingDisplayed = true; |
| 9768 | } |
| 9769 | } |
| 9770 | } else if (w.mReadyToShow) { |
| 9771 | w.performShowLocked(); |
| 9772 | } |
| 9773 | } |
| 9774 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9775 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9776 | |
| 9777 | if (tokenMayBeDrawn) { |
| 9778 | // See if any windows have been drawn, so they (and others |
| 9779 | // associated with them) can now be shown. |
| 9780 | final int NT = mTokenList.size(); |
| 9781 | for (i=0; i<NT; i++) { |
| 9782 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9783 | if (wtoken == null) { |
| 9784 | continue; |
| 9785 | } |
| 9786 | if (wtoken.freezingScreen) { |
| 9787 | int numInteresting = wtoken.numInterestingWindows; |
| 9788 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9789 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9790 | "allDrawn: " + wtoken |
| 9791 | + " interesting=" + numInteresting |
| 9792 | + " drawn=" + wtoken.numDrawnWindows); |
| 9793 | wtoken.showAllWindowsLocked(); |
| 9794 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9795 | orientationChangeComplete = true; |
| 9796 | } |
| 9797 | } else if (!wtoken.allDrawn) { |
| 9798 | int numInteresting = wtoken.numInterestingWindows; |
| 9799 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9800 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9801 | "allDrawn: " + wtoken |
| 9802 | + " interesting=" + numInteresting |
| 9803 | + " drawn=" + wtoken.numDrawnWindows); |
| 9804 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9805 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9806 | |
| 9807 | // We can now show all of the drawn windows! |
| 9808 | if (!mOpeningApps.contains(wtoken)) { |
| 9809 | wtoken.showAllWindowsLocked(); |
| 9810 | } |
| 9811 | } |
| 9812 | } |
| 9813 | } |
| 9814 | } |
| 9815 | |
| 9816 | // If we are ready to perform an app transition, check through |
| 9817 | // all of the app tokens to be shown and see if they are ready |
| 9818 | // to go. |
| 9819 | if (mAppTransitionReady) { |
| 9820 | int NN = mOpeningApps.size(); |
| 9821 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9822 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9823 | "Checking " + NN + " opening apps (frozen=" |
| 9824 | + mDisplayFrozen + " timeout=" |
| 9825 | + mAppTransitionTimeout + ")..."); |
| 9826 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9827 | // If the display isn't frozen, wait to do anything until |
| 9828 | // all of the apps are ready. Otherwise just go because |
| 9829 | // we'll unfreeze the display when everyone is ready. |
| 9830 | for (i=0; i<NN && goodToGo; i++) { |
| 9831 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9832 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9833 | "Check opening app" + wtoken + ": allDrawn=" |
| 9834 | + wtoken.allDrawn + " startingDisplayed=" |
| 9835 | + wtoken.startingDisplayed); |
| 9836 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9837 | && !wtoken.startingMoved) { |
| 9838 | goodToGo = false; |
| 9839 | } |
| 9840 | } |
| 9841 | } |
| 9842 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9843 | 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] | 9844 | int transit = mNextAppTransition; |
| 9845 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9846 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9847 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9848 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9849 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9850 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9851 | mAppTransitionTimeout = false; |
| 9852 | mStartingIconInTransition = false; |
| 9853 | mSkipAppTransitionAnimation = false; |
| 9854 | |
| 9855 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9856 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9857 | // If there are applications waiting to come to the |
| 9858 | // top of the stack, now is the time to move their windows. |
| 9859 | // (Note that we don't do apps going to the bottom |
| 9860 | // here -- we want to keep their windows in the old |
| 9861 | // Z-order until the animation completes.) |
| 9862 | if (mToTopApps.size() > 0) { |
| 9863 | NN = mAppTokens.size(); |
| 9864 | for (i=0; i<NN; i++) { |
| 9865 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9866 | if (wtoken.sendingToTop) { |
| 9867 | wtoken.sendingToTop = false; |
| 9868 | moveAppWindowsLocked(wtoken, NN, false); |
| 9869 | } |
| 9870 | } |
| 9871 | mToTopApps.clear(); |
| 9872 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9873 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9874 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9875 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9876 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9877 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9878 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9879 | // The top-most window will supply the layout params, |
| 9880 | // and we will determine it below. |
| 9881 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9882 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9883 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9884 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9885 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9886 | "New wallpaper target=" + mWallpaperTarget |
| 9887 | + ", lower target=" + mLowerWallpaperTarget |
| 9888 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9889 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9890 | // Do a first pass through the tokens for two |
| 9891 | // things: |
| 9892 | // (1) Determine if both the closing and opening |
| 9893 | // app token sets are wallpaper targets, in which |
| 9894 | // case special animations are needed |
| 9895 | // (since the wallpaper needs to stay static |
| 9896 | // behind them). |
| 9897 | // (2) Find the layout params of the top-most |
| 9898 | // application window in the tokens, which is |
| 9899 | // what will control the animation theme. |
| 9900 | final int NC = mClosingApps.size(); |
| 9901 | NN = NC + mOpeningApps.size(); |
| 9902 | for (i=0; i<NN; i++) { |
| 9903 | AppWindowToken wtoken; |
| 9904 | int mode; |
| 9905 | if (i < NC) { |
| 9906 | wtoken = mClosingApps.get(i); |
| 9907 | mode = 1; |
| 9908 | } else { |
| 9909 | wtoken = mOpeningApps.get(i-NC); |
| 9910 | mode = 2; |
| 9911 | } |
| 9912 | if (mLowerWallpaperTarget != null) { |
| 9913 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9914 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9915 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9916 | } |
| 9917 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9918 | if (wtoken.appFullscreen) { |
| 9919 | WindowState ws = wtoken.findMainWindow(); |
| 9920 | if (ws != null) { |
| 9921 | // If this is a compatibility mode |
| 9922 | // window, we will always use its anim. |
| 9923 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9924 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9925 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9926 | bestAnimLayer = Integer.MAX_VALUE; |
| 9927 | } else if (ws.mLayer > bestAnimLayer) { |
| 9928 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9929 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9930 | bestAnimLayer = ws.mLayer; |
| 9931 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9932 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9933 | } |
| 9934 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9935 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9936 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9937 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9938 | "Wallpaper animation!"); |
| 9939 | switch (transit) { |
| 9940 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9941 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9942 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9943 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9944 | break; |
| 9945 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9946 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9947 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9948 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9949 | break; |
| 9950 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9951 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9952 | "New transit: " + transit); |
| 9953 | } else if (oldWallpaper != null) { |
| 9954 | // We are transitioning from an activity with |
| 9955 | // a wallpaper to one without. |
| 9956 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9957 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9958 | "New transit away from wallpaper: " + transit); |
| 9959 | } else if (mWallpaperTarget != null) { |
| 9960 | // We are transitioning from an activity without |
| 9961 | // a wallpaper to now showing the wallpaper |
| 9962 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9963 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9964 | "New transit into wallpaper: " + transit); |
| 9965 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9966 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9967 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9968 | mLastEnterAnimToken = animToken; |
| 9969 | mLastEnterAnimParams = animLp; |
| 9970 | } else if (mLastEnterAnimParams != null) { |
| 9971 | animLp = mLastEnterAnimParams; |
| 9972 | mLastEnterAnimToken = null; |
| 9973 | mLastEnterAnimParams = null; |
| 9974 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9975 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9976 | // If all closing windows are obscured, then there is |
| 9977 | // no need to do an animation. This is the case, for |
| 9978 | // example, when this transition is being done behind |
| 9979 | // the lock screen. |
| 9980 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9981 | animLp = null; |
| 9982 | } |
| 9983 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9984 | NN = mOpeningApps.size(); |
| 9985 | for (i=0; i<NN; i++) { |
| 9986 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9987 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9988 | "Now opening app" + wtoken); |
| 9989 | wtoken.reportedVisible = false; |
| 9990 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9991 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9992 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9993 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9994 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9995 | wtoken.showAllWindowsLocked(); |
| 9996 | } |
| 9997 | NN = mClosingApps.size(); |
| 9998 | for (i=0; i<NN; i++) { |
| 9999 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10000 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10001 | "Now closing app" + wtoken); |
| 10002 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10003 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10004 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10005 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10006 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10007 | // Force the allDrawn flag, because we want to start |
| 10008 | // this guy's animations regardless of whether it's |
| 10009 | // gotten drawn. |
| 10010 | wtoken.allDrawn = true; |
| 10011 | } |
| 10012 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10013 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10014 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10015 | mOpeningApps.clear(); |
| 10016 | mClosingApps.clear(); |
| 10017 | |
| 10018 | // This has changed the visibility of windows, so perform |
| 10019 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10020 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10021 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10022 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10023 | assignLayersLocked(); |
| 10024 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10025 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10026 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10027 | } |
| 10028 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10029 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10030 | int adjResult = 0; |
| 10031 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10032 | if (!animating && mAppTransitionRunning) { |
| 10033 | // We have finished the animation of an app transition. To do |
| 10034 | // this, we have delayed a lot of operations like showing and |
| 10035 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10036 | // reflects the correct Z-order, but the window list may now |
| 10037 | // be out of sync with it. So here we will just rebuild the |
| 10038 | // entire app window list. Fun! |
| 10039 | mAppTransitionRunning = false; |
| 10040 | // Clear information about apps that were moving. |
| 10041 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10042 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10043 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10044 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10045 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10046 | moveInputMethodWindowsIfNeededLocked(false); |
| 10047 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10048 | // Since the window list has been rebuilt, focus might |
| 10049 | // have to be recomputed since the actual order of windows |
| 10050 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10051 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10052 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10053 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10054 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10055 | // At this point, there was a window with a wallpaper that |
| 10056 | // was force hiding other windows behind it, but now it |
| 10057 | // is going away. This may be simple -- just animate |
| 10058 | // away the wallpaper and its window -- or it may be |
| 10059 | // hard -- the wallpaper now needs to be shown behind |
| 10060 | // something that was hidden. |
| 10061 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10062 | if (mLowerWallpaperTarget != null |
| 10063 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10064 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10065 | "wallpaperForceHiding changed with lower=" |
| 10066 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10067 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10068 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10069 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10070 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10071 | // The lower target has become hidden before we |
| 10072 | // actually started the animation... let's completely |
| 10073 | // re-evaluate everything. |
| 10074 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10075 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10076 | } |
| 10077 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10078 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10079 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10080 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10081 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10082 | + " NEW: " + mWallpaperTarget |
| 10083 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10084 | if (mLowerWallpaperTarget == null) { |
| 10085 | // Whoops, we don't need a special wallpaper animation. |
| 10086 | // Clear them out. |
| 10087 | forceHiding = false; |
| 10088 | for (i=N-1; i>=0; i--) { |
| 10089 | WindowState w = (WindowState)mWindows.get(i); |
| 10090 | if (w.mSurface != null) { |
| 10091 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10092 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10093 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10094 | forceHiding = true; |
| 10095 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10096 | if (!w.mAnimating) { |
| 10097 | // We set the animation above so it |
| 10098 | // is not yet running. |
| 10099 | w.clearAnimation(); |
| 10100 | } |
| 10101 | } |
| 10102 | } |
| 10103 | } |
| 10104 | } |
| 10105 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10106 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10107 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10108 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10109 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10110 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10111 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10112 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10113 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10114 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10115 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10116 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10117 | assignLayersLocked(); |
| 10118 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10119 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10120 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10121 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10122 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10123 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10124 | if (mFocusMayChange) { |
| 10125 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10126 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10127 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10128 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10129 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10130 | } |
| 10131 | |
| 10132 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10133 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10134 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10135 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10136 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10137 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10138 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10139 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10140 | |
| 10141 | // THIRD LOOP: Update the surfaces of all windows. |
| 10142 | |
| 10143 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10144 | |
| 10145 | boolean obscured = false; |
| 10146 | boolean blurring = false; |
| 10147 | boolean dimming = false; |
| 10148 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10149 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10150 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10151 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10152 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10153 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10154 | for (i=N-1; i>=0; i--) { |
| 10155 | WindowState w = (WindowState)mWindows.get(i); |
| 10156 | |
| 10157 | boolean displayed = false; |
| 10158 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10159 | final int attrFlags = attrs.flags; |
| 10160 | |
| 10161 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10162 | // XXX NOTE: The logic here could be improved. We have |
| 10163 | // the decision about whether to resize a window separated |
| 10164 | // from whether to hide the surface. This can cause us to |
| 10165 | // resize a surface even if we are going to hide it. You |
| 10166 | // can see this by (1) holding device in landscape mode on |
| 10167 | // home screen; (2) tapping browser icon (device will rotate |
| 10168 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10169 | // in step 2 but then immediately hidden, causing us to |
| 10170 | // have to resize and then redraw it again in step 3. It |
| 10171 | // would be nice to figure out how to avoid this, but it is |
| 10172 | // difficult because we do need to resize surfaces in some |
| 10173 | // cases while they are hidden such as when first showing a |
| 10174 | // window. |
| 10175 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10176 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10177 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10178 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10179 | + ": new=" + w.mShownFrame + ", old=" |
| 10180 | + w.mLastShownFrame); |
| 10181 | |
| 10182 | boolean resize; |
| 10183 | int width, height; |
| 10184 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 10185 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 10186 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 10187 | // for a scaled surface, we just want to use |
| 10188 | // the requested size. |
| 10189 | width = w.mRequestedWidth; |
| 10190 | height = w.mRequestedHeight; |
| 10191 | w.mLastRequestedWidth = width; |
| 10192 | w.mLastRequestedHeight = height; |
| 10193 | w.mLastShownFrame.set(w.mShownFrame); |
| 10194 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10195 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10196 | "POS " + w.mShownFrame.left |
| 10197 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10198 | w.mSurfaceX = w.mShownFrame.left; |
| 10199 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10200 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10201 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10202 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10203 | if (!recoveringMemory) { |
| 10204 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10205 | } |
| 10206 | } |
| 10207 | } else { |
| 10208 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 10209 | width = w.mShownFrame.width(); |
| 10210 | height = w.mShownFrame.height(); |
| 10211 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10212 | } |
| 10213 | |
| 10214 | if (resize) { |
| 10215 | if (width < 1) width = 1; |
| 10216 | if (height < 1) height = 1; |
| 10217 | if (w.mSurface != null) { |
| 10218 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10219 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10220 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10221 | + w.mShownFrame.top + " SIZE " |
| 10222 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10223 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10224 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10225 | w.mSurfaceW = width; |
| 10226 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10227 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10228 | w.mSurfaceX = w.mShownFrame.left; |
| 10229 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10230 | w.mSurface.setPosition(w.mShownFrame.left, |
| 10231 | w.mShownFrame.top); |
| 10232 | } catch (RuntimeException e) { |
| 10233 | // If something goes wrong with the surface (such |
| 10234 | // as running out of memory), don't take down the |
| 10235 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10236 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10237 | + "size=(" + width + "x" + height |
| 10238 | + "), pos=(" + w.mShownFrame.left |
| 10239 | + "," + w.mShownFrame.top + ")", e); |
| 10240 | if (!recoveringMemory) { |
| 10241 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10242 | } |
| 10243 | } |
| 10244 | } |
| 10245 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10246 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10247 | w.mContentInsetsChanged = |
| 10248 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10249 | w.mVisibleInsetsChanged = |
| 10250 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10251 | boolean configChanged = |
| 10252 | w.mConfiguration != mCurConfiguration |
| 10253 | && (w.mConfiguration == null |
| 10254 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10255 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10256 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10257 | + mCurConfiguration); |
| 10258 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10259 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10260 | + ": configChanged=" + configChanged |
| 10261 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10262 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10263 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10264 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10265 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10266 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10267 | w.mLastFrame.set(w.mFrame); |
| 10268 | w.mLastContentInsets.set(w.mContentInsets); |
| 10269 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10270 | // If the screen is currently frozen, then keep |
| 10271 | // it frozen until this window draws at its new |
| 10272 | // orientation. |
| 10273 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10274 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10275 | "Resizing while display frozen: " + w); |
| 10276 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10277 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10278 | mWindowsFreezingScreen = true; |
| 10279 | // XXX should probably keep timeout from |
| 10280 | // when we first froze the display. |
| 10281 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10282 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10283 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10284 | } |
| 10285 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10286 | // If the orientation is changing, then we need to |
| 10287 | // hold off on unfreezing the display until this |
| 10288 | // window has been redrawn; to do that, we need |
| 10289 | // to go through the process of getting informed |
| 10290 | // by the application when it has finished drawing. |
| 10291 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10292 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10293 | "Orientation start waiting for draw in " |
| 10294 | + w + ", surface " + w.mSurface); |
| 10295 | w.mDrawPending = true; |
| 10296 | w.mCommitDrawPending = false; |
| 10297 | w.mReadyToShow = false; |
| 10298 | if (w.mAppToken != null) { |
| 10299 | w.mAppToken.allDrawn = false; |
| 10300 | } |
| 10301 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10302 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10303 | "Resizing window " + w + " to " + w.mFrame); |
| 10304 | mResizingWindows.add(w); |
| 10305 | } else if (w.mOrientationChanging) { |
| 10306 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10307 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10308 | "Orientation not waiting for draw in " |
| 10309 | + w + ", surface " + w.mSurface); |
| 10310 | w.mOrientationChanging = false; |
| 10311 | } |
| 10312 | } |
| 10313 | } |
| 10314 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10315 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10316 | if (!w.mLastHidden) { |
| 10317 | //dump(); |
| 10318 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10319 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10320 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10321 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10322 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10323 | try { |
| 10324 | w.mSurface.hide(); |
| 10325 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10326 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10327 | } |
| 10328 | } |
| 10329 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 10330 | } |
| 10331 | // If we are waiting for this window to handle an |
| 10332 | // orientation change, well, it is hidden, so |
| 10333 | // doesn't really matter. Note that this does |
| 10334 | // introduce a potential glitch if the window |
| 10335 | // becomes unhidden before it has drawn for the |
| 10336 | // new orientation. |
| 10337 | if (w.mOrientationChanging) { |
| 10338 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10339 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10340 | "Orientation change skips hidden " + w); |
| 10341 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10342 | } else if (w.mLastLayer != w.mAnimLayer |
| 10343 | || w.mLastAlpha != w.mShownAlpha |
| 10344 | || w.mLastDsDx != w.mDsDx |
| 10345 | || w.mLastDtDx != w.mDtDx |
| 10346 | || w.mLastDsDy != w.mDsDy |
| 10347 | || w.mLastDtDy != w.mDtDy |
| 10348 | || w.mLastHScale != w.mHScale |
| 10349 | || w.mLastVScale != w.mVScale |
| 10350 | || w.mLastHidden) { |
| 10351 | displayed = true; |
| 10352 | w.mLastAlpha = w.mShownAlpha; |
| 10353 | w.mLastLayer = w.mAnimLayer; |
| 10354 | w.mLastDsDx = w.mDsDx; |
| 10355 | w.mLastDtDx = w.mDtDx; |
| 10356 | w.mLastDsDy = w.mDsDy; |
| 10357 | w.mLastDtDy = w.mDtDy; |
| 10358 | w.mLastHScale = w.mHScale; |
| 10359 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10360 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10361 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10362 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10363 | + "," + (w.mDtDx*w.mVScale) |
| 10364 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10365 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10366 | if (w.mSurface != null) { |
| 10367 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10368 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10369 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10370 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10371 | w.mSurface.setLayer(w.mAnimLayer); |
| 10372 | w.mSurface.setMatrix( |
| 10373 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10374 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10375 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10376 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10377 | if (!recoveringMemory) { |
| 10378 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10379 | } |
| 10380 | } |
| 10381 | } |
| 10382 | |
| 10383 | if (w.mLastHidden && !w.mDrawPending |
| 10384 | && !w.mCommitDrawPending |
| 10385 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10386 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10387 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10388 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10389 | + " during relayout"); |
| 10390 | if (showSurfaceRobustlyLocked(w)) { |
| 10391 | w.mHasDrawn = true; |
| 10392 | w.mLastHidden = false; |
| 10393 | } else { |
| 10394 | w.mOrientationChanging = false; |
| 10395 | } |
| 10396 | } |
| 10397 | if (w.mSurface != null) { |
| 10398 | w.mToken.hasVisible = true; |
| 10399 | } |
| 10400 | } else { |
| 10401 | displayed = true; |
| 10402 | } |
| 10403 | |
| 10404 | if (displayed) { |
| 10405 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10406 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10407 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10408 | covered = true; |
| 10409 | } |
| 10410 | } |
| 10411 | if (w.mOrientationChanging) { |
| 10412 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10413 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10414 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10415 | "Orientation continue waiting for draw in " + w); |
| 10416 | } else { |
| 10417 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10418 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10419 | "Orientation change complete in " + w); |
| 10420 | } |
| 10421 | } |
| 10422 | w.mToken.hasVisible = true; |
| 10423 | } |
| 10424 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10425 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10426 | "Orientation change skips hidden " + w); |
| 10427 | w.mOrientationChanging = false; |
| 10428 | } |
| 10429 | |
| 10430 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10431 | |
| 10432 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10433 | focusDisplayed = true; |
| 10434 | } |
| 10435 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10436 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10438 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10439 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10440 | if (w.mSurface != null) { |
| 10441 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10442 | holdScreen = w.mSession; |
| 10443 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10444 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10445 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10446 | screenBrightness = w.mAttrs.screenBrightness; |
| 10447 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10448 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10449 | && buttonBrightness < 0) { |
| 10450 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10451 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10452 | if (canBeSeen |
| 10453 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10454 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10455 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10456 | syswin = true; |
| 10457 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10458 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10459 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10460 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10461 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10462 | // This window completely covers everything behind it, |
| 10463 | // so we want to leave all of them as unblurred (for |
| 10464 | // performance reasons). |
| 10465 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10466 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10467 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10468 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10469 | obscured = true; |
| 10470 | if (mBackgroundFillerSurface == null) { |
| 10471 | try { |
| 10472 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10473 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10474 | 0, dw, dh, |
| 10475 | PixelFormat.OPAQUE, |
| 10476 | Surface.FX_SURFACE_NORMAL); |
| 10477 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10478 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10479 | } |
| 10480 | } |
| 10481 | try { |
| 10482 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10483 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10484 | // Using the same layer as Dim because they will never be shown at the |
| 10485 | // same time. |
| 10486 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10487 | mBackgroundFillerSurface.show(); |
| 10488 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10489 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10490 | } |
| 10491 | backgroundFillerShown = true; |
| 10492 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10493 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10494 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10495 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10496 | + ": blurring=" + blurring |
| 10497 | + " obscured=" + obscured |
| 10498 | + " displayed=" + displayed); |
| 10499 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10500 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10501 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10502 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10503 | if (mDimAnimator == null) { |
| 10504 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10505 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10506 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10507 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10508 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10509 | } |
| 10510 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10511 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10512 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10513 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10514 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10515 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10516 | + mBlurSurface + ": CREATE"); |
| 10517 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10518 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10519 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10520 | -1, 16, 16, |
| 10521 | PixelFormat.OPAQUE, |
| 10522 | Surface.FX_SURFACE_BLUR); |
| 10523 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10524 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10525 | } |
| 10526 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10527 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10528 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10529 | + mBlurSurface + ": pos=(0,0) (" + |
| 10530 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10531 | mBlurSurface.setPosition(0, 0); |
| 10532 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10533 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10534 | if (!mBlurShown) { |
| 10535 | try { |
| 10536 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10537 | + mBlurSurface + ": SHOW"); |
| 10538 | mBlurSurface.show(); |
| 10539 | } catch (RuntimeException e) { |
| 10540 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10541 | } |
| 10542 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10543 | } |
| 10544 | } |
| 10545 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10546 | } |
| 10547 | } |
| 10548 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10549 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10550 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10551 | // This is the wallpaper target and its obscured state |
| 10552 | // changed... make sure the current wallaper's visibility |
| 10553 | // has been updated accordingly. |
| 10554 | updateWallpaperVisibilityLocked(); |
| 10555 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10556 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10557 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10558 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10559 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10560 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10561 | try { |
| 10562 | mBackgroundFillerSurface.hide(); |
| 10563 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10564 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10565 | } |
| 10566 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10567 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10568 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10569 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10570 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10571 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10572 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10573 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10574 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10575 | + ": HIDE"); |
| 10576 | try { |
| 10577 | mBlurSurface.hide(); |
| 10578 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10579 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10580 | } |
| 10581 | mBlurShown = false; |
| 10582 | } |
| 10583 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10584 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10585 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10586 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10587 | } |
| 10588 | |
| 10589 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10590 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10591 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10592 | "With display frozen, orientationChangeComplete=" |
| 10593 | + orientationChangeComplete); |
| 10594 | if (orientationChangeComplete) { |
| 10595 | if (mWindowsFreezingScreen) { |
| 10596 | mWindowsFreezingScreen = false; |
| 10597 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10598 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10599 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10600 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10602 | i = mResizingWindows.size(); |
| 10603 | if (i > 0) { |
| 10604 | do { |
| 10605 | i--; |
| 10606 | WindowState win = mResizingWindows.get(i); |
| 10607 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10608 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10609 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10610 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10611 | boolean configChanged = |
| 10612 | win.mConfiguration != mCurConfiguration |
| 10613 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10614 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10615 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10616 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10617 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10618 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10619 | + " / " + mCurConfiguration + " / 0x" |
| 10620 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10621 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10622 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10623 | win.mClient.resized(win.mFrame.width(), |
| 10624 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10625 | win.mLastVisibleInsets, win.mDrawPending, |
| 10626 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10627 | win.mContentInsetsChanged = false; |
| 10628 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10629 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10630 | } catch (RemoteException e) { |
| 10631 | win.mOrientationChanging = false; |
| 10632 | } |
| 10633 | } while (i > 0); |
| 10634 | mResizingWindows.clear(); |
| 10635 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10637 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10638 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10639 | i = mDestroySurface.size(); |
| 10640 | if (i > 0) { |
| 10641 | do { |
| 10642 | i--; |
| 10643 | WindowState win = mDestroySurface.get(i); |
| 10644 | win.mDestroying = false; |
| 10645 | if (mInputMethodWindow == win) { |
| 10646 | mInputMethodWindow = null; |
| 10647 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10648 | if (win == mWallpaperTarget) { |
| 10649 | wallpaperDestroyed = true; |
| 10650 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10651 | win.destroySurfaceLocked(); |
| 10652 | } while (i > 0); |
| 10653 | mDestroySurface.clear(); |
| 10654 | } |
| 10655 | |
| 10656 | // Time to remove any exiting tokens? |
| 10657 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10658 | WindowToken token = mExitingTokens.get(i); |
| 10659 | if (!token.hasVisible) { |
| 10660 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10661 | if (token.windowType == TYPE_WALLPAPER) { |
| 10662 | mWallpaperTokens.remove(token); |
| 10663 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10664 | } |
| 10665 | } |
| 10666 | |
| 10667 | // Time to remove any exiting applications? |
| 10668 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10669 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10670 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10671 | // Make sure there is no animation running on this token, |
| 10672 | // so any windows associated with it will be removed as |
| 10673 | // soon as their animations are complete |
| 10674 | token.animation = null; |
| 10675 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10676 | mAppTokens.remove(token); |
| 10677 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10678 | if (mLastEnterAnimToken == token) { |
| 10679 | mLastEnterAnimToken = null; |
| 10680 | mLastEnterAnimParams = null; |
| 10681 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10682 | } |
| 10683 | } |
| 10684 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10685 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10686 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10687 | if (!animating && mAppTransitionRunning) { |
| 10688 | // We have finished the animation of an app transition. To do |
| 10689 | // this, we have delayed a lot of operations like showing and |
| 10690 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10691 | // reflects the correct Z-order, but the window list may now |
| 10692 | // be out of sync with it. So here we will just rebuild the |
| 10693 | // entire app window list. Fun! |
| 10694 | mAppTransitionRunning = false; |
| 10695 | needRelayout = true; |
| 10696 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10697 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10698 | // Clear information about apps that were moving. |
| 10699 | mToBottomApps.clear(); |
| 10700 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10701 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10702 | if (focusDisplayed) { |
| 10703 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10704 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10705 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10706 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10707 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10708 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10709 | requestAnimationLocked(0); |
| 10710 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10711 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10712 | } |
| 10713 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 10714 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10715 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10716 | } else { |
| 10717 | mPowerManager.setScreenBrightnessOverride((int) |
| 10718 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10719 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10720 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10721 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10722 | } else { |
| 10723 | mPowerManager.setButtonBrightnessOverride((int) |
| 10724 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10725 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10726 | if (holdScreen != mHoldingScreenOn) { |
| 10727 | mHoldingScreenOn = holdScreen; |
| 10728 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10729 | mH.sendMessage(m); |
| 10730 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10731 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10732 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10733 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10734 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10735 | LocalPowerManager.BUTTON_EVENT, true); |
| 10736 | mTurnOnScreen = false; |
| 10737 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10738 | |
| 10739 | // Check to see if we are now in a state where the screen should |
| 10740 | // be enabled, because the window obscured flags have changed. |
| 10741 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10742 | } |
| 10743 | |
| 10744 | void requestAnimationLocked(long delay) { |
| 10745 | if (!mAnimationPending) { |
| 10746 | mAnimationPending = true; |
| 10747 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10748 | } |
| 10749 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10750 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10751 | /** |
| 10752 | * Have the surface flinger show a surface, robustly dealing with |
| 10753 | * error conditions. In particular, if there is not enough memory |
| 10754 | * to show the surface, then we will try to get rid of other surfaces |
| 10755 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10756 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10757 | * @return Returns true if the surface was successfully shown. |
| 10758 | */ |
| 10759 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10760 | try { |
| 10761 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10762 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10763 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10764 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10765 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10766 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10767 | win.mTurnOnScreen = false; |
| 10768 | mTurnOnScreen = true; |
| 10769 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10770 | } |
| 10771 | return true; |
| 10772 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10773 | 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] | 10774 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10775 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10776 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10777 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10778 | return false; |
| 10779 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10781 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10782 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10783 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10784 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10785 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10786 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10787 | if (mForceRemoves == null) { |
| 10788 | mForceRemoves = new ArrayList<WindowState>(); |
| 10789 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10790 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10791 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10792 | try { |
| 10793 | // There was some problem... first, do a sanity check of the |
| 10794 | // window list to make sure we haven't left any dangling surfaces |
| 10795 | // around. |
| 10796 | int N = mWindows.size(); |
| 10797 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10798 | 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] | 10799 | for (int i=0; i<N; i++) { |
| 10800 | WindowState ws = (WindowState)mWindows.get(i); |
| 10801 | if (ws.mSurface != null) { |
| 10802 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10803 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10804 | + ws + " surface=" + ws.mSurface |
| 10805 | + " token=" + win.mToken |
| 10806 | + " pid=" + ws.mSession.mPid |
| 10807 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10808 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10809 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10810 | ws.mSurface = null; |
| 10811 | mForceRemoves.add(ws); |
| 10812 | i--; |
| 10813 | N--; |
| 10814 | leakedSurface = true; |
| 10815 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10816 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10817 | + ws + " surface=" + ws.mSurface |
| 10818 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10819 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10820 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10821 | ws.mSurface = null; |
| 10822 | leakedSurface = true; |
| 10823 | } |
| 10824 | } |
| 10825 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10826 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10827 | boolean killedApps = false; |
| 10828 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10829 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10830 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10831 | for (int i=0; i<N; i++) { |
| 10832 | WindowState ws = (WindowState)mWindows.get(i); |
| 10833 | if (ws.mSurface != null) { |
| 10834 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10835 | } |
| 10836 | } |
| 10837 | if (pidCandidates.size() > 0) { |
| 10838 | int[] pids = new int[pidCandidates.size()]; |
| 10839 | for (int i=0; i<pids.length; i++) { |
| 10840 | pids[i] = pidCandidates.keyAt(i); |
| 10841 | } |
| 10842 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10843 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10844 | killedApps = true; |
| 10845 | } |
| 10846 | } catch (RemoteException e) { |
| 10847 | } |
| 10848 | } |
| 10849 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10850 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10851 | if (leakedSurface || killedApps) { |
| 10852 | // We managed to reclaim some memory, so get rid of the trouble |
| 10853 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10854 | 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] | 10855 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10856 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10857 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10858 | win.mSurface = null; |
| 10859 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10860 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10861 | try { |
| 10862 | win.mClient.dispatchGetNewSurface(); |
| 10863 | } catch (RemoteException e) { |
| 10864 | } |
| 10865 | } |
| 10866 | } finally { |
| 10867 | Binder.restoreCallingIdentity(callingIdentity); |
| 10868 | } |
| 10869 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10870 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10871 | private boolean updateFocusedWindowLocked(int mode) { |
| 10872 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10873 | if (mCurrentFocus != newFocus) { |
| 10874 | // This check makes sure that we don't already have the focus |
| 10875 | // change message pending. |
| 10876 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10877 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10878 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10879 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10880 | final WindowState oldFocus = mCurrentFocus; |
| 10881 | mCurrentFocus = newFocus; |
| 10882 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10883 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10884 | final WindowState imWindow = mInputMethodWindow; |
| 10885 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10886 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10887 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10888 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10889 | mLayoutNeeded = true; |
| 10890 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10891 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10892 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10893 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10894 | // Client will do the layout, but we need to assign layers |
| 10895 | // for handleNewWindowLocked() below. |
| 10896 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10897 | } |
| 10898 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10899 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10900 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10901 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 10902 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10903 | return true; |
| 10904 | } |
| 10905 | return false; |
| 10906 | } |
| 10907 | |
| 10908 | private WindowState computeFocusedWindowLocked() { |
| 10909 | WindowState result = null; |
| 10910 | WindowState win; |
| 10911 | |
| 10912 | int i = mWindows.size() - 1; |
| 10913 | int nextAppIndex = mAppTokens.size()-1; |
| 10914 | WindowToken nextApp = nextAppIndex >= 0 |
| 10915 | ? mAppTokens.get(nextAppIndex) : null; |
| 10916 | |
| 10917 | while (i >= 0) { |
| 10918 | win = (WindowState)mWindows.get(i); |
| 10919 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10920 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10921 | TAG, "Looking for focus: " + i |
| 10922 | + " = " + win |
| 10923 | + ", flags=" + win.mAttrs.flags |
| 10924 | + ", canReceive=" + win.canReceiveKeys()); |
| 10925 | |
| 10926 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10928 | // If this window's application has been removed, just skip it. |
| 10929 | if (thisApp != null && thisApp.removed) { |
| 10930 | i--; |
| 10931 | continue; |
| 10932 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10933 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10934 | // If there is a focused app, don't allow focus to go to any |
| 10935 | // windows below it. If this is an application window, step |
| 10936 | // through the app tokens until we find its app. |
| 10937 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10938 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10939 | int origAppIndex = nextAppIndex; |
| 10940 | while (nextAppIndex > 0) { |
| 10941 | if (nextApp == mFocusedApp) { |
| 10942 | // Whoops, we are below the focused app... no focus |
| 10943 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10944 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10945 | TAG, "Reached focused app: " + mFocusedApp); |
| 10946 | return null; |
| 10947 | } |
| 10948 | nextAppIndex--; |
| 10949 | nextApp = mAppTokens.get(nextAppIndex); |
| 10950 | if (nextApp == thisApp) { |
| 10951 | break; |
| 10952 | } |
| 10953 | } |
| 10954 | if (thisApp != nextApp) { |
| 10955 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10956 | // happen, but if it does we can get totally hosed... |
| 10957 | // so restart at the original app. |
| 10958 | nextAppIndex = origAppIndex; |
| 10959 | nextApp = mAppTokens.get(nextAppIndex); |
| 10960 | } |
| 10961 | } |
| 10962 | |
| 10963 | // Dispatch to this window if it is wants key events. |
| 10964 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10965 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10966 | TAG, "Found focus @ " + i + " = " + win); |
| 10967 | result = win; |
| 10968 | break; |
| 10969 | } |
| 10970 | |
| 10971 | i--; |
| 10972 | } |
| 10973 | |
| 10974 | return result; |
| 10975 | } |
| 10976 | |
| 10977 | private void startFreezingDisplayLocked() { |
| 10978 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10979 | // Freezing the display also suspends key event delivery, to |
| 10980 | // keep events from going astray while the display is reconfigured. |
| 10981 | // If someone has changed orientation again while the screen is |
| 10982 | // still frozen, the events will continue to be blocked while the |
| 10983 | // successive orientation change is processed. To prevent spurious |
| 10984 | // ANRs, we reset the event dispatch timeout in this case. |
| 10985 | synchronized (mKeyWaiter) { |
| 10986 | mKeyWaiter.mWasFrozen = true; |
| 10987 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10988 | return; |
| 10989 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10990 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10991 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10993 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10994 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10995 | if (mFreezeGcPending != 0) { |
| 10996 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10997 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10998 | mH.removeMessages(H.FORCE_GC); |
| 10999 | Runtime.getRuntime().gc(); |
| 11000 | mFreezeGcPending = now; |
| 11001 | } |
| 11002 | } else { |
| 11003 | mFreezeGcPending = now; |
| 11004 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11006 | mDisplayFrozen = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11007 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11008 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11009 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11010 | mAppTransitionReady = true; |
| 11011 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11012 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11013 | if (PROFILE_ORIENTATION) { |
| 11014 | File file = new File("/data/system/frozen"); |
| 11015 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11016 | } |
| 11017 | Surface.freezeDisplay(0); |
| 11018 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11020 | private void stopFreezingDisplayLocked() { |
| 11021 | if (!mDisplayFrozen) { |
| 11022 | return; |
| 11023 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11024 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11025 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11026 | return; |
| 11027 | } |
| 11028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11029 | mDisplayFrozen = false; |
| 11030 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11031 | if (PROFILE_ORIENTATION) { |
| 11032 | Debug.stopMethodTracing(); |
| 11033 | } |
| 11034 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11035 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 11036 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 11037 | // too because regular key delivery processing should resume immediately. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11038 | synchronized (mKeyWaiter) { |
| 11039 | mKeyWaiter.mWasFrozen = true; |
| 11040 | mKeyWaiter.notifyAll(); |
| 11041 | } |
| 11042 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11043 | // While the display is frozen we don't re-compute the orientation |
| 11044 | // to avoid inconsistent states. However, something interesting |
| 11045 | // could have actually changed during that time so re-evaluate it |
| 11046 | // now to catch that. |
| 11047 | if (updateOrientationFromAppTokensLocked()) { |
| 11048 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 11049 | } |
| 11050 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11051 | // A little kludge: a lot could have happened while the |
| 11052 | // display was frozen, so now that we are coming back we |
| 11053 | // do a gc so that any remote references the system |
| 11054 | // processes holds on others can be released if they are |
| 11055 | // no longer needed. |
| 11056 | mH.removeMessages(H.FORCE_GC); |
| 11057 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11058 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11059 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11060 | mScreenFrozenLock.release(); |
| 11061 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11062 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11063 | @Override |
| 11064 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11065 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11066 | != PackageManager.PERMISSION_GRANTED) { |
| 11067 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11068 | + Binder.getCallingPid() |
| 11069 | + ", uid=" + Binder.getCallingUid()); |
| 11070 | return; |
| 11071 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11072 | |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11073 | pw.println("Input State:"); |
| 11074 | mQueue.dump(pw, " "); |
| 11075 | pw.println(" "); |
| 11076 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11077 | synchronized(mWindowMap) { |
| 11078 | pw.println("Current Window Manager state:"); |
| 11079 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 11080 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11081 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11082 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11083 | w.dump(pw, " "); |
| 11084 | } |
| 11085 | if (mInputMethodDialogs.size() > 0) { |
| 11086 | pw.println(" "); |
| 11087 | pw.println(" Input method dialogs:"); |
| 11088 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11089 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11090 | 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] | 11091 | } |
| 11092 | } |
| 11093 | if (mPendingRemove.size() > 0) { |
| 11094 | pw.println(" "); |
| 11095 | pw.println(" Remove pending for:"); |
| 11096 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11097 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11098 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11099 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11100 | w.dump(pw, " "); |
| 11101 | } |
| 11102 | } |
| 11103 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11104 | pw.println(" "); |
| 11105 | pw.println(" Windows force removing:"); |
| 11106 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11107 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11108 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11109 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11110 | w.dump(pw, " "); |
| 11111 | } |
| 11112 | } |
| 11113 | if (mDestroySurface.size() > 0) { |
| 11114 | pw.println(" "); |
| 11115 | pw.println(" Windows waiting to destroy their surface:"); |
| 11116 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11117 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11118 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11119 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11120 | w.dump(pw, " "); |
| 11121 | } |
| 11122 | } |
| 11123 | if (mLosingFocus.size() > 0) { |
| 11124 | pw.println(" "); |
| 11125 | pw.println(" Windows losing focus:"); |
| 11126 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11127 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11128 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11129 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11130 | w.dump(pw, " "); |
| 11131 | } |
| 11132 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11133 | if (mResizingWindows.size() > 0) { |
| 11134 | pw.println(" "); |
| 11135 | pw.println(" Windows waiting to resize:"); |
| 11136 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11137 | WindowState w = mResizingWindows.get(i); |
| 11138 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11139 | pw.print(w); pw.println(":"); |
| 11140 | w.dump(pw, " "); |
| 11141 | } |
| 11142 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11143 | if (mSessions.size() > 0) { |
| 11144 | pw.println(" "); |
| 11145 | pw.println(" All active sessions:"); |
| 11146 | Iterator<Session> it = mSessions.iterator(); |
| 11147 | while (it.hasNext()) { |
| 11148 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11149 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11150 | s.dump(pw, " "); |
| 11151 | } |
| 11152 | } |
| 11153 | if (mTokenMap.size() > 0) { |
| 11154 | pw.println(" "); |
| 11155 | pw.println(" All tokens:"); |
| 11156 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11157 | while (it.hasNext()) { |
| 11158 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11159 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11160 | token.dump(pw, " "); |
| 11161 | } |
| 11162 | } |
| 11163 | if (mTokenList.size() > 0) { |
| 11164 | pw.println(" "); |
| 11165 | pw.println(" Window token list:"); |
| 11166 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11167 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 11168 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11169 | } |
| 11170 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11171 | if (mWallpaperTokens.size() > 0) { |
| 11172 | pw.println(" "); |
| 11173 | pw.println(" Wallpaper tokens:"); |
| 11174 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11175 | WindowToken token = mWallpaperTokens.get(i); |
| 11176 | pw.print(" Wallpaper #"); pw.print(i); |
| 11177 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11178 | token.dump(pw, " "); |
| 11179 | } |
| 11180 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11181 | if (mAppTokens.size() > 0) { |
| 11182 | pw.println(" "); |
| 11183 | pw.println(" Application tokens in Z order:"); |
| 11184 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11185 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11186 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11187 | } |
| 11188 | } |
| 11189 | if (mFinishedStarting.size() > 0) { |
| 11190 | pw.println(" "); |
| 11191 | pw.println(" Finishing start of application tokens:"); |
| 11192 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11193 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11194 | pw.print(" Finished Starting #"); pw.print(i); |
| 11195 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11196 | token.dump(pw, " "); |
| 11197 | } |
| 11198 | } |
| 11199 | if (mExitingTokens.size() > 0) { |
| 11200 | pw.println(" "); |
| 11201 | pw.println(" Exiting tokens:"); |
| 11202 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11203 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11204 | pw.print(" Exiting #"); pw.print(i); |
| 11205 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11206 | token.dump(pw, " "); |
| 11207 | } |
| 11208 | } |
| 11209 | if (mExitingAppTokens.size() > 0) { |
| 11210 | pw.println(" "); |
| 11211 | pw.println(" Exiting application tokens:"); |
| 11212 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11213 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11214 | pw.print(" Exiting App #"); pw.print(i); |
| 11215 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11216 | token.dump(pw, " "); |
| 11217 | } |
| 11218 | } |
| 11219 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11220 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11221 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11222 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11223 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11224 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11225 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11226 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11227 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11228 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11229 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11230 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11231 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11232 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11233 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11234 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11235 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11236 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11237 | if (mDimAnimator != null) { |
| 11238 | mDimAnimator.printTo(pw); |
| 11239 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11240 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11241 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11242 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11243 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11244 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11245 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11246 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11247 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11248 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11249 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11250 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11251 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11252 | pw.print(" mRotation="); pw.print(mRotation); |
| 11253 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11254 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11255 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11256 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11257 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11258 | pw.print(" mNextAppTransition=0x"); |
| 11259 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11260 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11261 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11262 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11263 | if (mNextAppTransitionPackage != null) { |
| 11264 | pw.print(" mNextAppTransitionPackage="); |
| 11265 | pw.print(mNextAppTransitionPackage); |
| 11266 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11267 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11268 | pw.print(", mNextAppTransitionExit=0x"); |
| 11269 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11270 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11271 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11272 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11273 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11274 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11275 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11276 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11277 | if (mOpeningApps.size() > 0) { |
| 11278 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11279 | } |
| 11280 | if (mClosingApps.size() > 0) { |
| 11281 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11282 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11283 | if (mToTopApps.size() > 0) { |
| 11284 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11285 | } |
| 11286 | if (mToBottomApps.size() > 0) { |
| 11287 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11288 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11289 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11290 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11291 | pw.println(" KeyWaiter state:"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11292 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 11293 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 11294 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 11295 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 11296 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 11297 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11298 | } |
| 11299 | } |
| 11300 | |
| 11301 | public void monitor() { |
| 11302 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11303 | synchronized (mKeyguardTokenWatcher) { } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11304 | synchronized (mKeyWaiter) { } |
| 11305 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11306 | |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11307 | public void virtualKeyFeedback(KeyEvent event) { |
| 11308 | mPolicy.keyFeedbackFromInput(event); |
| 11309 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11310 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11311 | /** |
| 11312 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11313 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11314 | */ |
| 11315 | private static class DimAnimator { |
| 11316 | Surface mDimSurface; |
| 11317 | boolean mDimShown = false; |
| 11318 | float mDimCurrentAlpha; |
| 11319 | float mDimTargetAlpha; |
| 11320 | float mDimDeltaPerMs; |
| 11321 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11322 | |
| 11323 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11324 | |
| 11325 | DimAnimator (SurfaceSession session) { |
| 11326 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11327 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11328 | + mDimSurface + ": CREATE"); |
| 11329 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11330 | mDimSurface = new Surface(session, 0, |
| 11331 | "DimSurface", |
| 11332 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11333 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11334 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11335 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11336 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11337 | } |
| 11338 | } |
| 11339 | } |
| 11340 | |
| 11341 | /** |
| 11342 | * Show the dim surface. |
| 11343 | */ |
| 11344 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11345 | if (!mDimShown) { |
| 11346 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11347 | dw + "x" + dh + ")"); |
| 11348 | mDimShown = true; |
| 11349 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11350 | mLastDimWidth = dw; |
| 11351 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11352 | mDimSurface.setPosition(0, 0); |
| 11353 | mDimSurface.setSize(dw, dh); |
| 11354 | mDimSurface.show(); |
| 11355 | } catch (RuntimeException e) { |
| 11356 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11357 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11358 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11359 | mLastDimWidth = dw; |
| 11360 | mLastDimHeight = dh; |
| 11361 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11362 | } |
| 11363 | } |
| 11364 | |
| 11365 | /** |
| 11366 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11367 | * {@link updateSurface} after all windows are examined. |
| 11368 | */ |
| 11369 | void updateParameters(WindowState w, long currentTime) { |
| 11370 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11371 | |
| 11372 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11373 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11374 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11375 | if (mDimTargetAlpha != target) { |
| 11376 | // If the desired dim level has changed, then |
| 11377 | // start an animation to it. |
| 11378 | mLastDimAnimTime = currentTime; |
| 11379 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11380 | ? w.mAnimation.computeDurationHint() |
| 11381 | : DEFAULT_DIM_DURATION; |
| 11382 | if (target > mDimTargetAlpha) { |
| 11383 | // This is happening behind the activity UI, |
| 11384 | // so we can make it run a little longer to |
| 11385 | // give a stronger impression without disrupting |
| 11386 | // the user. |
| 11387 | duration *= DIM_DURATION_MULTIPLIER; |
| 11388 | } |
| 11389 | if (duration < 1) { |
| 11390 | // Don't divide by zero |
| 11391 | duration = 1; |
| 11392 | } |
| 11393 | mDimTargetAlpha = target; |
| 11394 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11395 | } |
| 11396 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11397 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11398 | /** |
| 11399 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11400 | * false when the animation is finished and the dim surface is hidden. |
| 11401 | */ |
| 11402 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11403 | if (!dimming) { |
| 11404 | if (mDimTargetAlpha != 0) { |
| 11405 | mLastDimAnimTime = currentTime; |
| 11406 | mDimTargetAlpha = 0; |
| 11407 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11408 | } |
| 11409 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11410 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11411 | boolean animating = false; |
| 11412 | if (mLastDimAnimTime != 0) { |
| 11413 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11414 | * (currentTime-mLastDimAnimTime); |
| 11415 | boolean more = true; |
| 11416 | if (displayFrozen) { |
| 11417 | // If the display is frozen, there is no reason to animate. |
| 11418 | more = false; |
| 11419 | } else if (mDimDeltaPerMs > 0) { |
| 11420 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11421 | more = false; |
| 11422 | } |
| 11423 | } else if (mDimDeltaPerMs < 0) { |
| 11424 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11425 | more = false; |
| 11426 | } |
| 11427 | } else { |
| 11428 | more = false; |
| 11429 | } |
| 11430 | |
| 11431 | // Do we need to continue animating? |
| 11432 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11433 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11434 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11435 | mLastDimAnimTime = currentTime; |
| 11436 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11437 | animating = true; |
| 11438 | } else { |
| 11439 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11440 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11441 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11442 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11443 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11444 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11445 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11446 | + ": HIDE"); |
| 11447 | try { |
| 11448 | mDimSurface.hide(); |
| 11449 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11450 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11451 | } |
| 11452 | mDimShown = false; |
| 11453 | } |
| 11454 | } |
| 11455 | } |
| 11456 | return animating; |
| 11457 | } |
| 11458 | |
| 11459 | public void printTo(PrintWriter pw) { |
| 11460 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11461 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11462 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11463 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11464 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11465 | } |
| 11466 | } |
| 11467 | |
| 11468 | /** |
| 11469 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11470 | * This is used for opening/closing transition for apps in compatible mode. |
| 11471 | */ |
| 11472 | private static class FadeInOutAnimation extends Animation { |
| 11473 | int mWidth; |
| 11474 | boolean mFadeIn; |
| 11475 | |
| 11476 | public FadeInOutAnimation(boolean fadeIn) { |
| 11477 | setInterpolator(new AccelerateInterpolator()); |
| 11478 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11479 | mFadeIn = fadeIn; |
| 11480 | } |
| 11481 | |
| 11482 | @Override |
| 11483 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11484 | float x = interpolatedTime; |
| 11485 | if (!mFadeIn) { |
| 11486 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11487 | } |
| 11488 | if (x < 0.5) { |
| 11489 | // move the window out of the screen. |
| 11490 | t.getMatrix().setTranslate(mWidth, 0); |
| 11491 | } else { |
| 11492 | t.getMatrix().setTranslate(0, 0);// show |
| 11493 | t.setAlpha((x - 0.5f) * 2); |
| 11494 | } |
| 11495 | } |
| 11496 | |
| 11497 | @Override |
| 11498 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11499 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11500 | mWidth = width; |
| 11501 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11502 | |
| 11503 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11504 | public int getZAdjustment() { |
| 11505 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11506 | } |
| 11507 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11508 | } |