| 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; |
| 46 | import com.android.internal.view.IInputContext; |
| 47 | import com.android.internal.view.IInputMethodClient; |
| 48 | import com.android.internal.view.IInputMethodManager; |
| 49 | import com.android.server.KeyInputQueue.QueuedEvent; |
| 50 | import com.android.server.am.BatteryStatsService; |
| 51 | |
| 52 | import android.Manifest; |
| 53 | import android.app.ActivityManagerNative; |
| 54 | import android.app.IActivityManager; |
| 55 | import android.content.Context; |
| 56 | import android.content.pm.ActivityInfo; |
| 57 | import android.content.pm.PackageManager; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 58 | import android.content.res.CompatibilityInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.res.Configuration; |
| 60 | import android.graphics.Matrix; |
| 61 | import android.graphics.PixelFormat; |
| 62 | import android.graphics.Rect; |
| 63 | import android.graphics.Region; |
| 64 | import android.os.BatteryStats; |
| 65 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 66 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.os.Debug; |
| 68 | import android.os.Handler; |
| 69 | import android.os.IBinder; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 70 | import android.os.LatencyTimer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.LocalPowerManager; |
| 72 | import android.os.Looper; |
| 73 | import android.os.Message; |
| 74 | import android.os.Parcel; |
| 75 | import android.os.ParcelFileDescriptor; |
| 76 | import android.os.Power; |
| 77 | import android.os.PowerManager; |
| 78 | import android.os.Process; |
| 79 | import android.os.RemoteException; |
| 80 | import android.os.ServiceManager; |
| 81 | import android.os.SystemClock; |
| 82 | import android.os.SystemProperties; |
| 83 | import android.os.TokenWatcher; |
| 84 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 85 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.util.EventLog; |
| 87 | import android.util.Log; |
| 88 | import android.util.SparseIntArray; |
| 89 | import android.view.Display; |
| 90 | import android.view.Gravity; |
| 91 | import android.view.IApplicationToken; |
| 92 | import android.view.IOnKeyguardExitResult; |
| 93 | import android.view.IRotationWatcher; |
| 94 | import android.view.IWindow; |
| 95 | import android.view.IWindowManager; |
| 96 | import android.view.IWindowSession; |
| 97 | import android.view.KeyEvent; |
| 98 | import android.view.MotionEvent; |
| 99 | import android.view.RawInputEvent; |
| 100 | import android.view.Surface; |
| 101 | import android.view.SurfaceSession; |
| 102 | import android.view.View; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 103 | import android.view.ViewConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.view.ViewTreeObserver; |
| 105 | import android.view.WindowManager; |
| 106 | import android.view.WindowManagerImpl; |
| 107 | import android.view.WindowManagerPolicy; |
| 108 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 109 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.animation.Animation; |
| 111 | import android.view.animation.AnimationUtils; |
| 112 | import android.view.animation.Transformation; |
| 113 | |
| 114 | import java.io.BufferedWriter; |
| 115 | import java.io.File; |
| 116 | import java.io.FileDescriptor; |
| 117 | import java.io.IOException; |
| 118 | import java.io.OutputStream; |
| 119 | import java.io.OutputStreamWriter; |
| 120 | import java.io.PrintWriter; |
| 121 | import java.io.StringWriter; |
| 122 | import java.net.Socket; |
| 123 | import java.util.ArrayList; |
| 124 | import java.util.HashMap; |
| 125 | import java.util.HashSet; |
| 126 | import java.util.Iterator; |
| 127 | import java.util.List; |
| 128 | |
| 129 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 130 | public class WindowManagerService extends IWindowManager.Stub |
| 131 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | static final String TAG = "WindowManager"; |
| 133 | static final boolean DEBUG = false; |
| 134 | static final boolean DEBUG_FOCUS = false; |
| 135 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 136 | static final boolean DEBUG_LAYOUT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | static final boolean DEBUG_LAYERS = false; |
| 138 | static final boolean DEBUG_INPUT = false; |
| 139 | static final boolean DEBUG_INPUT_METHOD = false; |
| 140 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 141 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | static final boolean DEBUG_ORIENTATION = false; |
| 143 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 144 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 145 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 146 | static final boolean DEBUG_WALLPAPER = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 148 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 149 | static final boolean MEASURE_LATENCY = false; |
| 150 | static private LatencyTimer lt; |
| 151 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | static final boolean PROFILE_ORIENTATION = false; |
| 153 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 154 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 155 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 157 | static final int KEY_REPEAT_DELAY = 50; |
| 158 | |
| 159 | /** How much to multiply the policy's type layer, to reserve room |
| 160 | * for multiple windows of the same type and Z-ordering adjustment |
| 161 | * with TYPE_LAYER_OFFSET. */ |
| 162 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 165 | * or below others in the same layer. */ |
| 166 | static final int TYPE_LAYER_OFFSET = 1000; |
| 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 | /** How much to increment the layer for each window, to reserve room |
| 169 | * for effect surfaces between them. |
| 170 | */ |
| 171 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 172 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | /** The maximum length we will accept for a loaded animation duration: |
| 174 | * this is 10 seconds. |
| 175 | */ |
| 176 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 177 | |
| 178 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 179 | * value to another, when no window animation is driving it. |
| 180 | */ |
| 181 | static final int DEFAULT_DIM_DURATION = 200; |
| 182 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 183 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 184 | * compatible windows. |
| 185 | */ |
| 186 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 189 | */ |
| 190 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 191 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 192 | static final int INJECT_FAILED = 0; |
| 193 | static final int INJECT_SUCCEEDED = 1; |
| 194 | static final int INJECT_NO_PERMISSION = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 197 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 198 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 199 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 200 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 201 | /** The minimum time between dispatching touch events. */ |
| 202 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 203 | |
| 204 | // Last touch event time |
| 205 | long mLastTouchEventTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 206 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 207 | // Last touch event type |
| 208 | int mLastTouchEventType = OTHER_EVENT; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 209 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 210 | // Time to wait before calling useractivity again. This saves CPU usage |
| 211 | // when we get a flood of touch events. |
| 212 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 213 | |
| 214 | // Last time we call user activity |
| 215 | long mLastUserActivityCallTime = 0; |
| 216 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 217 | // Last time we updated battery stats |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 218 | long mLastBatteryStatsCallTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 219 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 221 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
| 223 | /** |
| 224 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 225 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 226 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 227 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 229 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 231 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 232 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | public void acquired() { |
| 234 | mPolicy.enableKeyguard(false); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 235 | mKeyguardDisabled = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | } |
| 237 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 238 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 239 | synchronized (mKeyguardTokenWatcher) { |
| 240 | mKeyguardDisabled = false; |
| 241 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | }; |
| 245 | |
| 246 | final Context mContext; |
| 247 | |
| 248 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 249 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 253 | |
| 254 | final IActivityManager mActivityManager; |
| 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 IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | /** |
| 259 | * All currently active sessions with clients. |
| 260 | */ |
| 261 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | /** |
| 264 | * Mapping from an IWindow IBinder to the server's Window object. |
| 265 | * This is also used as the lock for all of our state. |
| 266 | */ |
| 267 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 268 | |
| 269 | /** |
| 270 | * Mapping from a token IBinder to a WindowToken object. |
| 271 | */ |
| 272 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 273 | new HashMap<IBinder, WindowToken>(); |
| 274 | |
| 275 | /** |
| 276 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 277 | * over them. |
| 278 | */ |
| 279 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 280 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | /** |
| 282 | * Window tokens that are in the process of exiting, but still |
| 283 | * on screen for animations. |
| 284 | */ |
| 285 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 286 | |
| 287 | /** |
| 288 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 289 | * controlling the ordering of windows in different applications. This |
| 290 | * contains WindowToken objects. |
| 291 | */ |
| 292 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 293 | |
| 294 | /** |
| 295 | * Application tokens that are in the process of exiting, but still |
| 296 | * on screen for animations. |
| 297 | */ |
| 298 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 299 | |
| 300 | /** |
| 301 | * List of window tokens that have finished starting their application, |
| 302 | * and now need to have the policy remove their windows. |
| 303 | */ |
| 304 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 305 | |
| 306 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 307 | * This was the app token that was used to retrieve the last enter |
| 308 | * animation. It will be used for the next exit animation. |
| 309 | */ |
| 310 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 311 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 312 | /** |
| 313 | * These were the layout params used to retrieve the last enter animation. |
| 314 | * They will be used for the next exit animation. |
| 315 | */ |
| 316 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 317 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 318 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | * Z-ordered (bottom-most first) list of all Window objects. |
| 320 | */ |
| 321 | final ArrayList mWindows = new ArrayList(); |
| 322 | |
| 323 | /** |
| 324 | * Windows that are being resized. Used so we can tell the client about |
| 325 | * the resize after closing the transaction in which we resized the |
| 326 | * underlying surface. |
| 327 | */ |
| 328 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 329 | |
| 330 | /** |
| 331 | * Windows whose animations have ended and now must be removed. |
| 332 | */ |
| 333 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 334 | |
| 335 | /** |
| 336 | * Windows whose surface should be destroyed. |
| 337 | */ |
| 338 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 339 | |
| 340 | /** |
| 341 | * Windows that have lost input focus and are waiting for the new |
| 342 | * focus window to be displayed before they are told about this. |
| 343 | */ |
| 344 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 345 | |
| 346 | /** |
| 347 | * This is set when we have run out of memory, and will either be an empty |
| 348 | * list or contain windows that need to be force removed. |
| 349 | */ |
| 350 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 351 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 353 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 355 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | Surface mBlurSurface; |
| 357 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 358 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 360 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | final float[] mTmpFloats = new float[9]; |
| 362 | |
| 363 | boolean mSafeMode; |
| 364 | boolean mDisplayEnabled = false; |
| 365 | boolean mSystemBooted = false; |
| 366 | int mRotation = 0; |
| 367 | int mRequestedRotation = 0; |
| 368 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 369 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | ArrayList<IRotationWatcher> mRotationWatchers |
| 371 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | boolean mLayoutNeeded = true; |
| 374 | boolean mAnimationPending = false; |
| 375 | boolean mDisplayFrozen = false; |
| 376 | boolean mWindowsFreezingScreen = false; |
| 377 | long mFreezeGcPending = 0; |
| 378 | int mAppsFreezingScreen = 0; |
| 379 | |
| 380 | // This is held as long as we have the screen frozen, to give us time to |
| 381 | // perform a rotation animation when turning off shows the lock screen which |
| 382 | // changes the orientation. |
| 383 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | // State management of app transitions. When we are preparing for a |
| 386 | // transition, mNextAppTransition will be the kind of transition to |
| 387 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 388 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 389 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 390 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 391 | String mNextAppTransitionPackage; |
| 392 | int mNextAppTransitionEnter; |
| 393 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 395 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | boolean mAppTransitionTimeout = false; |
| 397 | boolean mStartingIconInTransition = false; |
| 398 | boolean mSkipAppTransitionAnimation = false; |
| 399 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 400 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 401 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 402 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | //flag to detect fat touch events |
| 405 | boolean mFatTouch = false; |
| 406 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 407 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | H mH = new H(); |
| 409 | |
| 410 | WindowState mCurrentFocus = null; |
| 411 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 412 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | // This just indicates the window the input method is on top of, not |
| 414 | // necessarily the window its input is going to. |
| 415 | WindowState mInputMethodTarget = null; |
| 416 | WindowState mUpcomingInputMethodTarget = null; |
| 417 | boolean mInputMethodTargetWaitingAnim; |
| 418 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | WindowState mInputMethodWindow = null; |
| 421 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 422 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 423 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 424 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 425 | // If non-null, this is the currently visible window that is associated |
| 426 | // with the wallpaper. |
| 427 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 428 | // If non-null, we are in the middle of animating from one wallpaper target |
| 429 | // to another, and this is the lower one in Z-order. |
| 430 | WindowState mLowerWallpaperTarget = null; |
| 431 | // If non-null, we are in the middle of animating from one wallpaper target |
| 432 | // to another, and this is the higher one in Z-order. |
| 433 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 434 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 435 | float mLastWallpaperX = -1; |
| 436 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 437 | float mLastWallpaperXStep = -1; |
| 438 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 439 | boolean mSendingPointersToWallpaper = false; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 440 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 441 | // changing its scroll position. |
| 442 | WindowState mWaitingOnWallpaper; |
| 443 | // The last time we had a timeout when waiting for a wallpaper. |
| 444 | long mLastWallpaperTimeoutTime; |
| 445 | // We give a wallpaper up to 150ms to finish scrolling. |
| 446 | static final long WALLPAPER_TIMEOUT = 150; |
| 447 | // Time we wait after a timeout before trying to wait again. |
| 448 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | AppWindowToken mFocusedApp = null; |
| 451 | |
| 452 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 453 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | float mWindowAnimationScale = 1.0f; |
| 455 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 456 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 458 | final KeyQ mQueue; |
| 459 | final InputDispatcherThread mInputThread; |
| 460 | |
| 461 | // Who is holding the screen on. |
| 462 | Session mHoldingScreenOn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 463 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 464 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | /** |
| 467 | * Whether the UI is currently running in touch mode (not showing |
| 468 | * navigational focus because the user is directly pressing the screen). |
| 469 | */ |
| 470 | boolean mInTouchMode = false; |
| 471 | |
| 472 | private ViewServer mViewServer; |
| 473 | |
| 474 | final Rect mTempRect = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 475 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 476 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 477 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 478 | |
| 479 | // The frame use to limit the size of the app running in compatibility mode. |
| 480 | Rect mCompatibleScreenFrame = new Rect(); |
| 481 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 482 | Surface mBackgroundFillerSurface = null; |
| 483 | boolean mBackgroundFillerShown = false; |
| 484 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | public static WindowManagerService main(Context context, |
| 486 | PowerManagerService pm, boolean haveInputMethods) { |
| 487 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 488 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | synchronized (thr) { |
| 491 | while (thr.mService == null) { |
| 492 | try { |
| 493 | thr.wait(); |
| 494 | } catch (InterruptedException e) { |
| 495 | } |
| 496 | } |
| 497 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 498 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | return thr.mService; |
| 500 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 501 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | static class WMThread extends Thread { |
| 503 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | private final Context mContext; |
| 506 | private final PowerManagerService mPM; |
| 507 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 508 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | public WMThread(Context context, PowerManagerService pm, |
| 510 | boolean haveInputMethods) { |
| 511 | super("WindowManager"); |
| 512 | mContext = context; |
| 513 | mPM = pm; |
| 514 | mHaveInputMethods = haveInputMethods; |
| 515 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 516 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | public void run() { |
| 518 | Looper.prepare(); |
| 519 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 520 | mHaveInputMethods); |
| 521 | android.os.Process.setThreadPriority( |
| 522 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 523 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | synchronized (this) { |
| 525 | mService = s; |
| 526 | notifyAll(); |
| 527 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 528 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | Looper.loop(); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | static class PolicyThread extends Thread { |
| 534 | private final WindowManagerPolicy mPolicy; |
| 535 | private final WindowManagerService mService; |
| 536 | private final Context mContext; |
| 537 | private final PowerManagerService mPM; |
| 538 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 539 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | public PolicyThread(WindowManagerPolicy policy, |
| 541 | WindowManagerService service, Context context, |
| 542 | PowerManagerService pm) { |
| 543 | super("WindowManagerPolicy"); |
| 544 | mPolicy = policy; |
| 545 | mService = service; |
| 546 | mContext = context; |
| 547 | mPM = pm; |
| 548 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | public void run() { |
| 551 | Looper.prepare(); |
| 552 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| 553 | // Log.VERBOSE, "WindowManagerPolicy")); |
| 554 | android.os.Process.setThreadPriority( |
| 555 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 556 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | synchronized (this) { |
| 559 | mRunning = true; |
| 560 | notifyAll(); |
| 561 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 562 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | Looper.loop(); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | private WindowManagerService(Context context, PowerManagerService pm, |
| 568 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 569 | if (MEASURE_LATENCY) { |
| 570 | lt = new LatencyTimer(100, 1000); |
| 571 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 572 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | mContext = context; |
| 574 | mHaveInputMethods = haveInputMethods; |
| 575 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 576 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | mPowerManager = pm; |
| 579 | mPowerManager.setPolicy(mPolicy); |
| 580 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 581 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 582 | "SCREEN_FROZEN"); |
| 583 | mScreenFrozenLock.setReferenceCounted(false); |
| 584 | |
| 585 | mActivityManager = ActivityManagerNative.getDefault(); |
| 586 | mBatteryStats = BatteryStatsService.getService(); |
| 587 | |
| 588 | // Get persisted window scale setting |
| 589 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 590 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 591 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 592 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 593 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 594 | int max_events_per_sec = 35; |
| 595 | try { |
| 596 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 597 | .get("windowsmgr.max_events_per_sec")); |
| 598 | if (max_events_per_sec < 1) { |
| 599 | max_events_per_sec = 35; |
| 600 | } |
| 601 | } catch (NumberFormatException e) { |
| 602 | } |
| 603 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 604 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | mQueue = new KeyQ(); |
| 606 | |
| 607 | mInputThread = new InputDispatcherThread(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 610 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | synchronized (thr) { |
| 613 | while (!thr.mRunning) { |
| 614 | try { |
| 615 | thr.wait(); |
| 616 | } catch (InterruptedException e) { |
| 617 | } |
| 618 | } |
| 619 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | mInputThread.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 622 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | // Add ourself to the Watchdog monitors. |
| 624 | Watchdog.getInstance().addMonitor(this); |
| 625 | } |
| 626 | |
| 627 | @Override |
| 628 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 629 | throws RemoteException { |
| 630 | try { |
| 631 | return super.onTransact(code, data, reply, flags); |
| 632 | } catch (RuntimeException e) { |
| 633 | // The window manager only throws security exceptions, so let's |
| 634 | // log all others. |
| 635 | if (!(e instanceof SecurityException)) { |
| 636 | Log.e(TAG, "Window Manager Crash", e); |
| 637 | } |
| 638 | throw e; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | private void placeWindowAfter(Object pos, WindowState window) { |
| 643 | final int i = mWindows.indexOf(pos); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 644 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | TAG, "Adding window " + window + " at " |
| 646 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 647 | mWindows.add(i+1, window); |
| 648 | } |
| 649 | |
| 650 | private void placeWindowBefore(Object pos, WindowState window) { |
| 651 | final int i = mWindows.indexOf(pos); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 652 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | TAG, "Adding window " + window + " at " |
| 654 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 655 | mWindows.add(i, window); |
| 656 | } |
| 657 | |
| 658 | //This method finds out the index of a window that has the same app token as |
| 659 | //win. used for z ordering the windows in mWindows |
| 660 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 661 | //use a local variable to cache mWindows |
| 662 | ArrayList localmWindows = mWindows; |
| 663 | int jmax = localmWindows.size(); |
| 664 | if(jmax == 0) { |
| 665 | return -1; |
| 666 | } |
| 667 | for(int j = (jmax-1); j >= 0; j--) { |
| 668 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 669 | if(wentry.mAppToken == win.mAppToken) { |
| 670 | return j; |
| 671 | } |
| 672 | } |
| 673 | return -1; |
| 674 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 675 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 677 | final IWindow client = win.mClient; |
| 678 | final WindowToken token = win.mToken; |
| 679 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | final int N = localmWindows.size(); |
| 682 | final WindowState attached = win.mAttachedWindow; |
| 683 | int i; |
| 684 | if (attached == null) { |
| 685 | int tokenWindowsPos = token.windows.size(); |
| 686 | if (token.appWindowToken != null) { |
| 687 | int index = tokenWindowsPos-1; |
| 688 | if (index >= 0) { |
| 689 | // If this application has existing windows, we |
| 690 | // simply place the new window on top of them... but |
| 691 | // keep the starting window on top. |
| 692 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 693 | // Base windows go behind everything else. |
| 694 | placeWindowBefore(token.windows.get(0), win); |
| 695 | tokenWindowsPos = 0; |
| 696 | } else { |
| 697 | AppWindowToken atoken = win.mAppToken; |
| 698 | if (atoken != null && |
| 699 | token.windows.get(index) == atoken.startingWindow) { |
| 700 | placeWindowBefore(token.windows.get(index), win); |
| 701 | tokenWindowsPos--; |
| 702 | } else { |
| 703 | int newIdx = findIdxBasedOnAppTokens(win); |
| 704 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 705 | //there is a window above this one associated with the same |
| 706 | //apptoken note that the window could be a floating window |
| 707 | //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] | 708 | //windows associated with this token. |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 709 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 710 | TAG, "Adding window " + win + " at " |
| 711 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 712 | localmWindows.add(newIdx+1, win); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 713 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | } else { |
| 717 | if (localLOGV) Log.v( |
| 718 | TAG, "Figuring out where to add app window " |
| 719 | + client.asBinder() + " (token=" + token + ")"); |
| 720 | // Figure out where the window should go, based on the |
| 721 | // order of applications. |
| 722 | final int NA = mAppTokens.size(); |
| 723 | Object pos = null; |
| 724 | for (i=NA-1; i>=0; i--) { |
| 725 | AppWindowToken t = mAppTokens.get(i); |
| 726 | if (t == token) { |
| 727 | i--; |
| 728 | break; |
| 729 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 730 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 731 | // We haven't reached the token yet; if this token |
| 732 | // is not going to the bottom and has windows, we can |
| 733 | // use it as an anchor for when we do reach the token. |
| 734 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | pos = t.windows.get(0); |
| 736 | } |
| 737 | } |
| 738 | // We now know the index into the apps. If we found |
| 739 | // an app window above, that gives us the position; else |
| 740 | // we need to look some more. |
| 741 | if (pos != null) { |
| 742 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 743 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 745 | if (atoken != null) { |
| 746 | final int NC = atoken.windows.size(); |
| 747 | if (NC > 0) { |
| 748 | WindowState bottom = atoken.windows.get(0); |
| 749 | if (bottom.mSubLayer < 0) { |
| 750 | pos = bottom; |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | placeWindowBefore(pos, win); |
| 755 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 756 | // Continue looking down until we find the first |
| 757 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | while (i >= 0) { |
| 759 | AppWindowToken t = mAppTokens.get(i); |
| 760 | final int NW = t.windows.size(); |
| 761 | if (NW > 0) { |
| 762 | pos = t.windows.get(NW-1); |
| 763 | break; |
| 764 | } |
| 765 | i--; |
| 766 | } |
| 767 | if (pos != null) { |
| 768 | // Move in front of any windows attached to this |
| 769 | // one. |
| 770 | WindowToken atoken = |
| 771 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 772 | if (atoken != null) { |
| 773 | final int NC = atoken.windows.size(); |
| 774 | if (NC > 0) { |
| 775 | WindowState top = atoken.windows.get(NC-1); |
| 776 | if (top.mSubLayer >= 0) { |
| 777 | pos = top; |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | placeWindowAfter(pos, win); |
| 782 | } else { |
| 783 | // Just search for the start of this layer. |
| 784 | final int myLayer = win.mBaseLayer; |
| 785 | for (i=0; i<N; i++) { |
| 786 | WindowState w = (WindowState)localmWindows.get(i); |
| 787 | if (w.mBaseLayer > myLayer) { |
| 788 | break; |
| 789 | } |
| 790 | } |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 791 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 792 | TAG, "Adding window " + win + " at " |
| 793 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | localmWindows.add(i, win); |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | } else { |
| 799 | // Figure out where window should go, based on layer. |
| 800 | final int myLayer = win.mBaseLayer; |
| 801 | for (i=N-1; i>=0; i--) { |
| 802 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 803 | i++; |
| 804 | break; |
| 805 | } |
| 806 | } |
| 807 | if (i < 0) i = 0; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 808 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Log.v( |
| 809 | TAG, "Adding window " + win + " at " |
| 810 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | localmWindows.add(i, win); |
| 812 | } |
| 813 | if (addToToken) { |
| 814 | token.windows.add(tokenWindowsPos, win); |
| 815 | } |
| 816 | |
| 817 | } else { |
| 818 | // Figure out this window's ordering relative to the window |
| 819 | // it is attached to. |
| 820 | final int NA = token.windows.size(); |
| 821 | final int sublayer = win.mSubLayer; |
| 822 | int largestSublayer = Integer.MIN_VALUE; |
| 823 | WindowState windowWithLargestSublayer = null; |
| 824 | for (i=0; i<NA; i++) { |
| 825 | WindowState w = token.windows.get(i); |
| 826 | final int wSublayer = w.mSubLayer; |
| 827 | if (wSublayer >= largestSublayer) { |
| 828 | largestSublayer = wSublayer; |
| 829 | windowWithLargestSublayer = w; |
| 830 | } |
| 831 | if (sublayer < 0) { |
| 832 | // For negative sublayers, we go below all windows |
| 833 | // in the same sublayer. |
| 834 | if (wSublayer >= sublayer) { |
| 835 | if (addToToken) { |
| 836 | token.windows.add(i, win); |
| 837 | } |
| 838 | placeWindowBefore( |
| 839 | wSublayer >= 0 ? attached : w, win); |
| 840 | break; |
| 841 | } |
| 842 | } else { |
| 843 | // For positive sublayers, we go above all windows |
| 844 | // in the same sublayer. |
| 845 | if (wSublayer > sublayer) { |
| 846 | if (addToToken) { |
| 847 | token.windows.add(i, win); |
| 848 | } |
| 849 | placeWindowBefore(w, win); |
| 850 | break; |
| 851 | } |
| 852 | } |
| 853 | } |
| 854 | if (i >= NA) { |
| 855 | if (addToToken) { |
| 856 | token.windows.add(win); |
| 857 | } |
| 858 | if (sublayer < 0) { |
| 859 | placeWindowBefore(attached, win); |
| 860 | } else { |
| 861 | placeWindowAfter(largestSublayer >= 0 |
| 862 | ? windowWithLargestSublayer |
| 863 | : attached, |
| 864 | win); |
| 865 | } |
| 866 | } |
| 867 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 868 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | if (win.mAppToken != null && addToToken) { |
| 870 | win.mAppToken.allAppWindows.add(win); |
| 871 | } |
| 872 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 874 | static boolean canBeImeTarget(WindowState w) { |
| 875 | final int fl = w.mAttrs.flags |
| 876 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 877 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 878 | return w.isVisibleOrAdding(); |
| 879 | } |
| 880 | return false; |
| 881 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 884 | final ArrayList localmWindows = mWindows; |
| 885 | final int N = localmWindows.size(); |
| 886 | WindowState w = null; |
| 887 | int i = N; |
| 888 | while (i > 0) { |
| 889 | i--; |
| 890 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 891 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | //Log.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| 893 | // + Integer.toHexString(w.mAttrs.flags)); |
| 894 | if (canBeImeTarget(w)) { |
| 895 | //Log.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | // Yet more tricksyness! If this window is a "starting" |
| 898 | // window, we do actually want to be on top of it, but |
| 899 | // it is not -really- where input will go. So if the caller |
| 900 | // is not actually looking to move the IME, look down below |
| 901 | // for a real window to target... |
| 902 | if (!willMove |
| 903 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 904 | && i > 0) { |
| 905 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 906 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 907 | i--; |
| 908 | w = wb; |
| 909 | } |
| 910 | } |
| 911 | break; |
| 912 | } |
| 913 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 916 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Desired input method target=" |
| 918 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | if (willMove && w != null) { |
| 921 | final WindowState curTarget = mInputMethodTarget; |
| 922 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 923 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | // Now some fun for dealing with window animations that |
| 925 | // modify the Z order. We need to look at all windows below |
| 926 | // the current target that are in this app, finding the highest |
| 927 | // visible one in layering. |
| 928 | AppWindowToken token = curTarget.mAppToken; |
| 929 | WindowState highestTarget = null; |
| 930 | int highestPos = 0; |
| 931 | if (token.animating || token.animation != null) { |
| 932 | int pos = 0; |
| 933 | pos = localmWindows.indexOf(curTarget); |
| 934 | while (pos >= 0) { |
| 935 | WindowState win = (WindowState)localmWindows.get(pos); |
| 936 | if (win.mAppToken != token) { |
| 937 | break; |
| 938 | } |
| 939 | if (!win.mRemoved) { |
| 940 | if (highestTarget == null || win.mAnimLayer > |
| 941 | highestTarget.mAnimLayer) { |
| 942 | highestTarget = win; |
| 943 | highestPos = pos; |
| 944 | } |
| 945 | } |
| 946 | pos--; |
| 947 | } |
| 948 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | if (highestTarget != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 951 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | + mNextAppTransition + " " + highestTarget |
| 953 | + " animating=" + highestTarget.isAnimating() |
| 954 | + " layer=" + highestTarget.mAnimLayer |
| 955 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 956 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 957 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | // If we are currently setting up for an animation, |
| 959 | // hold everything until we can find out what will happen. |
| 960 | mInputMethodTargetWaitingAnim = true; |
| 961 | mInputMethodTarget = highestTarget; |
| 962 | return highestPos + 1; |
| 963 | } else if (highestTarget.isAnimating() && |
| 964 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 965 | // If the window we are currently targeting is involved |
| 966 | // with an animation, and it is on top of the next target |
| 967 | // we will be over, then hold off on moving until |
| 968 | // that is done. |
| 969 | mInputMethodTarget = highestTarget; |
| 970 | return highestPos + 1; |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | //Log.i(TAG, "Placing input method @" + (i+1)); |
| 977 | if (w != null) { |
| 978 | if (willMove) { |
| 979 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 980 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 982 | + mInputMethodTarget + " to " + w, e); |
| 983 | mInputMethodTarget = w; |
| 984 | if (w.mAppToken != null) { |
| 985 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 986 | } else { |
| 987 | setInputMethodAnimLayerAdjustment(0); |
| 988 | } |
| 989 | } |
| 990 | return i+1; |
| 991 | } |
| 992 | if (willMove) { |
| 993 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 994 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | if (DEBUG_INPUT_METHOD) Log.w(TAG, "Moving IM target from " |
| 996 | + mInputMethodTarget + " to null", e); |
| 997 | mInputMethodTarget = null; |
| 998 | setInputMethodAnimLayerAdjustment(0); |
| 999 | } |
| 1000 | return -1; |
| 1001 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1002 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1004 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1005 | if (pos >= 0) { |
| 1006 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1007 | if (DEBUG_WINDOW_MOVEMENT) Log.v( |
| 1008 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | mWindows.add(pos, win); |
| 1010 | moveInputMethodDialogsLocked(pos+1); |
| 1011 | return; |
| 1012 | } |
| 1013 | win.mTargetAppToken = null; |
| 1014 | addWindowToListInOrderLocked(win, true); |
| 1015 | moveInputMethodDialogsLocked(pos); |
| 1016 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 1019 | if (DEBUG_LAYERS) Log.v(TAG, "Setting im layer adj to " + adj); |
| 1020 | mInputMethodAnimLayerAdjustment = adj; |
| 1021 | WindowState imw = mInputMethodWindow; |
| 1022 | if (imw != null) { |
| 1023 | imw.mAnimLayer = imw.mLayer + adj; |
| 1024 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 1025 | + " anim layer: " + imw.mAnimLayer); |
| 1026 | int wi = imw.mChildWindows.size(); |
| 1027 | while (wi > 0) { |
| 1028 | wi--; |
| 1029 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1030 | cw.mAnimLayer = cw.mLayer + adj; |
| 1031 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + cw |
| 1032 | + " anim layer: " + cw.mAnimLayer); |
| 1033 | } |
| 1034 | } |
| 1035 | int di = mInputMethodDialogs.size(); |
| 1036 | while (di > 0) { |
| 1037 | di --; |
| 1038 | imw = mInputMethodDialogs.get(di); |
| 1039 | imw.mAnimLayer = imw.mLayer + adj; |
| 1040 | if (DEBUG_LAYERS) Log.v(TAG, "IM win " + imw |
| 1041 | + " anim layer: " + imw.mAnimLayer); |
| 1042 | } |
| 1043 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1044 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1046 | int wpos = mWindows.indexOf(win); |
| 1047 | if (wpos >= 0) { |
| 1048 | if (wpos < interestingPos) interestingPos--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1049 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Temp removing at " + wpos + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | mWindows.remove(wpos); |
| 1051 | int NC = win.mChildWindows.size(); |
| 1052 | while (NC > 0) { |
| 1053 | NC--; |
| 1054 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1055 | int cpos = mWindows.indexOf(cw); |
| 1056 | if (cpos >= 0) { |
| 1057 | if (cpos < interestingPos) interestingPos--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1058 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Temp removing child at " |
| 1059 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | mWindows.remove(cpos); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | return interestingPos; |
| 1065 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1066 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1068 | addWindowToListInOrderLocked(win, false); |
| 1069 | // This is a hack to get all of the child windows added as well |
| 1070 | // at the right position. Child windows should be rare and |
| 1071 | // this case should be rare, so it shouldn't be that big a deal. |
| 1072 | int wpos = mWindows.indexOf(win); |
| 1073 | if (wpos >= 0) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1074 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "ReAdd removing from " + wpos |
| 1075 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | mWindows.remove(wpos); |
| 1077 | reAddWindowLocked(wpos, win); |
| 1078 | } |
| 1079 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1080 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | void logWindowList(String prefix) { |
| 1082 | int N = mWindows.size(); |
| 1083 | while (N > 0) { |
| 1084 | N--; |
| 1085 | Log.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| 1086 | } |
| 1087 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1088 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | void moveInputMethodDialogsLocked(int pos) { |
| 1090 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1091 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | final int N = dialogs.size(); |
| 1093 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| 1094 | for (int i=0; i<N; i++) { |
| 1095 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1096 | } |
| 1097 | if (DEBUG_INPUT_METHOD) { |
| 1098 | Log.v(TAG, "Window list w/pos=" + pos); |
| 1099 | logWindowList(" "); |
| 1100 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | if (pos >= 0) { |
| 1103 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1104 | if (pos < mWindows.size()) { |
| 1105 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1106 | if (wp == mInputMethodWindow) { |
| 1107 | pos++; |
| 1108 | } |
| 1109 | } |
| 1110 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| 1111 | for (int i=0; i<N; i++) { |
| 1112 | WindowState win = dialogs.get(i); |
| 1113 | win.mTargetAppToken = targetAppToken; |
| 1114 | pos = reAddWindowLocked(pos, win); |
| 1115 | } |
| 1116 | if (DEBUG_INPUT_METHOD) { |
| 1117 | Log.v(TAG, "Final window list:"); |
| 1118 | logWindowList(" "); |
| 1119 | } |
| 1120 | return; |
| 1121 | } |
| 1122 | for (int i=0; i<N; i++) { |
| 1123 | WindowState win = dialogs.get(i); |
| 1124 | win.mTargetAppToken = null; |
| 1125 | reAddWindowToListInOrderLocked(win); |
| 1126 | if (DEBUG_INPUT_METHOD) { |
| 1127 | Log.v(TAG, "No IM target, final list:"); |
| 1128 | logWindowList(" "); |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1134 | final WindowState imWin = mInputMethodWindow; |
| 1135 | final int DN = mInputMethodDialogs.size(); |
| 1136 | if (imWin == null && DN == 0) { |
| 1137 | return false; |
| 1138 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1141 | if (imPos >= 0) { |
| 1142 | // In this case, the input method windows are to be placed |
| 1143 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1144 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | // First check to see if the input method windows are already |
| 1146 | // located here, and contiguous. |
| 1147 | final int N = mWindows.size(); |
| 1148 | WindowState firstImWin = imPos < N |
| 1149 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1150 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | // Figure out the actual input method window that should be |
| 1152 | // at the bottom of their stack. |
| 1153 | WindowState baseImWin = imWin != null |
| 1154 | ? imWin : mInputMethodDialogs.get(0); |
| 1155 | if (baseImWin.mChildWindows.size() > 0) { |
| 1156 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1157 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1158 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | if (firstImWin == baseImWin) { |
| 1161 | // The windows haven't moved... but are they still contiguous? |
| 1162 | // First find the top IM window. |
| 1163 | int pos = imPos+1; |
| 1164 | while (pos < N) { |
| 1165 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1166 | break; |
| 1167 | } |
| 1168 | pos++; |
| 1169 | } |
| 1170 | pos++; |
| 1171 | // Now there should be no more input method windows above. |
| 1172 | while (pos < N) { |
| 1173 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1174 | break; |
| 1175 | } |
| 1176 | pos++; |
| 1177 | } |
| 1178 | if (pos >= N) { |
| 1179 | // All is good! |
| 1180 | return false; |
| 1181 | } |
| 1182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | if (imWin != null) { |
| 1185 | if (DEBUG_INPUT_METHOD) { |
| 1186 | Log.v(TAG, "Moving IM from " + imPos); |
| 1187 | logWindowList(" "); |
| 1188 | } |
| 1189 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1190 | if (DEBUG_INPUT_METHOD) { |
| 1191 | Log.v(TAG, "List after moving with new pos " + imPos + ":"); |
| 1192 | logWindowList(" "); |
| 1193 | } |
| 1194 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1195 | reAddWindowLocked(imPos, imWin); |
| 1196 | if (DEBUG_INPUT_METHOD) { |
| 1197 | Log.v(TAG, "List after moving IM to " + imPos + ":"); |
| 1198 | logWindowList(" "); |
| 1199 | } |
| 1200 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1201 | } else { |
| 1202 | moveInputMethodDialogsLocked(imPos); |
| 1203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | } else { |
| 1206 | // In this case, the input method windows go in a fixed layer, |
| 1207 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1208 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | if (imWin != null) { |
| 1210 | if (DEBUG_INPUT_METHOD) Log.v(TAG, "Moving IM from " + imPos); |
| 1211 | tmpRemoveWindowLocked(0, imWin); |
| 1212 | imWin.mTargetAppToken = null; |
| 1213 | reAddWindowToListInOrderLocked(imWin); |
| 1214 | if (DEBUG_INPUT_METHOD) { |
| 1215 | Log.v(TAG, "List with no IM target:"); |
| 1216 | logWindowList(" "); |
| 1217 | } |
| 1218 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1219 | } else { |
| 1220 | moveInputMethodDialogsLocked(-1);; |
| 1221 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1222 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1224 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | if (needAssignLayers) { |
| 1226 | assignLayersLocked(); |
| 1227 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1228 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | return true; |
| 1230 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1231 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | void adjustInputMethodDialogsLocked() { |
| 1233 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1234 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1235 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1236 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| 1237 | if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper vis: target obscured=" |
| 1238 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1239 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1240 | ? wallpaperTarget.mAppToken.animation : null) |
| 1241 | + " upper=" + mUpperWallpaperTarget |
| 1242 | + " lower=" + mLowerWallpaperTarget); |
| 1243 | return (wallpaperTarget != null |
| 1244 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1245 | && wallpaperTarget.mAppToken.animation != null))) |
| 1246 | || mUpperWallpaperTarget != null |
| 1247 | || mLowerWallpaperTarget != null; |
| 1248 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1249 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1250 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1251 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1252 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1253 | int adjustWallpaperWindowsLocked() { |
| 1254 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1255 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1256 | final int dw = mDisplay.getWidth(); |
| 1257 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1258 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1259 | // First find top-most window that has asked to be on top of the |
| 1260 | // wallpaper; all wallpapers go behind it. |
| 1261 | final ArrayList localmWindows = mWindows; |
| 1262 | int N = localmWindows.size(); |
| 1263 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1264 | WindowState foundW = null; |
| 1265 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1266 | WindowState topCurW = null; |
| 1267 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1268 | int i = N; |
| 1269 | while (i > 0) { |
| 1270 | i--; |
| 1271 | w = (WindowState)localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1272 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1273 | if (topCurW == null) { |
| 1274 | topCurW = w; |
| 1275 | topCurI = i; |
| 1276 | } |
| 1277 | continue; |
| 1278 | } |
| 1279 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1280 | if (w.mAppToken != null) { |
| 1281 | // If this window's app token is hidden and not animating, |
| 1282 | // it is of no interest to us. |
| 1283 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| 1284 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1285 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1286 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1287 | continue; |
| 1288 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1289 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1290 | if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w + ": readyfordisplay=" |
| 1291 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1292 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1293 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1294 | && (mWallpaperTarget == w |
| 1295 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1296 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1297 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1298 | foundW = w; |
| 1299 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1300 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1301 | && w.mAppToken.animation != null) |
| 1302 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1303 | // The current wallpaper target is animating, so we'll |
| 1304 | // look behind it for another possible target and figure |
| 1305 | // out what is going on below. |
| 1306 | if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w |
| 1307 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1308 | continue; |
| 1309 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1310 | break; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1314 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1315 | // If we are currently waiting for an app transition, and either |
| 1316 | // the current target or the next target are involved with it, |
| 1317 | // then hold off on doing anything with the wallpaper. |
| 1318 | // Note that we are checking here for just whether the target |
| 1319 | // is part of an app token... which is potentially overly aggressive |
| 1320 | // (the app token may not be involved in the transition), but good |
| 1321 | // enough (we'll just wait until whatever transition is pending |
| 1322 | // executes). |
| 1323 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1324 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1325 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1326 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1327 | } |
| 1328 | if (foundW != null && foundW.mAppToken != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1329 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1330 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1331 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1332 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1333 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1334 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1335 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1336 | if (DEBUG_WALLPAPER) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1337 | Log.v(TAG, "New wallpaper target: " + foundW |
| 1338 | + " oldTarget: " + mWallpaperTarget); |
| 1339 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1340 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1341 | mLowerWallpaperTarget = null; |
| 1342 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1343 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1344 | WindowState oldW = mWallpaperTarget; |
| 1345 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1346 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1347 | // Now what is happening... if the current and new targets are |
| 1348 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1349 | if (foundW != null && oldW != null) { |
| 1350 | boolean oldAnim = oldW.mAnimation != null |
| 1351 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1352 | boolean foundAnim = foundW.mAnimation != null |
| 1353 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1354 | if (DEBUG_WALLPAPER) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1355 | Log.v(TAG, "New animation: " + foundAnim |
| 1356 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1357 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1358 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1359 | int oldI = localmWindows.indexOf(oldW); |
| 1360 | if (DEBUG_WALLPAPER) { |
| 1361 | Log.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| 1362 | } |
| 1363 | if (oldI >= 0) { |
| 1364 | if (DEBUG_WALLPAPER) { |
| 1365 | Log.v(TAG, "Animating wallpapers: old#" + oldI |
| 1366 | + "=" + oldW + "; new#" + foundI |
| 1367 | + "=" + foundW); |
| 1368 | } |
| 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 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1371 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1372 | if (DEBUG_WALLPAPER) { |
| 1373 | Log.v(TAG, "Old wallpaper still the target."); |
| 1374 | } |
| 1375 | mWallpaperTarget = oldW; |
| 1376 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1377 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1378 | // Now set the upper and lower wallpaper targets |
| 1379 | // correctly, and make sure that we are positioning |
| 1380 | // the wallpaper below the lower. |
| 1381 | if (foundI > oldI) { |
| 1382 | // The new target is on top of the old one. |
| 1383 | if (DEBUG_WALLPAPER) { |
| 1384 | Log.v(TAG, "Found target above old target."); |
| 1385 | } |
| 1386 | mUpperWallpaperTarget = foundW; |
| 1387 | mLowerWallpaperTarget = oldW; |
| 1388 | foundW = oldW; |
| 1389 | foundI = oldI; |
| 1390 | } else { |
| 1391 | // The new target is below the old one. |
| 1392 | if (DEBUG_WALLPAPER) { |
| 1393 | Log.v(TAG, "Found target below old target."); |
| 1394 | } |
| 1395 | mUpperWallpaperTarget = oldW; |
| 1396 | mLowerWallpaperTarget = foundW; |
| 1397 | } |
| 1398 | } |
| 1399 | } |
| 1400 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1401 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1402 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1403 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1404 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1405 | || (mLowerWallpaperTarget.mAppToken != null |
| 1406 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1407 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1408 | || (mUpperWallpaperTarget.mAppToken != null |
| 1409 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1410 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1411 | if (DEBUG_WALLPAPER) { |
| 1412 | Log.v(TAG, "No longer animating wallpaper targets!"); |
| 1413 | } |
| 1414 | mLowerWallpaperTarget = null; |
| 1415 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1416 | } |
| 1417 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1418 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1419 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1420 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1421 | // The window is visible to the compositor... but is it visible |
| 1422 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1423 | visible = isWallpaperVisible(foundW); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1424 | if (DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1425 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1426 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1427 | // its layer adjustment. Only do this if we are not transfering |
| 1428 | // between two wallpaper targets. |
| 1429 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1430 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1431 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1432 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1433 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1434 | * TYPE_LAYER_MULTIPLIER |
| 1435 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1436 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1437 | // Now w is the window we are supposed to be behind... but we |
| 1438 | // 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] | 1439 | // AND any starting window associated with it, AND below the |
| 1440 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1441 | while (foundI > 0) { |
| 1442 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1443 | if (wb.mBaseLayer < maxLayer && |
| 1444 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1445 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1446 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1447 | // This window is not related to the previous one in any |
| 1448 | // interesting way, so stop here. |
| 1449 | break; |
| 1450 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1451 | foundW = wb; |
| 1452 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1453 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1454 | } else { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1455 | if (DEBUG_WALLPAPER) Log.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1456 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1457 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1458 | if (foundW == null && topCurW != null) { |
| 1459 | // There is no wallpaper target, so it goes at the bottom. |
| 1460 | // We will assume it is the same place as last time, if known. |
| 1461 | foundW = topCurW; |
| 1462 | foundI = topCurI+1; |
| 1463 | } else { |
| 1464 | // Okay i is the position immediately above the wallpaper. Look at |
| 1465 | // what is below it for later. |
| 1466 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1467 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1468 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1469 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1470 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1471 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1472 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1473 | } |
| 1474 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1475 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1476 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1477 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1478 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1479 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1480 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1481 | // are correctly placed. |
| 1482 | int curTokenIndex = mWallpaperTokens.size(); |
| 1483 | while (curTokenIndex > 0) { |
| 1484 | curTokenIndex--; |
| 1485 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1486 | if (token.hidden == visible) { |
| 1487 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1488 | token.hidden = !visible; |
| 1489 | // Need to do a layout to ensure the wallpaper now has the |
| 1490 | // correct size. |
| 1491 | mLayoutNeeded = true; |
| 1492 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1493 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1494 | int curWallpaperIndex = token.windows.size(); |
| 1495 | while (curWallpaperIndex > 0) { |
| 1496 | curWallpaperIndex--; |
| 1497 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1498 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1499 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1500 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1501 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1502 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1503 | // First, make sure the client has the current visibility |
| 1504 | // state. |
| 1505 | if (wallpaper.mWallpaperVisible != visible) { |
| 1506 | wallpaper.mWallpaperVisible = visible; |
| 1507 | try { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1508 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1509 | "Setting visibility of wallpaper " + wallpaper |
| 1510 | + ": " + visible); |
| 1511 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1512 | } catch (RemoteException e) { |
| 1513 | } |
| 1514 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1515 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1516 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1517 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1518 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| 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 | // First, if this window is at the current index, then all |
| 1521 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1522 | if (wallpaper == foundW) { |
| 1523 | foundI--; |
| 1524 | foundW = foundI > 0 |
| 1525 | ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1526 | continue; |
| 1527 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1528 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1529 | // The window didn't match... the current wallpaper window, |
| 1530 | // wherever it is, is in the wrong place, so make sure it is |
| 1531 | // not in the list. |
| 1532 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1533 | if (oldIndex >= 0) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1534 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Wallpaper removing at " |
| 1535 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1536 | localmWindows.remove(oldIndex); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1537 | if (oldIndex < foundI) { |
| 1538 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1539 | } |
| 1540 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1541 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1542 | // Now stick it in. |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1543 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 1544 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1545 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1546 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1547 | localmWindows.add(foundI, wallpaper); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1548 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1549 | } |
| 1550 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1551 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1552 | return changed; |
| 1553 | } |
| 1554 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1555 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1556 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, |
| 1557 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1558 | mWallpaperAnimLayerAdjustment = adj; |
| 1559 | int curTokenIndex = mWallpaperTokens.size(); |
| 1560 | while (curTokenIndex > 0) { |
| 1561 | curTokenIndex--; |
| 1562 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1563 | int curWallpaperIndex = token.windows.size(); |
| 1564 | while (curWallpaperIndex > 0) { |
| 1565 | curWallpaperIndex--; |
| 1566 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1567 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1568 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Log.v(TAG, "Wallpaper win " |
| 1569 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1574 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1575 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1576 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1577 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1578 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1579 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1580 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1581 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1582 | changed = wallpaperWin.mXOffset != offset; |
| 1583 | if (changed) { |
| 1584 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1585 | + wallpaperWin + " x: " + offset); |
| 1586 | wallpaperWin.mXOffset = offset; |
| 1587 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1588 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1589 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1590 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1591 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1592 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1593 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1594 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1595 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1596 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1597 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1598 | if (wallpaperWin.mYOffset != offset) { |
| 1599 | if (DEBUG_WALLPAPER) Log.v(TAG, "Update wallpaper " |
| 1600 | + wallpaperWin + " y: " + offset); |
| 1601 | changed = true; |
| 1602 | wallpaperWin.mYOffset = offset; |
| 1603 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1604 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1605 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1606 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1607 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1608 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1609 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1610 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1611 | try { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1612 | if (DEBUG_WALLPAPER) Log.v(TAG, "Report new wp offset " |
| 1613 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1614 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1615 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1616 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1617 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1618 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1619 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1620 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1621 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1622 | if (mWaitingOnWallpaper != null) { |
| 1623 | long start = SystemClock.uptimeMillis(); |
| 1624 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1625 | < start) { |
| 1626 | try { |
| 1627 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 1628 | "Waiting for offset complete..."); |
| 1629 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1630 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1631 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1632 | if (DEBUG_WALLPAPER) Log.v(TAG, "Offset complete!"); |
| 1633 | if ((start+WALLPAPER_TIMEOUT) |
| 1634 | < SystemClock.uptimeMillis()) { |
| 1635 | Log.i(TAG, "Timeout waiting for wallpaper to offset: " |
| 1636 | + wallpaperWin); |
| 1637 | mLastWallpaperTimeoutTime = start; |
| 1638 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1639 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1640 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1641 | } |
| 1642 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1643 | } catch (RemoteException e) { |
| 1644 | } |
| 1645 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1646 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1647 | return changed; |
| 1648 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1649 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1650 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1651 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1652 | if (mWaitingOnWallpaper != null && |
| 1653 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1654 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1655 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1659 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1660 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1661 | final int dw = mDisplay.getWidth(); |
| 1662 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1663 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1664 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1665 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1666 | WindowState target = mWallpaperTarget; |
| 1667 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1668 | if (target.mWallpaperX >= 0) { |
| 1669 | mLastWallpaperX = target.mWallpaperX; |
| 1670 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1671 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1672 | } |
| 1673 | if (target.mWallpaperY >= 0) { |
| 1674 | mLastWallpaperY = target.mWallpaperY; |
| 1675 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1676 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1677 | } |
| 1678 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1679 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1680 | int curTokenIndex = mWallpaperTokens.size(); |
| 1681 | while (curTokenIndex > 0) { |
| 1682 | curTokenIndex--; |
| 1683 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1684 | int curWallpaperIndex = token.windows.size(); |
| 1685 | while (curWallpaperIndex > 0) { |
| 1686 | curWallpaperIndex--; |
| 1687 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1688 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1689 | wallpaper.computeShownFrameLocked(); |
| 1690 | changed = true; |
| 1691 | // We only want to be synchronous with one wallpaper. |
| 1692 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1693 | } |
| 1694 | } |
| 1695 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1696 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1697 | return changed; |
| 1698 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1699 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1700 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1701 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1702 | final int dw = mDisplay.getWidth(); |
| 1703 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1704 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1705 | int curTokenIndex = mWallpaperTokens.size(); |
| 1706 | while (curTokenIndex > 0) { |
| 1707 | curTokenIndex--; |
| 1708 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1709 | if (token.hidden == visible) { |
| 1710 | token.hidden = !visible; |
| 1711 | // Need to do a layout to ensure the wallpaper now has the |
| 1712 | // correct size. |
| 1713 | mLayoutNeeded = true; |
| 1714 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1715 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1716 | int curWallpaperIndex = token.windows.size(); |
| 1717 | while (curWallpaperIndex > 0) { |
| 1718 | curWallpaperIndex--; |
| 1719 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1720 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1721 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1722 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1723 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1724 | if (wallpaper.mWallpaperVisible != visible) { |
| 1725 | wallpaper.mWallpaperVisible = visible; |
| 1726 | try { |
| 1727 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Log.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1728 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1729 | + ": " + visible); |
| 1730 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1731 | } catch (RemoteException e) { |
| 1732 | } |
| 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1737 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1738 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1739 | MotionEvent pointer, long eventTime) { |
| 1740 | int curTokenIndex = mWallpaperTokens.size(); |
| 1741 | while (curTokenIndex > 0) { |
| 1742 | curTokenIndex--; |
| 1743 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1744 | int curWallpaperIndex = token.windows.size(); |
| 1745 | while (curWallpaperIndex > 0) { |
| 1746 | curWallpaperIndex--; |
| 1747 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1748 | if ((wallpaper.mAttrs.flags & |
| 1749 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1750 | continue; |
| 1751 | } |
| 1752 | try { |
| 1753 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1754 | if (srcWin != null) { |
| 1755 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1756 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1757 | } else { |
| 1758 | ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top); |
| 1759 | } |
| 1760 | switch (pointer.getAction()) { |
| 1761 | case MotionEvent.ACTION_DOWN: |
| 1762 | mSendingPointersToWallpaper = true; |
| 1763 | break; |
| 1764 | case MotionEvent.ACTION_UP: |
| 1765 | mSendingPointersToWallpaper = false; |
| 1766 | break; |
| 1767 | } |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1768 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1769 | } catch (RemoteException e) { |
| 1770 | Log.w(TAG, "Failure sending pointer to wallpaper", e); |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1775 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1776 | public int addWindow(Session session, IWindow client, |
| 1777 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1778 | Rect outContentInsets) { |
| 1779 | int res = mPolicy.checkAddPermission(attrs); |
| 1780 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1781 | return res; |
| 1782 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | boolean reportNewConfig = false; |
| 1785 | WindowState attachedWindow = null; |
| 1786 | WindowState win = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1787 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | synchronized(mWindowMap) { |
| 1789 | // Instantiating a Display requires talking with the simulator, |
| 1790 | // so don't do it until we know the system is mostly up and |
| 1791 | // running. |
| 1792 | if (mDisplay == null) { |
| 1793 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1794 | mDisplay = wm.getDefaultDisplay(); |
| 1795 | mQueue.setDisplay(mDisplay); |
| 1796 | reportNewConfig = true; |
| 1797 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1798 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | if (mWindowMap.containsKey(client.asBinder())) { |
| 1800 | Log.w(TAG, "Window " + client + " is already added"); |
| 1801 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1802 | } |
| 1803 | |
| 1804 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1805 | attachedWindow = windowForClientLocked(null, attrs.token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1806 | if (attachedWindow == null) { |
| 1807 | Log.w(TAG, "Attempted to add window with token that is not a window: " |
| 1808 | + attrs.token + ". Aborting."); |
| 1809 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1810 | } |
| 1811 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1812 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| 1813 | Log.w(TAG, "Attempted to add window with token that is a sub-window: " |
| 1814 | + attrs.token + ". Aborting."); |
| 1815 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | boolean addToken = false; |
| 1820 | WindowToken token = mTokenMap.get(attrs.token); |
| 1821 | if (token == null) { |
| 1822 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1823 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1824 | Log.w(TAG, "Attempted to add application window with unknown token " |
| 1825 | + attrs.token + ". Aborting."); |
| 1826 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1827 | } |
| 1828 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1829 | Log.w(TAG, "Attempted to add input method window with unknown token " |
| 1830 | + attrs.token + ". Aborting."); |
| 1831 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1832 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1833 | if (attrs.type == TYPE_WALLPAPER) { |
| 1834 | Log.w(TAG, "Attempted to add wallpaper window with unknown token " |
| 1835 | + attrs.token + ". Aborting."); |
| 1836 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1837 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | token = new WindowToken(attrs.token, -1, false); |
| 1839 | addToken = true; |
| 1840 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1841 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1842 | AppWindowToken atoken = token.appWindowToken; |
| 1843 | if (atoken == null) { |
| 1844 | Log.w(TAG, "Attempted to add window with non-application token " |
| 1845 | + token + ". Aborting."); |
| 1846 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1847 | } else if (atoken.removed) { |
| 1848 | Log.w(TAG, "Attempted to add window with exiting application token " |
| 1849 | + token + ". Aborting."); |
| 1850 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1851 | } |
| 1852 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1853 | // No need for this guy! |
| 1854 | if (localLOGV) Log.v( |
| 1855 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1856 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1857 | } |
| 1858 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1859 | if (token.windowType != TYPE_INPUT_METHOD) { |
| 1860 | Log.w(TAG, "Attempted to add input method window with bad token " |
| 1861 | + attrs.token + ". Aborting."); |
| 1862 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1863 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1864 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1865 | if (token.windowType != TYPE_WALLPAPER) { |
| 1866 | Log.w(TAG, "Attempted to add wallpaper window with bad token " |
| 1867 | + attrs.token + ". Aborting."); |
| 1868 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1869 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | win = new WindowState(session, client, token, |
| 1873 | attachedWindow, attrs, viewVisibility); |
| 1874 | if (win.mDeathRecipient == null) { |
| 1875 | // Client has apparently died, so there is no reason to |
| 1876 | // continue. |
| 1877 | Log.w(TAG, "Adding window client " + client.asBinder() |
| 1878 | + " that is dead, aborting."); |
| 1879 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1880 | } |
| 1881 | |
| 1882 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1883 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1885 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1886 | return res; |
| 1887 | } |
| 1888 | |
| 1889 | // From now on, no exceptions or errors allowed! |
| 1890 | |
| 1891 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1894 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1895 | if (addToken) { |
| 1896 | mTokenMap.put(attrs.token, token); |
| 1897 | mTokenList.add(token); |
| 1898 | } |
| 1899 | win.attach(); |
| 1900 | mWindowMap.put(client.asBinder(), win); |
| 1901 | |
| 1902 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1903 | token.appWindowToken != null) { |
| 1904 | token.appWindowToken.startingWindow = win; |
| 1905 | } |
| 1906 | |
| 1907 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1910 | mInputMethodWindow = win; |
| 1911 | addInputMethodWindowToListLocked(win); |
| 1912 | imMayMove = false; |
| 1913 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1914 | mInputMethodDialogs.add(win); |
| 1915 | addWindowToListInOrderLocked(win, true); |
| 1916 | adjustInputMethodDialogsLocked(); |
| 1917 | imMayMove = false; |
| 1918 | } else { |
| 1919 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1920 | if (attrs.type == TYPE_WALLPAPER) { |
| 1921 | mLastWallpaperTimeoutTime = 0; |
| 1922 | adjustWallpaperWindowsLocked(); |
| 1923 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1924 | adjustWallpaperWindowsLocked(); |
| 1925 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1928 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1929 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | if (mInTouchMode) { |
| 1933 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1934 | } |
| 1935 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1936 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1937 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1938 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1939 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | if (win.canReceiveKeys()) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1941 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1942 | == true) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | imMayMove = false; |
| 1944 | } |
| 1945 | } |
| 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 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1948 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | assignLayersLocked(); |
| 1952 | // Don't do layout here, the window must call |
| 1953 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | //dump(); |
| 1956 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1957 | if (focusChanged) { |
| 1958 | if (mCurrentFocus != null) { |
| 1959 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 1960 | } |
| 1961 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | if (localLOGV) Log.v( |
| 1963 | TAG, "New client " + client.asBinder() |
| 1964 | + ": window=" + win); |
| 1965 | } |
| 1966 | |
| 1967 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1968 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1969 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1970 | // block. |
| 1971 | final long origId = Binder.clearCallingIdentity(); |
| 1972 | if (reportNewConfig) { |
| 1973 | sendNewConfiguration(); |
| 1974 | } else { |
| 1975 | // Update Orientation after adding a window, only if the window needs to be |
| 1976 | // displayed right away |
| 1977 | if (win.isVisibleOrAdding()) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 1978 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1979 | sendNewConfiguration(); |
| 1980 | } |
| 1981 | } |
| 1982 | } |
| 1983 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1984 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1985 | return res; |
| 1986 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1987 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1988 | public void removeWindow(Session session, IWindow client) { |
| 1989 | synchronized(mWindowMap) { |
| 1990 | WindowState win = windowForClientLocked(session, client); |
| 1991 | if (win == null) { |
| 1992 | return; |
| 1993 | } |
| 1994 | removeWindowLocked(session, win); |
| 1995 | } |
| 1996 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1997 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | public void removeWindowLocked(Session session, WindowState win) { |
| 1999 | |
| 2000 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 2001 | TAG, "Remove " + win + " client=" |
| 2002 | + Integer.toHexString(System.identityHashCode( |
| 2003 | win.mClient.asBinder())) |
| 2004 | + ", surface=" + win.mSurface); |
| 2005 | |
| 2006 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2007 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2008 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 2009 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2010 | + " mExiting=" + win.mExiting |
| 2011 | + " isAnimating=" + win.isAnimating() |
| 2012 | + " app-animation=" |
| 2013 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2014 | + " inPendingTransaction=" |
| 2015 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2016 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2017 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2018 | boolean wasVisible = false; |
| 2019 | // First, see if we need to run an animation. If we do, we have |
| 2020 | // to hold off on removing the window until the animation is done. |
| 2021 | // If the display is frozen, just remove immediately, since the |
| 2022 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2023 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | // If we are not currently running the exit animation, we |
| 2025 | // need to see about starting one. |
| 2026 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2027 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2029 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2030 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2031 | } |
| 2032 | // Try starting an animation. |
| 2033 | if (applyAnimationLocked(win, transit, false)) { |
| 2034 | win.mExiting = true; |
| 2035 | } |
| 2036 | } |
| 2037 | if (win.mExiting || win.isAnimating()) { |
| 2038 | // The exit animation is running... wait for it! |
| 2039 | //Log.i(TAG, "*** Running exit animation..."); |
| 2040 | win.mExiting = true; |
| 2041 | win.mRemoveOnExit = true; |
| 2042 | mLayoutNeeded = true; |
| 2043 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2044 | performLayoutAndPlaceSurfacesLocked(); |
| 2045 | if (win.mAppToken != null) { |
| 2046 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2047 | } |
| 2048 | //dump(); |
| 2049 | Binder.restoreCallingIdentity(origId); |
| 2050 | return; |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | removeWindowInnerLocked(session, win); |
| 2055 | // Removing a visible window will effect the computed orientation |
| 2056 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2057 | if (wasVisible && computeForcedAppOrientationLocked() |
| 2058 | != mForcedAppOrientation) { |
| 2059 | mH.sendMessage(mH.obtainMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | } |
| 2061 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2062 | Binder.restoreCallingIdentity(origId); |
| 2063 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2064 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2065 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 2066 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 2067 | KeyWaiter.RETURN_NOTHING); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 2069 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2070 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2072 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2073 | if (mInputMethodTarget == win) { |
| 2074 | moveInputMethodWindowsIfNeededLocked(false); |
| 2075 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2076 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2077 | if (false) { |
| 2078 | RuntimeException e = new RuntimeException("here"); |
| 2079 | e.fillInStackTrace(); |
| 2080 | Log.w(TAG, "Removing window " + win, e); |
| 2081 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2082 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | mPolicy.removeWindowLw(win); |
| 2084 | win.removeLocked(); |
| 2085 | |
| 2086 | mWindowMap.remove(win.mClient.asBinder()); |
| 2087 | mWindows.remove(win); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2088 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Final remove of window: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | |
| 2090 | if (mInputMethodWindow == win) { |
| 2091 | mInputMethodWindow = null; |
| 2092 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2093 | mInputMethodDialogs.remove(win); |
| 2094 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2095 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | final WindowToken token = win.mToken; |
| 2097 | final AppWindowToken atoken = win.mAppToken; |
| 2098 | token.windows.remove(win); |
| 2099 | if (atoken != null) { |
| 2100 | atoken.allAppWindows.remove(win); |
| 2101 | } |
| 2102 | if (localLOGV) Log.v( |
| 2103 | TAG, "**** Removing window " + win + ": count=" |
| 2104 | + token.windows.size()); |
| 2105 | if (token.windows.size() == 0) { |
| 2106 | if (!token.explicit) { |
| 2107 | mTokenMap.remove(token.token); |
| 2108 | mTokenList.remove(token); |
| 2109 | } else if (atoken != null) { |
| 2110 | atoken.firstWindowDrawn = false; |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | if (atoken != null) { |
| 2115 | if (atoken.startingWindow == win) { |
| 2116 | atoken.startingWindow = null; |
| 2117 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2118 | // If this is the last window and we had requested a starting |
| 2119 | // transition window, well there is no point now. |
| 2120 | atoken.startingData = null; |
| 2121 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2122 | // If this is the last window except for a starting transition |
| 2123 | // window, we need to get rid of the starting transition. |
| 2124 | if (DEBUG_STARTING_WINDOW) { |
| 2125 | Log.v(TAG, "Schedule remove starting " + token |
| 2126 | + ": no more real windows"); |
| 2127 | } |
| 2128 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2129 | mH.sendMessage(m); |
| 2130 | } |
| 2131 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2132 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2133 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2134 | mLastWallpaperTimeoutTime = 0; |
| 2135 | adjustWallpaperWindowsLocked(); |
| 2136 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2137 | adjustWallpaperWindowsLocked(); |
| 2138 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | if (!mInLayout) { |
| 2141 | assignLayersLocked(); |
| 2142 | mLayoutNeeded = true; |
| 2143 | performLayoutAndPlaceSurfacesLocked(); |
| 2144 | if (win.mAppToken != null) { |
| 2145 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2146 | } |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2151 | long origId = Binder.clearCallingIdentity(); |
| 2152 | try { |
| 2153 | synchronized (mWindowMap) { |
| 2154 | WindowState w = windowForClientLocked(session, client); |
| 2155 | if ((w != null) && (w.mSurface != null)) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2156 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | Surface.openTransaction(); |
| 2158 | try { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2159 | if (SHOW_TRANSACTIONS) Log.i( |
| 2160 | TAG, " SURFACE " + w.mSurface |
| 2161 | + ": transparentRegionHint=" + region); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | w.mSurface.setTransparentRegionHint(region); |
| 2163 | } finally { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2164 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | Surface.closeTransaction(); |
| 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | } finally { |
| 2170 | Binder.restoreCallingIdentity(origId); |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2175 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2176 | Rect visibleInsets) { |
| 2177 | long origId = Binder.clearCallingIdentity(); |
| 2178 | try { |
| 2179 | synchronized (mWindowMap) { |
| 2180 | WindowState w = windowForClientLocked(session, client); |
| 2181 | if (w != null) { |
| 2182 | w.mGivenInsetsPending = false; |
| 2183 | w.mGivenContentInsets.set(contentInsets); |
| 2184 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2185 | w.mTouchableInsets = touchableInsets; |
| 2186 | mLayoutNeeded = true; |
| 2187 | performLayoutAndPlaceSurfacesLocked(); |
| 2188 | } |
| 2189 | } |
| 2190 | } finally { |
| 2191 | Binder.restoreCallingIdentity(origId); |
| 2192 | } |
| 2193 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2194 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2195 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2196 | Rect outDisplayFrame) { |
| 2197 | synchronized(mWindowMap) { |
| 2198 | WindowState win = windowForClientLocked(session, client); |
| 2199 | if (win == null) { |
| 2200 | outDisplayFrame.setEmpty(); |
| 2201 | return; |
| 2202 | } |
| 2203 | outDisplayFrame.set(win.mDisplayFrame); |
| 2204 | } |
| 2205 | } |
| 2206 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2207 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2208 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2209 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2210 | window.mWallpaperX = x; |
| 2211 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2212 | window.mWallpaperXStep = xStep; |
| 2213 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2214 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2215 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2216 | } |
| 2217 | } |
| 2218 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2219 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2220 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2221 | synchronized (mWindowMap) { |
| 2222 | if (mWaitingOnWallpaper != null && |
| 2223 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2224 | mWaitingOnWallpaper = null; |
| 2225 | mWindowMap.notifyAll(); |
| 2226 | } |
| 2227 | } |
| 2228 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2229 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2230 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2231 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2232 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2233 | || window == mUpperWallpaperTarget) { |
| 2234 | boolean doWait = sync; |
| 2235 | int curTokenIndex = mWallpaperTokens.size(); |
| 2236 | while (curTokenIndex > 0) { |
| 2237 | curTokenIndex--; |
| 2238 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2239 | int curWallpaperIndex = token.windows.size(); |
| 2240 | while (curWallpaperIndex > 0) { |
| 2241 | curWallpaperIndex--; |
| 2242 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2243 | try { |
| 2244 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2245 | x, y, z, extras, sync); |
| 2246 | // We only want to be synchronous with one wallpaper. |
| 2247 | sync = false; |
| 2248 | } catch (RemoteException e) { |
| 2249 | } |
| 2250 | } |
| 2251 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2252 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2253 | if (doWait) { |
| 2254 | // XXX Need to wait for result. |
| 2255 | } |
| 2256 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2257 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2258 | return null; |
| 2259 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2260 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2261 | public int relayoutWindow(Session session, IWindow client, |
| 2262 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2263 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2264 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| 2265 | Surface outSurface) { |
| 2266 | boolean displayed = false; |
| 2267 | boolean inTouchMode; |
| 2268 | Configuration newConfig = null; |
| 2269 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | synchronized(mWindowMap) { |
| 2272 | WindowState win = windowForClientLocked(session, client); |
| 2273 | if (win == null) { |
| 2274 | return 0; |
| 2275 | } |
| 2276 | win.mRequestedWidth = requestedWidth; |
| 2277 | win.mRequestedHeight = requestedHeight; |
| 2278 | |
| 2279 | if (attrs != null) { |
| 2280 | mPolicy.adjustWindowParamsLw(attrs); |
| 2281 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | int attrChanges = 0; |
| 2284 | int flagChanges = 0; |
| 2285 | if (attrs != null) { |
| 2286 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2287 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2288 | } |
| 2289 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2290 | if (DEBUG_LAYOUT) Log.v(TAG, "Relayout " + win + ": " + win.mAttrs); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | |
| 2292 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2293 | win.mAlpha = attrs.alpha; |
| 2294 | } |
| 2295 | |
| 2296 | final boolean scaledWindow = |
| 2297 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2298 | |
| 2299 | if (scaledWindow) { |
| 2300 | // requested{Width|Height} Surface's physical size |
| 2301 | // attrs.{width|height} Size on screen |
| 2302 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2303 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2304 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2305 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2306 | } else { |
| 2307 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | boolean imMayMove = (flagChanges&( |
| 2311 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2312 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2313 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2314 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2315 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2316 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2317 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2318 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2319 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| 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 | win.mRelayoutCalled = true; |
| 2322 | final int oldVisibility = win.mViewVisibility; |
| 2323 | win.mViewVisibility = viewVisibility; |
| 2324 | if (viewVisibility == View.VISIBLE && |
| 2325 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2326 | displayed = !win.isVisibleLw(); |
| 2327 | if (win.mExiting) { |
| 2328 | win.mExiting = false; |
| 2329 | win.mAnimation = null; |
| 2330 | } |
| 2331 | if (win.mDestroying) { |
| 2332 | win.mDestroying = false; |
| 2333 | mDestroySurface.remove(win); |
| 2334 | } |
| 2335 | if (oldVisibility == View.GONE) { |
| 2336 | win.mEnterAnimationPending = true; |
| 2337 | } |
| 2338 | if (displayed && win.mSurface != null && !win.mDrawPending |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2339 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2340 | && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | applyEnterAnimationLocked(win); |
| 2342 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2343 | if (displayed && (win.mAttrs.flags |
| 2344 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2345 | win.mTurnOnScreen = true; |
| 2346 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2348 | // To change the format, we need to re-build the surface. |
| 2349 | win.destroySurfaceLocked(); |
| 2350 | displayed = true; |
| 2351 | } |
| 2352 | try { |
| 2353 | Surface surface = win.createSurfaceLocked(); |
| 2354 | if (surface != null) { |
| 2355 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2356 | win.mReportDestroySurface = false; |
| 2357 | win.mSurfacePendingDestroy = false; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2358 | if (SHOW_TRANSACTIONS) Log.i(TAG, |
| 2359 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2361 | // For some reason there isn't a surface. Clear the |
| 2362 | // caller's object so they see the same state. |
| 2363 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | } |
| 2365 | } catch (Exception e) { |
| 2366 | Log.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2367 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2368 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2369 | Binder.restoreCallingIdentity(origId); |
| 2370 | return 0; |
| 2371 | } |
| 2372 | if (displayed) { |
| 2373 | focusMayChange = true; |
| 2374 | } |
| 2375 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2376 | && mInputMethodWindow == null) { |
| 2377 | mInputMethodWindow = win; |
| 2378 | imMayMove = true; |
| 2379 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2380 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2381 | && win.mAppToken != null |
| 2382 | && win.mAppToken.startingWindow != null) { |
| 2383 | // Special handling of starting window over the base |
| 2384 | // window of the app: propagate lock screen flags to it, |
| 2385 | // to provide the correct semantics while starting. |
| 2386 | final int mask = |
| 2387 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 2388 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 2389 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2390 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2391 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2392 | } else { |
| 2393 | win.mEnterAnimationPending = false; |
| 2394 | if (win.mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2395 | if (DEBUG_VISIBILITY) Log.i(TAG, "Relayout invis " + win |
| 2396 | + ": mExiting=" + win.mExiting |
| 2397 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | // If we are not currently running the exit animation, we |
| 2399 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2400 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2401 | // Try starting an animation; if there isn't one, we |
| 2402 | // can destroy the surface right away. |
| 2403 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2404 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2405 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2406 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2407 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2409 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | win.mExiting = true; |
| 2411 | mKeyWaiter.finishedKey(session, client, true, |
| 2412 | KeyWaiter.RETURN_NOTHING); |
| 2413 | } else if (win.isAnimating()) { |
| 2414 | // Currently in a hide animation... turn this into |
| 2415 | // an exit. |
| 2416 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2417 | } else if (win == mWallpaperTarget) { |
| 2418 | // If the wallpaper is currently behind this |
| 2419 | // window, we need to change both of them inside |
| 2420 | // of a transaction to avoid artifacts. |
| 2421 | win.mExiting = true; |
| 2422 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | } else { |
| 2424 | if (mInputMethodWindow == win) { |
| 2425 | mInputMethodWindow = null; |
| 2426 | } |
| 2427 | win.destroySurfaceLocked(); |
| 2428 | } |
| 2429 | } |
| 2430 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2431 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2432 | if (win.mSurface == null || (win.getAttrs().flags |
| 2433 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2434 | || win.mSurfacePendingDestroy) { |
| 2435 | // We are being called from a local process, which |
| 2436 | // means outSurface holds its current surface. Ensure the |
| 2437 | // surface object is cleared, but we don't want it actually |
| 2438 | // destroyed at this point. |
| 2439 | win.mSurfacePendingDestroy = false; |
| 2440 | outSurface.release(); |
| 2441 | if (DEBUG_VISIBILITY) Log.i(TAG, "Releasing surface in: " + win); |
| 2442 | } else if (win.mSurface != null) { |
| 2443 | if (DEBUG_VISIBILITY) Log.i(TAG, |
| 2444 | "Keeping surface, will report destroy: " + win); |
| 2445 | win.mReportDestroySurface = true; |
| 2446 | outSurface.copyFrom(win.mSurface); |
| 2447 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | } |
| 2449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | if (focusMayChange) { |
| 2451 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2452 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2453 | imMayMove = false; |
| 2454 | } |
| 2455 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2456 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2457 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2458 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2459 | // reassign them at this point if the IM window state gets shuffled |
| 2460 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2463 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2464 | // Little hack here -- we -should- be able to rely on the |
| 2465 | // function to return true if the IME has moved and needs |
| 2466 | // its layer recomputed. However, if the IME was hidden |
| 2467 | // and isn't actually moved in the list, its layer may be |
| 2468 | // 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] | 2469 | assignLayers = true; |
| 2470 | } |
| 2471 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2472 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2473 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2474 | assignLayers = true; |
| 2475 | } |
| 2476 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2477 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | mLayoutNeeded = true; |
| 2479 | win.mGivenInsetsPending = insetsPending; |
| 2480 | if (assignLayers) { |
| 2481 | assignLayersLocked(); |
| 2482 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2483 | newConfig = updateOrientationFromAppTokensLocked(null, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2484 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2485 | if (displayed && win.mIsWallpaper) { |
| 2486 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2487 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2488 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | if (win.mAppToken != null) { |
| 2490 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2491 | } |
| 2492 | outFrame.set(win.mFrame); |
| 2493 | outContentInsets.set(win.mContentInsets); |
| 2494 | outVisibleInsets.set(win.mVisibleInsets); |
| 2495 | if (localLOGV) Log.v( |
| 2496 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2497 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2498 | + ", requestedHeight=" + requestedHeight |
| 2499 | + ", viewVisibility=" + viewVisibility |
| 2500 | + "\nRelayout returning frame=" + outFrame |
| 2501 | + ", surface=" + outSurface); |
| 2502 | |
| 2503 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 2504 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2505 | |
| 2506 | inTouchMode = mInTouchMode; |
| 2507 | } |
| 2508 | |
| 2509 | if (newConfig != null) { |
| 2510 | sendNewConfiguration(); |
| 2511 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2512 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2513 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2514 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2516 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2517 | } |
| 2518 | |
| 2519 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2520 | final long origId = Binder.clearCallingIdentity(); |
| 2521 | synchronized(mWindowMap) { |
| 2522 | WindowState win = windowForClientLocked(session, client); |
| 2523 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2524 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2525 | adjustWallpaperWindowsLocked(); |
| 2526 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | mLayoutNeeded = true; |
| 2528 | performLayoutAndPlaceSurfacesLocked(); |
| 2529 | } |
| 2530 | } |
| 2531 | Binder.restoreCallingIdentity(origId); |
| 2532 | } |
| 2533 | |
| 2534 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| 2535 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2536 | + (lp != null ? lp.packageName : null) |
| 2537 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2538 | if (lp != null && lp.windowAnimations != 0) { |
| 2539 | // If this is a system resource, don't try to load it from the |
| 2540 | // application resources. It is nice to avoid loading application |
| 2541 | // resources if we can. |
| 2542 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2543 | int resId = lp.windowAnimations; |
| 2544 | if ((resId&0xFF000000) == 0x01000000) { |
| 2545 | packageName = "android"; |
| 2546 | } |
| 2547 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2548 | + packageName); |
| 2549 | return AttributeCache.instance().get(packageName, resId, |
| 2550 | com.android.internal.R.styleable.WindowAnimation); |
| 2551 | } |
| 2552 | return null; |
| 2553 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2554 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2555 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| 2556 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2557 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2558 | if (packageName != null) { |
| 2559 | if ((resId&0xFF000000) == 0x01000000) { |
| 2560 | packageName = "android"; |
| 2561 | } |
| 2562 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2563 | + packageName); |
| 2564 | return AttributeCache.instance().get(packageName, resId, |
| 2565 | com.android.internal.R.styleable.WindowAnimation); |
| 2566 | } |
| 2567 | return null; |
| 2568 | } |
| 2569 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2570 | private void applyEnterAnimationLocked(WindowState win) { |
| 2571 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2572 | if (win.mEnterAnimationPending) { |
| 2573 | win.mEnterAnimationPending = false; |
| 2574 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2575 | } |
| 2576 | |
| 2577 | applyAnimationLocked(win, transit, true); |
| 2578 | } |
| 2579 | |
| 2580 | private boolean applyAnimationLocked(WindowState win, |
| 2581 | int transit, boolean isEntrance) { |
| 2582 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2583 | // If we are trying to apply an animation, but already running |
| 2584 | // an animation of the same type, then just leave that one alone. |
| 2585 | return true; |
| 2586 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2587 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2588 | // Only apply an animation if the display isn't frozen. If it is |
| 2589 | // frozen, there is no reason to animate and it can cause strange |
| 2590 | // artifacts when we unfreeze the display if some different animation |
| 2591 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2592 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2594 | int attr = -1; |
| 2595 | Animation a = null; |
| 2596 | if (anim != 0) { |
| 2597 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2598 | } else { |
| 2599 | switch (transit) { |
| 2600 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2601 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2602 | break; |
| 2603 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2604 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2605 | break; |
| 2606 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2607 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2608 | break; |
| 2609 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2610 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2611 | break; |
| 2612 | } |
| 2613 | if (attr >= 0) { |
| 2614 | a = loadAnimation(win.mAttrs, attr); |
| 2615 | } |
| 2616 | } |
| 2617 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win |
| 2618 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2619 | + " mAnimation=" + win.mAnimation |
| 2620 | + " isEntrance=" + isEntrance); |
| 2621 | if (a != null) { |
| 2622 | if (DEBUG_ANIM) { |
| 2623 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2624 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | Log.v(TAG, "Loaded animation " + a + " for " + win, e); |
| 2626 | } |
| 2627 | win.setAnimation(a); |
| 2628 | win.mAnimationIsEntrance = isEntrance; |
| 2629 | } |
| 2630 | } else { |
| 2631 | win.clearAnimation(); |
| 2632 | } |
| 2633 | |
| 2634 | return win.mAnimation != null; |
| 2635 | } |
| 2636 | |
| 2637 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2638 | int anim = 0; |
| 2639 | Context context = mContext; |
| 2640 | if (animAttr >= 0) { |
| 2641 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2642 | if (ent != null) { |
| 2643 | context = ent.context; |
| 2644 | anim = ent.array.getResourceId(animAttr, 0); |
| 2645 | } |
| 2646 | } |
| 2647 | if (anim != 0) { |
| 2648 | return AnimationUtils.loadAnimation(context, anim); |
| 2649 | } |
| 2650 | return null; |
| 2651 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2652 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2653 | private Animation loadAnimation(String packageName, int resId) { |
| 2654 | int anim = 0; |
| 2655 | Context context = mContext; |
| 2656 | if (resId >= 0) { |
| 2657 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2658 | if (ent != null) { |
| 2659 | context = ent.context; |
| 2660 | anim = resId; |
| 2661 | } |
| 2662 | } |
| 2663 | if (anim != 0) { |
| 2664 | return AnimationUtils.loadAnimation(context, anim); |
| 2665 | } |
| 2666 | return null; |
| 2667 | } |
| 2668 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2669 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2670 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2671 | // Only apply an animation if the display isn't frozen. If it is |
| 2672 | // frozen, there is no reason to animate and it can cause strange |
| 2673 | // artifacts when we unfreeze the display if some different animation |
| 2674 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2675 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2676 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2677 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2678 | a = new FadeInOutAnimation(enter); |
| 2679 | if (DEBUG_ANIM) Log.v(TAG, |
| 2680 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2681 | } else if (mNextAppTransitionPackage != null) { |
| 2682 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2683 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2684 | } else { |
| 2685 | int animAttr = 0; |
| 2686 | switch (transit) { |
| 2687 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2688 | animAttr = enter |
| 2689 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2690 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2691 | break; |
| 2692 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2693 | animAttr = enter |
| 2694 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2695 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2696 | break; |
| 2697 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2698 | animAttr = enter |
| 2699 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2700 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2701 | break; |
| 2702 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2703 | animAttr = enter |
| 2704 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2705 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2706 | break; |
| 2707 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2708 | animAttr = enter |
| 2709 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2710 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2711 | break; |
| 2712 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2713 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2714 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2715 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2716 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2717 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2718 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2719 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2720 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2721 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2722 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2723 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2724 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2725 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2726 | break; |
| 2727 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2728 | animAttr = enter |
| 2729 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2730 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2731 | break; |
| 2732 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2733 | animAttr = enter |
| 2734 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2735 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2736 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2737 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2738 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2739 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 2740 | + " anim=" + a |
| 2741 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2742 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2743 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | if (a != null) { |
| 2745 | if (DEBUG_ANIM) { |
| 2746 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2747 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| 2749 | } |
| 2750 | wtoken.setAnimation(a); |
| 2751 | } |
| 2752 | } else { |
| 2753 | wtoken.clearAnimation(); |
| 2754 | } |
| 2755 | |
| 2756 | return wtoken.animation != null; |
| 2757 | } |
| 2758 | |
| 2759 | // ------------------------------------------------------------- |
| 2760 | // Application Window Tokens |
| 2761 | // ------------------------------------------------------------- |
| 2762 | |
| 2763 | public void validateAppTokens(List tokens) { |
| 2764 | int v = tokens.size()-1; |
| 2765 | int m = mAppTokens.size()-1; |
| 2766 | while (v >= 0 && m >= 0) { |
| 2767 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2768 | if (wtoken.removed) { |
| 2769 | m--; |
| 2770 | continue; |
| 2771 | } |
| 2772 | if (tokens.get(v) != wtoken.token) { |
| 2773 | Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| 2774 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2775 | } |
| 2776 | v--; |
| 2777 | m--; |
| 2778 | } |
| 2779 | while (v >= 0) { |
| 2780 | Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| 2781 | v--; |
| 2782 | } |
| 2783 | while (m >= 0) { |
| 2784 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2785 | if (!wtoken.removed) { |
| 2786 | Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| 2787 | } |
| 2788 | m--; |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | boolean checkCallingPermission(String permission, String func) { |
| 2793 | // Quick check: if the calling permission is me, it's all okay. |
| 2794 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2795 | return true; |
| 2796 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2797 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | if (mContext.checkCallingPermission(permission) |
| 2799 | == PackageManager.PERMISSION_GRANTED) { |
| 2800 | return true; |
| 2801 | } |
| 2802 | String msg = "Permission Denial: " + func + " from pid=" |
| 2803 | + Binder.getCallingPid() |
| 2804 | + ", uid=" + Binder.getCallingUid() |
| 2805 | + " requires " + permission; |
| 2806 | Log.w(TAG, msg); |
| 2807 | return false; |
| 2808 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2809 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2811 | WindowToken wtoken = mTokenMap.get(token); |
| 2812 | if (wtoken == null) { |
| 2813 | return null; |
| 2814 | } |
| 2815 | return wtoken.appWindowToken; |
| 2816 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2818 | public void addWindowToken(IBinder token, int type) { |
| 2819 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2820 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2821 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2822 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2823 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2824 | synchronized(mWindowMap) { |
| 2825 | WindowToken wtoken = mTokenMap.get(token); |
| 2826 | if (wtoken != null) { |
| 2827 | Log.w(TAG, "Attempted to add existing input method token: " + token); |
| 2828 | return; |
| 2829 | } |
| 2830 | wtoken = new WindowToken(token, type, true); |
| 2831 | mTokenMap.put(token, wtoken); |
| 2832 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2833 | if (type == TYPE_WALLPAPER) { |
| 2834 | mWallpaperTokens.add(wtoken); |
| 2835 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2836 | } |
| 2837 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2838 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | public void removeWindowToken(IBinder token) { |
| 2840 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2841 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2842 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | final long origId = Binder.clearCallingIdentity(); |
| 2846 | synchronized(mWindowMap) { |
| 2847 | WindowToken wtoken = mTokenMap.remove(token); |
| 2848 | mTokenList.remove(wtoken); |
| 2849 | if (wtoken != null) { |
| 2850 | boolean delayed = false; |
| 2851 | if (!wtoken.hidden) { |
| 2852 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2854 | final int N = wtoken.windows.size(); |
| 2855 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2856 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | for (int i=0; i<N; i++) { |
| 2858 | WindowState win = wtoken.windows.get(i); |
| 2859 | |
| 2860 | if (win.isAnimating()) { |
| 2861 | delayed = true; |
| 2862 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | if (win.isVisibleNow()) { |
| 2865 | applyAnimationLocked(win, |
| 2866 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2867 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2868 | KeyWaiter.RETURN_NOTHING); |
| 2869 | changed = true; |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | if (changed) { |
| 2874 | mLayoutNeeded = true; |
| 2875 | performLayoutAndPlaceSurfacesLocked(); |
| 2876 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2877 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2878 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2879 | if (delayed) { |
| 2880 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2881 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2882 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | } |
| 2884 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2886 | } else { |
| 2887 | Log.w(TAG, "Attempted to remove non-existing token: " + token); |
| 2888 | } |
| 2889 | } |
| 2890 | Binder.restoreCallingIdentity(origId); |
| 2891 | } |
| 2892 | |
| 2893 | public void addAppToken(int addPos, IApplicationToken token, |
| 2894 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2895 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2896 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2897 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2898 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | synchronized(mWindowMap) { |
| 2901 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2902 | if (wtoken != null) { |
| 2903 | Log.w(TAG, "Attempted to add existing app token: " + token); |
| 2904 | return; |
| 2905 | } |
| 2906 | wtoken = new AppWindowToken(token); |
| 2907 | wtoken.groupId = groupId; |
| 2908 | wtoken.appFullscreen = fullscreen; |
| 2909 | wtoken.requestedOrientation = requestedOrientation; |
| 2910 | mAppTokens.add(addPos, wtoken); |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 2911 | if (localLOGV) Log.v(TAG, "Adding new app token: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | mTokenMap.put(token.asBinder(), wtoken); |
| 2913 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | // Application tokens start out hidden. |
| 2916 | wtoken.hidden = true; |
| 2917 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2918 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2919 | //dump(); |
| 2920 | } |
| 2921 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2923 | public void setAppGroupId(IBinder token, int groupId) { |
| 2924 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2925 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2926 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | synchronized(mWindowMap) { |
| 2930 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2931 | if (wtoken == null) { |
| 2932 | Log.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| 2933 | return; |
| 2934 | } |
| 2935 | wtoken.groupId = groupId; |
| 2936 | } |
| 2937 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2938 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | public int getOrientationFromWindowsLocked() { |
| 2940 | int pos = mWindows.size() - 1; |
| 2941 | while (pos >= 0) { |
| 2942 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2943 | pos--; |
| 2944 | if (wtoken.mAppToken != null) { |
| 2945 | // We hit an application window. so the orientation will be determined by the |
| 2946 | // app window. No point in continuing further. |
| 2947 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2948 | } |
| 2949 | if (!wtoken.isVisibleLw()) { |
| 2950 | continue; |
| 2951 | } |
| 2952 | int req = wtoken.mAttrs.screenOrientation; |
| 2953 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2954 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2955 | continue; |
| 2956 | } else { |
| 2957 | return req; |
| 2958 | } |
| 2959 | } |
| 2960 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2961 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2962 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | public int getOrientationFromAppTokensLocked() { |
| 2964 | int pos = mAppTokens.size() - 1; |
| 2965 | int curGroup = 0; |
| 2966 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2967 | boolean findingBehind = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2968 | boolean haveGroup = false; |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2969 | boolean lastFullscreen = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | while (pos >= 0) { |
| 2971 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 2972 | pos--; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2973 | // if we're about to tear down this window and not seek for |
| 2974 | // the behind activity, don't use it for orientation |
| 2975 | if (!findingBehind |
| 2976 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2977 | continue; |
| 2978 | } |
| 2979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | if (!haveGroup) { |
| 2981 | // We ignore any hidden applications on the top. |
| 2982 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 2983 | continue; |
| 2984 | } |
| 2985 | haveGroup = true; |
| 2986 | curGroup = wtoken.groupId; |
| 2987 | lastOrientation = wtoken.requestedOrientation; |
| 2988 | } else if (curGroup != wtoken.groupId) { |
| 2989 | // If we have hit a new application group, and the bottom |
| 2990 | // of the previous group didn't explicitly say to use |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2991 | // the orientation behind it, and the last app was |
| 2992 | // full screen, then we'll stick with the |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | // user's orientation. |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2994 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 2995 | && lastFullscreen) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2996 | return lastOrientation; |
| 2997 | } |
| 2998 | } |
| 2999 | int or = wtoken.requestedOrientation; |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 3000 | // If this application is fullscreen, and didn't explicitly say |
| 3001 | // to use the orientation behind it, then just take whatever |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | // orientation it has and ignores whatever is under it. |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3003 | lastFullscreen = wtoken.appFullscreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3004 | if (lastFullscreen |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 3005 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | return or; |
| 3007 | } |
| 3008 | // If this application has requested an explicit orientation, |
| 3009 | // then use it. |
| 3010 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3011 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3012 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3013 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3014 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3015 | return or; |
| 3016 | } |
| Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 3017 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3018 | } |
| 3019 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 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 Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3023 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3024 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3025 | "updateOrientationFromAppTokens()")) { |
| 3026 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3027 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | Configuration config; |
| 3030 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3031 | config = updateOrientationFromAppTokensUnchecked(currentConfig, |
| 3032 | freezeThisOneIfNeeded); |
| 3033 | Binder.restoreCallingIdentity(ident); |
| 3034 | return config; |
| 3035 | } |
| 3036 | |
| 3037 | Configuration updateOrientationFromAppTokensUnchecked( |
| 3038 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 3039 | Configuration config; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | synchronized(mWindowMap) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3041 | config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3042 | if (config != null) { |
| 3043 | mLayoutNeeded = true; |
| 3044 | performLayoutAndPlaceSurfacesLocked(); |
| 3045 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3046 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | return config; |
| 3048 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3049 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | /* |
| 3051 | * The orientation is computed from non-application windows first. If none of |
| 3052 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3053 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3054 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3055 | * android.os.IBinder) |
| 3056 | */ |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3057 | Configuration updateOrientationFromAppTokensLocked( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3058 | Configuration appConfig, IBinder freezeThisOneIfNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | long ident = Binder.clearCallingIdentity(); |
| 3061 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3062 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3063 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3064 | if (req != mForcedAppOrientation) { |
| 3065 | changed = true; |
| 3066 | mForcedAppOrientation = req; |
| 3067 | //send a message to Policy indicating orientation change to take |
| 3068 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3069 | mPolicy.setCurrentOrientationLw(req); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3071 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3072 | if (changed) { |
| 3073 | changed = setRotationUncheckedLocked( |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3074 | WindowManagerPolicy.USE_LAST_ROTATION, |
| 3075 | mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3076 | if (changed) { |
| 3077 | if (freezeThisOneIfNeeded != null) { |
| 3078 | AppWindowToken wtoken = findAppWindowToken( |
| 3079 | freezeThisOneIfNeeded); |
| 3080 | if (wtoken != null) { |
| 3081 | startAppFreezingScreenLocked(wtoken, |
| 3082 | ActivityInfo.CONFIG_ORIENTATION); |
| 3083 | } |
| 3084 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3085 | return computeNewConfigurationLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | } |
| 3087 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3088 | |
| 3089 | // No obvious action we need to take, but if our current |
| 3090 | // state mismatches the activity maanager's, update it |
| 3091 | if (appConfig != null) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3092 | mTempConfiguration.setToDefaults(); |
| 3093 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3094 | if (appConfig.diff(mTempConfiguration) != 0) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3095 | return new Configuration(mTempConfiguration); |
| 3096 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3097 | } |
| 3098 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3099 | } finally { |
| 3100 | Binder.restoreCallingIdentity(ident); |
| 3101 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3102 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3103 | return null; |
| 3104 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3105 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3106 | int computeForcedAppOrientationLocked() { |
| 3107 | int req = getOrientationFromWindowsLocked(); |
| 3108 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3109 | req = getOrientationFromAppTokensLocked(); |
| 3110 | } |
| 3111 | return req; |
| 3112 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3113 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3114 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3115 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3116 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3117 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3118 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3119 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3120 | synchronized(mWindowMap) { |
| 3121 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3122 | if (wtoken == null) { |
| 3123 | Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| 3124 | return; |
| 3125 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3126 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3127 | wtoken.requestedOrientation = requestedOrientation; |
| 3128 | } |
| 3129 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3130 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | public int getAppOrientation(IApplicationToken token) { |
| 3132 | synchronized(mWindowMap) { |
| 3133 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3134 | if (wtoken == null) { |
| 3135 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3136 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3137 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | return wtoken.requestedOrientation; |
| 3139 | } |
| 3140 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3141 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3143 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3144 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3145 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | synchronized(mWindowMap) { |
| 3149 | boolean changed = false; |
| 3150 | if (token == null) { |
| 3151 | if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| 3152 | changed = mFocusedApp != null; |
| 3153 | mFocusedApp = null; |
| 3154 | mKeyWaiter.tickle(); |
| 3155 | } else { |
| 3156 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3157 | if (newFocus == null) { |
| 3158 | Log.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| 3159 | return; |
| 3160 | } |
| 3161 | changed = mFocusedApp != newFocus; |
| 3162 | mFocusedApp = newFocus; |
| 3163 | if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp); |
| 3164 | mKeyWaiter.tickle(); |
| 3165 | } |
| 3166 | |
| 3167 | if (moveFocusNow && changed) { |
| 3168 | final long origId = Binder.clearCallingIdentity(); |
| 3169 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3170 | Binder.restoreCallingIdentity(origId); |
| 3171 | } |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | public void prepareAppTransition(int transit) { |
| 3176 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3177 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3178 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3179 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3181 | synchronized(mWindowMap) { |
| 3182 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3183 | TAG, "Prepare app transition: transit=" + transit |
| 3184 | + " mNextAppTransition=" + mNextAppTransition); |
| 3185 | if (!mDisplayFrozen) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3186 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3187 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3188 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3189 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3190 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3191 | // Opening a new task always supersedes a close for the anim. |
| 3192 | mNextAppTransition = transit; |
| 3193 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3194 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3195 | // Opening a new activity always supersedes a close for the anim. |
| 3196 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | } |
| 3198 | mAppTransitionReady = false; |
| 3199 | mAppTransitionTimeout = false; |
| 3200 | mStartingIconInTransition = false; |
| 3201 | mSkipAppTransitionAnimation = false; |
| 3202 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3203 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3204 | 5000); |
| 3205 | } |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | public int getPendingAppTransition() { |
| 3210 | return mNextAppTransition; |
| 3211 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3212 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3213 | public void overridePendingAppTransition(String packageName, |
| 3214 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3215 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3216 | mNextAppTransitionPackage = packageName; |
| 3217 | mNextAppTransitionEnter = enterAnim; |
| 3218 | mNextAppTransitionExit = exitAnim; |
| 3219 | } |
| 3220 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | public void executeAppTransition() { |
| 3223 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3224 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3225 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3228 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3229 | if (DEBUG_APP_TRANSITIONS) { |
| 3230 | RuntimeException e = new RuntimeException("here"); |
| 3231 | e.fillInStackTrace(); |
| 3232 | Log.w(TAG, "Execute app transition: mNextAppTransition=" |
| 3233 | + mNextAppTransition, e); |
| 3234 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3235 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | mAppTransitionReady = true; |
| 3237 | final long origId = Binder.clearCallingIdentity(); |
| 3238 | performLayoutAndPlaceSurfacesLocked(); |
| 3239 | Binder.restoreCallingIdentity(origId); |
| 3240 | } |
| 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3245 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3246 | IBinder transferFrom, boolean createIfNeeded) { |
| 3247 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3248 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3249 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | synchronized(mWindowMap) { |
| 3253 | if (DEBUG_STARTING_WINDOW) Log.v( |
| 3254 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3255 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3257 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3258 | if (wtoken == null) { |
| 3259 | Log.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| 3260 | return; |
| 3261 | } |
| 3262 | |
| 3263 | // If the display is frozen, we won't do anything until the |
| 3264 | // actual window is displayed so there is no reason to put in |
| 3265 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3266 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | return; |
| 3268 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3269 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3270 | if (wtoken.startingData != null) { |
| 3271 | return; |
| 3272 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3273 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | if (transferFrom != null) { |
| 3275 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3276 | if (ttoken != null) { |
| 3277 | WindowState startingWindow = ttoken.startingWindow; |
| 3278 | if (startingWindow != null) { |
| 3279 | if (mStartingIconInTransition) { |
| 3280 | // In this case, the starting icon has already |
| 3281 | // been displayed, so start letting windows get |
| 3282 | // shown immediately without any more transitions. |
| 3283 | mSkipAppTransitionAnimation = true; |
| 3284 | } |
| 3285 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3286 | "Moving existing starting from " + ttoken |
| 3287 | + " to " + wtoken); |
| 3288 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3289 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | // Transfer the starting window over to the new |
| 3291 | // token. |
| 3292 | wtoken.startingData = ttoken.startingData; |
| 3293 | wtoken.startingView = ttoken.startingView; |
| 3294 | wtoken.startingWindow = startingWindow; |
| 3295 | ttoken.startingData = null; |
| 3296 | ttoken.startingView = null; |
| 3297 | ttoken.startingWindow = null; |
| 3298 | ttoken.startingMoved = true; |
| 3299 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3300 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3301 | startingWindow.mAppToken = wtoken; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3302 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3303 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3304 | mWindows.remove(startingWindow); |
| 3305 | ttoken.windows.remove(startingWindow); |
| 3306 | ttoken.allAppWindows.remove(startingWindow); |
| 3307 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3308 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3309 | // Propagate other interesting state between the |
| 3310 | // tokens. If the old token is displayed, we should |
| 3311 | // immediately force the new one to be displayed. If |
| 3312 | // it is animating, we need to move that animation to |
| 3313 | // the new one. |
| 3314 | if (ttoken.allDrawn) { |
| 3315 | wtoken.allDrawn = true; |
| 3316 | } |
| 3317 | if (ttoken.firstWindowDrawn) { |
| 3318 | wtoken.firstWindowDrawn = true; |
| 3319 | } |
| 3320 | if (!ttoken.hidden) { |
| 3321 | wtoken.hidden = false; |
| 3322 | wtoken.hiddenRequested = false; |
| 3323 | wtoken.willBeHidden = false; |
| 3324 | } |
| 3325 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3326 | wtoken.clientHidden = ttoken.clientHidden; |
| 3327 | wtoken.sendAppVisibilityToClients(); |
| 3328 | } |
| 3329 | if (ttoken.animation != null) { |
| 3330 | wtoken.animation = ttoken.animation; |
| 3331 | wtoken.animating = ttoken.animating; |
| 3332 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3333 | ttoken.animation = null; |
| 3334 | ttoken.animLayerAdjustment = 0; |
| 3335 | wtoken.updateLayers(); |
| 3336 | ttoken.updateLayers(); |
| 3337 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3339 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | mLayoutNeeded = true; |
| 3341 | performLayoutAndPlaceSurfacesLocked(); |
| 3342 | Binder.restoreCallingIdentity(origId); |
| 3343 | return; |
| 3344 | } else if (ttoken.startingData != null) { |
| 3345 | // The previous app was getting ready to show a |
| 3346 | // starting window, but hasn't yet done so. Steal it! |
| 3347 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3348 | "Moving pending starting from " + ttoken |
| 3349 | + " to " + wtoken); |
| 3350 | wtoken.startingData = ttoken.startingData; |
| 3351 | ttoken.startingData = null; |
| 3352 | ttoken.startingMoved = true; |
| 3353 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3354 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3355 | // want to process the message ASAP, before any other queued |
| 3356 | // messages. |
| 3357 | mH.sendMessageAtFrontOfQueue(m); |
| 3358 | return; |
| 3359 | } |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | // There is no existing starting window, and the caller doesn't |
| 3364 | // want us to create one, so that's it! |
| 3365 | if (!createIfNeeded) { |
| 3366 | return; |
| 3367 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3368 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3369 | // If this is a translucent or wallpaper window, then don't |
| 3370 | // show a starting window -- the current effect (a full-screen |
| 3371 | // opaque starting window that fades away to the real contents |
| 3372 | // when it is ready) does not work for this. |
| 3373 | if (theme != 0) { |
| 3374 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3375 | com.android.internal.R.styleable.Window); |
| 3376 | if (ent.array.getBoolean( |
| 3377 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3378 | return; |
| 3379 | } |
| 3380 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3381 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3382 | return; |
| 3383 | } |
| 3384 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3385 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3386 | return; |
| 3387 | } |
| 3388 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | mStartingIconInTransition = true; |
| 3391 | wtoken.startingData = new StartingData( |
| 3392 | pkg, theme, nonLocalizedLabel, |
| 3393 | labelRes, icon); |
| 3394 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3395 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3396 | // want to process the message ASAP, before any other queued |
| 3397 | // messages. |
| 3398 | mH.sendMessageAtFrontOfQueue(m); |
| 3399 | } |
| 3400 | } |
| 3401 | |
| 3402 | public void setAppWillBeHidden(IBinder token) { |
| 3403 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3404 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3405 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | AppWindowToken wtoken; |
| 3409 | |
| 3410 | synchronized(mWindowMap) { |
| 3411 | wtoken = findAppWindowToken(token); |
| 3412 | if (wtoken == null) { |
| 3413 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 3414 | return; |
| 3415 | } |
| 3416 | wtoken.willBeHidden = true; |
| 3417 | } |
| 3418 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3420 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3421 | boolean visible, int transit, boolean performLayout) { |
| 3422 | boolean delayed = false; |
| 3423 | |
| 3424 | if (wtoken.clientHidden == visible) { |
| 3425 | wtoken.clientHidden = !visible; |
| 3426 | wtoken.sendAppVisibilityToClients(); |
| 3427 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3428 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | wtoken.willBeHidden = false; |
| 3430 | if (wtoken.hidden == visible) { |
| 3431 | final int N = wtoken.allAppWindows.size(); |
| 3432 | boolean changed = false; |
| 3433 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3434 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3435 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3438 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3439 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | if (wtoken.animation == sDummyAnimation) { |
| 3441 | wtoken.animation = null; |
| 3442 | } |
| 3443 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3444 | changed = true; |
| 3445 | if (wtoken.animation != null) { |
| 3446 | delayed = runningAppAnimation = true; |
| 3447 | } |
| 3448 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3450 | for (int i=0; i<N; i++) { |
| 3451 | WindowState win = wtoken.allAppWindows.get(i); |
| 3452 | if (win == wtoken.startingWindow) { |
| 3453 | continue; |
| 3454 | } |
| 3455 | |
| 3456 | if (win.isAnimating()) { |
| 3457 | delayed = true; |
| 3458 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 3461 | //win.dump(" "); |
| 3462 | if (visible) { |
| 3463 | if (!win.isVisibleNow()) { |
| 3464 | if (!runningAppAnimation) { |
| 3465 | applyAnimationLocked(win, |
| 3466 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3467 | } |
| 3468 | changed = true; |
| 3469 | } |
| 3470 | } else if (win.isVisibleNow()) { |
| 3471 | if (!runningAppAnimation) { |
| 3472 | applyAnimationLocked(win, |
| 3473 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3474 | } |
| 3475 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3476 | KeyWaiter.RETURN_NOTHING); |
| 3477 | changed = true; |
| 3478 | } |
| 3479 | } |
| 3480 | |
| 3481 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3482 | if (!visible) { |
| 3483 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3484 | } else { |
| 3485 | // If we are being set visible, and the starting window is |
| 3486 | // not yet displayed, then make sure it doesn't get displayed. |
| 3487 | WindowState swin = wtoken.startingWindow; |
| 3488 | if (swin != null && (swin.mDrawPending |
| 3489 | || swin.mCommitDrawPending)) { |
| 3490 | swin.mPolicyVisibility = false; |
| 3491 | swin.mPolicyVisibilityAfterAnim = false; |
| 3492 | } |
| 3493 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3495 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 3496 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3497 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3498 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3499 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3501 | if (performLayout) { |
| 3502 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3503 | performLayoutAndPlaceSurfacesLocked(); |
| 3504 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | } |
| 3506 | } |
| 3507 | |
| 3508 | if (wtoken.animation != null) { |
| 3509 | delayed = true; |
| 3510 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3511 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3512 | return delayed; |
| 3513 | } |
| 3514 | |
| 3515 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3516 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3517 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3518 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | AppWindowToken wtoken; |
| 3522 | |
| 3523 | synchronized(mWindowMap) { |
| 3524 | wtoken = findAppWindowToken(token); |
| 3525 | if (wtoken == null) { |
| 3526 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 3527 | return; |
| 3528 | } |
| 3529 | |
| 3530 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 3531 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3532 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 3534 | + "): mNextAppTransition=" + mNextAppTransition |
| 3535 | + " hidden=" + wtoken.hidden |
| 3536 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3537 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | // If we are preparing an app transition, then delay changing |
| 3540 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3541 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | // Already in requested state, don't do anything more. |
| 3543 | if (wtoken.hiddenRequested != visible) { |
| 3544 | return; |
| 3545 | } |
| 3546 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3547 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3549 | TAG, "Setting dummy animation on: " + wtoken); |
| 3550 | wtoken.setDummyAnimation(); |
| 3551 | mOpeningApps.remove(wtoken); |
| 3552 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3553 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | wtoken.inPendingTransaction = true; |
| 3555 | if (visible) { |
| 3556 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | wtoken.startingDisplayed = false; |
| 3558 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3559 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3560 | // If the token is currently hidden (should be the |
| 3561 | // common case), then we need to set up to wait for |
| 3562 | // its windows to be ready. |
| 3563 | if (wtoken.hidden) { |
| 3564 | wtoken.allDrawn = false; |
| 3565 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3566 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3567 | if (wtoken.clientHidden) { |
| 3568 | // In the case where we are making an app visible |
| 3569 | // but holding off for a transition, we still need |
| 3570 | // to tell the client to make its windows visible so |
| 3571 | // they get drawn. Otherwise, we will wait on |
| 3572 | // performing the transition until all windows have |
| 3573 | // been drawn, they never will be, and we are sad. |
| 3574 | wtoken.clientHidden = false; |
| 3575 | wtoken.sendAppVisibilityToClients(); |
| 3576 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | } |
| 3578 | } else { |
| 3579 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3580 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3581 | // If the token is currently visible (should be the |
| 3582 | // common case), then set up to wait for it to be hidden. |
| 3583 | if (!wtoken.hidden) { |
| 3584 | wtoken.waitingToHide = true; |
| 3585 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | } |
| 3587 | return; |
| 3588 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3589 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3590 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3591 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | wtoken.updateReportedVisibilityLocked(); |
| 3593 | Binder.restoreCallingIdentity(origId); |
| 3594 | } |
| 3595 | } |
| 3596 | |
| 3597 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3598 | boolean unfreezeSurfaceNow, boolean force) { |
| 3599 | if (wtoken.freezingScreen) { |
| 3600 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 3601 | + " force=" + force); |
| 3602 | final int N = wtoken.allAppWindows.size(); |
| 3603 | boolean unfrozeWindows = false; |
| 3604 | for (int i=0; i<N; i++) { |
| 3605 | WindowState w = wtoken.allAppWindows.get(i); |
| 3606 | if (w.mAppFreezing) { |
| 3607 | w.mAppFreezing = false; |
| 3608 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3609 | w.mOrientationChanging = true; |
| 3610 | } |
| 3611 | unfrozeWindows = true; |
| 3612 | } |
| 3613 | } |
| 3614 | if (force || unfrozeWindows) { |
| 3615 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 3616 | wtoken.freezingScreen = false; |
| 3617 | mAppsFreezingScreen--; |
| 3618 | } |
| 3619 | if (unfreezeSurfaceNow) { |
| 3620 | if (unfrozeWindows) { |
| 3621 | mLayoutNeeded = true; |
| 3622 | performLayoutAndPlaceSurfacesLocked(); |
| 3623 | } |
| 3624 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 3625 | stopFreezingDisplayLocked(); |
| 3626 | } |
| 3627 | } |
| 3628 | } |
| 3629 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3630 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3631 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3632 | int configChanges) { |
| 3633 | if (DEBUG_ORIENTATION) { |
| 3634 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3635 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3636 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 3637 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3638 | + wtoken.freezingScreen, e); |
| 3639 | } |
| 3640 | if (!wtoken.hiddenRequested) { |
| 3641 | if (!wtoken.freezingScreen) { |
| 3642 | wtoken.freezingScreen = true; |
| 3643 | mAppsFreezingScreen++; |
| 3644 | if (mAppsFreezingScreen == 1) { |
| 3645 | startFreezingDisplayLocked(); |
| 3646 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3647 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3648 | 5000); |
| 3649 | } |
| 3650 | } |
| 3651 | final int N = wtoken.allAppWindows.size(); |
| 3652 | for (int i=0; i<N; i++) { |
| 3653 | WindowState w = wtoken.allAppWindows.get(i); |
| 3654 | w.mAppFreezing = true; |
| 3655 | } |
| 3656 | } |
| 3657 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3658 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3659 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3660 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3661 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3662 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | synchronized(mWindowMap) { |
| 3666 | if (configChanges == 0 && !mDisplayFrozen) { |
| 3667 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 3668 | return; |
| 3669 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3670 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3672 | if (wtoken == null || wtoken.appToken == null) { |
| 3673 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 3674 | return; |
| 3675 | } |
| 3676 | final long origId = Binder.clearCallingIdentity(); |
| 3677 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3678 | Binder.restoreCallingIdentity(origId); |
| 3679 | } |
| 3680 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3681 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3683 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3684 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3685 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | synchronized(mWindowMap) { |
| 3689 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3690 | if (wtoken == null || wtoken.appToken == null) { |
| 3691 | return; |
| 3692 | } |
| 3693 | final long origId = Binder.clearCallingIdentity(); |
| 3694 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 3695 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3696 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3697 | Binder.restoreCallingIdentity(origId); |
| 3698 | } |
| 3699 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3700 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | public void removeAppToken(IBinder token) { |
| 3702 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3703 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3704 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | AppWindowToken wtoken = null; |
| 3708 | AppWindowToken startingToken = null; |
| 3709 | boolean delayed = false; |
| 3710 | |
| 3711 | final long origId = Binder.clearCallingIdentity(); |
| 3712 | synchronized(mWindowMap) { |
| 3713 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3714 | mTokenList.remove(basewtoken); |
| 3715 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 3716 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3717 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3718 | wtoken.inPendingTransaction = false; |
| 3719 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3720 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | if (mClosingApps.contains(wtoken)) { |
| 3722 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3723 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3724 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3725 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | delayed = true; |
| 3727 | } |
| 3728 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3729 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3730 | + " animation=" + wtoken.animation |
| 3731 | + " animating=" + wtoken.animating); |
| 3732 | if (delayed) { |
| 3733 | // set the token aside because it has an active animation to be finished |
| 3734 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3735 | } else { |
| 3736 | // Make sure there is no animation running on this token, |
| 3737 | // so any windows associated with it will be removed as |
| 3738 | // soon as their animations are complete |
| 3739 | wtoken.animation = null; |
| 3740 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3741 | } |
| 3742 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3743 | if (mLastEnterAnimToken == wtoken) { |
| 3744 | mLastEnterAnimToken = null; |
| 3745 | mLastEnterAnimParams = null; |
| 3746 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3747 | wtoken.removed = true; |
| 3748 | if (wtoken.startingData != null) { |
| 3749 | startingToken = wtoken; |
| 3750 | } |
| 3751 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3752 | if (mFocusedApp == wtoken) { |
| 3753 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 3754 | mFocusedApp = null; |
| 3755 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3756 | mKeyWaiter.tickle(); |
| 3757 | } |
| 3758 | } else { |
| 3759 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 3760 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | if (!delayed && wtoken != null) { |
| 3763 | wtoken.updateReportedVisibilityLocked(); |
| 3764 | } |
| 3765 | } |
| 3766 | Binder.restoreCallingIdentity(origId); |
| 3767 | |
| 3768 | if (startingToken != null) { |
| 3769 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 3770 | + startingToken + ": app token removed"); |
| 3771 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3772 | mH.sendMessage(m); |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3777 | final int NW = token.windows.size(); |
| 3778 | for (int i=0; i<NW; i++) { |
| 3779 | WindowState win = token.windows.get(i); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3780 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Tmp removing app window " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3781 | mWindows.remove(win); |
| 3782 | int j = win.mChildWindows.size(); |
| 3783 | while (j > 0) { |
| 3784 | j--; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3785 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3786 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3787 | "Tmp removing child window " + cwin); |
| 3788 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3789 | } |
| 3790 | } |
| 3791 | return NW > 0; |
| 3792 | } |
| 3793 | |
| 3794 | void dumpAppTokensLocked() { |
| 3795 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 3796 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 3797 | } |
| 3798 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3799 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | void dumpWindowsLocked() { |
| 3801 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3802 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 3803 | } |
| 3804 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3805 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3806 | private int findWindowOffsetLocked(int tokenPos) { |
| 3807 | final int NW = mWindows.size(); |
| 3808 | |
| 3809 | if (tokenPos >= mAppTokens.size()) { |
| 3810 | int i = NW; |
| 3811 | while (i > 0) { |
| 3812 | i--; |
| 3813 | WindowState win = (WindowState)mWindows.get(i); |
| 3814 | if (win.getAppToken() != null) { |
| 3815 | return i+1; |
| 3816 | } |
| 3817 | } |
| 3818 | } |
| 3819 | |
| 3820 | while (tokenPos > 0) { |
| 3821 | // Find the first app token below the new position that has |
| 3822 | // a window displayed. |
| 3823 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 3824 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 3825 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3826 | if (wtoken.sendingToBottom) { |
| 3827 | if (DEBUG_REORDER) Log.v(TAG, |
| 3828 | "Skipping token -- currently sending to bottom"); |
| 3829 | tokenPos--; |
| 3830 | continue; |
| 3831 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | int i = wtoken.windows.size(); |
| 3833 | while (i > 0) { |
| 3834 | i--; |
| 3835 | WindowState win = wtoken.windows.get(i); |
| 3836 | int j = win.mChildWindows.size(); |
| 3837 | while (j > 0) { |
| 3838 | j--; |
| 3839 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3840 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | for (int pos=NW-1; pos>=0; pos--) { |
| 3842 | if (mWindows.get(pos) == cwin) { |
| 3843 | if (DEBUG_REORDER) Log.v(TAG, |
| 3844 | "Found child win @" + (pos+1)); |
| 3845 | return pos+1; |
| 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | } |
| 3850 | for (int pos=NW-1; pos>=0; pos--) { |
| 3851 | if (mWindows.get(pos) == win) { |
| 3852 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 3853 | return pos+1; |
| 3854 | } |
| 3855 | } |
| 3856 | } |
| 3857 | tokenPos--; |
| 3858 | } |
| 3859 | |
| 3860 | return 0; |
| 3861 | } |
| 3862 | |
| 3863 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3864 | final int NCW = win.mChildWindows.size(); |
| 3865 | boolean added = false; |
| 3866 | for (int j=0; j<NCW; j++) { |
| 3867 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3868 | if (!added && cwin.mSubLayer >= 0) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3869 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding child window at " |
| 3870 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | mWindows.add(index, win); |
| 3872 | index++; |
| 3873 | added = true; |
| 3874 | } |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3875 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3876 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | mWindows.add(index, cwin); |
| 3878 | index++; |
| 3879 | } |
| 3880 | if (!added) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3881 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3882 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | mWindows.add(index, win); |
| 3884 | index++; |
| 3885 | } |
| 3886 | return index; |
| 3887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3890 | final int NW = token.windows.size(); |
| 3891 | for (int i=0; i<NW; i++) { |
| 3892 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3893 | } |
| 3894 | return index; |
| 3895 | } |
| 3896 | |
| 3897 | public void moveAppToken(int index, IBinder token) { |
| 3898 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3899 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3900 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | synchronized(mWindowMap) { |
| 3904 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 3905 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3906 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3907 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 3908 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3909 | + token + " (" + wtoken + ")"); |
| 3910 | return; |
| 3911 | } |
| 3912 | mAppTokens.add(index, wtoken); |
| 3913 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 3914 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | final long origId = Binder.clearCallingIdentity(); |
| 3917 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 3918 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3919 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 3920 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 3921 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3922 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 3923 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 3924 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3925 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3926 | mLayoutNeeded = true; |
| 3927 | performLayoutAndPlaceSurfacesLocked(); |
| 3928 | } |
| 3929 | Binder.restoreCallingIdentity(origId); |
| 3930 | } |
| 3931 | } |
| 3932 | |
| 3933 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3934 | // XXX This should be done more efficiently! |
| 3935 | // (take advantage of the fact that both lists should be |
| 3936 | // ordered in the same way.) |
| 3937 | int N = tokens.size(); |
| 3938 | for (int i=0; i<N; i++) { |
| 3939 | IBinder token = tokens.get(i); |
| 3940 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3941 | if (!mAppTokens.remove(wtoken)) { |
| 3942 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3943 | + token + " (" + wtoken + ")"); |
| 3944 | i--; |
| 3945 | N--; |
| 3946 | } |
| 3947 | } |
| 3948 | } |
| 3949 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3950 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 3951 | boolean updateFocusAndLayout) { |
| 3952 | // First remove all of the windows from the list. |
| 3953 | tmpRemoveAppWindowsLocked(wtoken); |
| 3954 | |
| 3955 | // Where to start adding? |
| 3956 | int pos = findWindowOffsetLocked(tokenPos); |
| 3957 | |
| 3958 | // And now add them back at the correct place. |
| 3959 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 3960 | |
| 3961 | if (updateFocusAndLayout) { |
| 3962 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3963 | assignLayersLocked(); |
| 3964 | } |
| 3965 | mLayoutNeeded = true; |
| 3966 | performLayoutAndPlaceSurfacesLocked(); |
| 3967 | } |
| 3968 | } |
| 3969 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3970 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3971 | // First remove all of the windows from the list. |
| 3972 | final int N = tokens.size(); |
| 3973 | int i; |
| 3974 | for (i=0; i<N; i++) { |
| 3975 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3976 | if (token != null) { |
| 3977 | tmpRemoveAppWindowsLocked(token); |
| 3978 | } |
| 3979 | } |
| 3980 | |
| 3981 | // Where to start adding? |
| 3982 | int pos = findWindowOffsetLocked(tokenPos); |
| 3983 | |
| 3984 | // And now add them back at the correct place. |
| 3985 | for (i=0; i<N; i++) { |
| 3986 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3987 | if (token != null) { |
| 3988 | pos = reAddAppWindowsLocked(pos, token); |
| 3989 | } |
| 3990 | } |
| 3991 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3992 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3993 | assignLayersLocked(); |
| 3994 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3995 | mLayoutNeeded = true; |
| 3996 | performLayoutAndPlaceSurfacesLocked(); |
| 3997 | |
| 3998 | //dump(); |
| 3999 | } |
| 4000 | |
| 4001 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4002 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4003 | "moveAppTokensToTop()")) { |
| 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 | final long origId = Binder.clearCallingIdentity(); |
| 4008 | synchronized(mWindowMap) { |
| 4009 | removeAppTokensLocked(tokens); |
| 4010 | final int N = tokens.size(); |
| 4011 | for (int i=0; i<N; i++) { |
| 4012 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4013 | if (wt != null) { |
| 4014 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4015 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4016 | mToTopApps.remove(wt); |
| 4017 | mToBottomApps.remove(wt); |
| 4018 | mToTopApps.add(wt); |
| 4019 | wt.sendingToBottom = false; |
| 4020 | wt.sendingToTop = true; |
| 4021 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4022 | } |
| 4023 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4024 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4025 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4026 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4027 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | } |
| 4029 | Binder.restoreCallingIdentity(origId); |
| 4030 | } |
| 4031 | |
| 4032 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4033 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4034 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4035 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | final long origId = Binder.clearCallingIdentity(); |
| 4039 | synchronized(mWindowMap) { |
| 4040 | removeAppTokensLocked(tokens); |
| 4041 | final int N = tokens.size(); |
| 4042 | int pos = 0; |
| 4043 | for (int i=0; i<N; i++) { |
| 4044 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4045 | if (wt != null) { |
| 4046 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4047 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4048 | mToTopApps.remove(wt); |
| 4049 | mToBottomApps.remove(wt); |
| 4050 | mToBottomApps.add(i, wt); |
| 4051 | wt.sendingToTop = false; |
| 4052 | wt.sendingToBottom = true; |
| 4053 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | pos++; |
| 4055 | } |
| 4056 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4057 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4058 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4059 | moveAppWindowsLocked(tokens, 0); |
| 4060 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4061 | } |
| 4062 | Binder.restoreCallingIdentity(origId); |
| 4063 | } |
| 4064 | |
| 4065 | // ------------------------------------------------------------- |
| 4066 | // Misc IWindowSession methods |
| 4067 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4068 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4069 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4070 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4071 | != PackageManager.PERMISSION_GRANTED) { |
| 4072 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4073 | } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4074 | synchronized (mKeyguardTokenWatcher) { |
| 4075 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4076 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4080 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4081 | != PackageManager.PERMISSION_GRANTED) { |
| 4082 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4083 | } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4084 | synchronized (mKeyguardTokenWatcher) { |
| 4085 | mKeyguardTokenWatcher.release(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4086 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4087 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4088 | // If we are the last one to reenable the keyguard wait until |
| 4089 | // we have actaully finished reenabling until returning. |
| 4090 | // It is possible that reenableKeyguard() can be called before |
| 4091 | // the previous disableKeyguard() is handled, in which case |
| 4092 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4093 | // be called. In that case mKeyguardDisabled will be false here |
| 4094 | // and we have nothing to wait for. |
| 4095 | while (mKeyguardDisabled) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | try { |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4097 | mKeyguardTokenWatcher.wait(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4098 | } catch (InterruptedException e) { |
| 4099 | Thread.currentThread().interrupt(); |
| 4100 | } |
| 4101 | } |
| 4102 | } |
| 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | /** |
| 4107 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4108 | */ |
| 4109 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4110 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4111 | != PackageManager.PERMISSION_GRANTED) { |
| 4112 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4113 | } |
| 4114 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4115 | public void onKeyguardExitResult(boolean success) { |
| 4116 | try { |
| 4117 | callback.onKeyguardExitResult(success); |
| 4118 | } catch (RemoteException e) { |
| 4119 | // Client has died, we don't care. |
| 4120 | } |
| 4121 | } |
| 4122 | }); |
| 4123 | } |
| 4124 | |
| 4125 | public boolean inKeyguardRestrictedInputMode() { |
| 4126 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4127 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4128 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4129 | public void closeSystemDialogs(String reason) { |
| 4130 | synchronized(mWindowMap) { |
| 4131 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4132 | WindowState w = (WindowState)mWindows.get(i); |
| 4133 | if (w.mSurface != null) { |
| 4134 | try { |
| 4135 | w.mClient.closeSystemDialogs(reason); |
| 4136 | } catch (RemoteException e) { |
| 4137 | } |
| 4138 | } |
| 4139 | } |
| 4140 | } |
| 4141 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4142 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4143 | static float fixScale(float scale) { |
| 4144 | if (scale < 0) scale = 0; |
| 4145 | else if (scale > 20) scale = 20; |
| 4146 | return Math.abs(scale); |
| 4147 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4148 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | public void setAnimationScale(int which, float scale) { |
| 4150 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4151 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4152 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | if (scale < 0) scale = 0; |
| 4156 | else if (scale > 20) scale = 20; |
| 4157 | scale = Math.abs(scale); |
| 4158 | switch (which) { |
| 4159 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4160 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4161 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4162 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | // Persist setting |
| 4164 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4165 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4167 | public void setAnimationScales(float[] scales) { |
| 4168 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4169 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4170 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | if (scales != null) { |
| 4174 | if (scales.length >= 1) { |
| 4175 | mWindowAnimationScale = fixScale(scales[0]); |
| 4176 | } |
| 4177 | if (scales.length >= 2) { |
| 4178 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4179 | } |
| 4180 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4181 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | // Persist setting |
| 4183 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4184 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | public float getAnimationScale(int which) { |
| 4187 | switch (which) { |
| 4188 | case 0: return mWindowAnimationScale; |
| 4189 | case 1: return mTransitionAnimationScale; |
| 4190 | } |
| 4191 | return 0; |
| 4192 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4193 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4194 | public float[] getAnimationScales() { |
| 4195 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4196 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4198 | public int getSwitchState(int sw) { |
| 4199 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4200 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4201 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | } |
| 4203 | return KeyInputQueue.getSwitchState(sw); |
| 4204 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4205 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4206 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4207 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4208 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4209 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4210 | } |
| 4211 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4212 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4213 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4214 | public int getScancodeState(int sw) { |
| 4215 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4216 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4217 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4218 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4219 | return mQueue.getScancodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4220 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4222 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4223 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4224 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4225 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4227 | return mQueue.getScancodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4229 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4230 | public int getTrackballScancodeState(int sw) { |
| 4231 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4232 | "getTrackballScancodeState()")) { |
| 4233 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4234 | } |
| 4235 | return mQueue.getTrackballScancodeState(sw); |
| 4236 | } |
| 4237 | |
| 4238 | public int getDPadScancodeState(int sw) { |
| 4239 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4240 | "getDPadScancodeState()")) { |
| 4241 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4242 | } |
| 4243 | return mQueue.getDPadScancodeState(sw); |
| 4244 | } |
| 4245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4246 | public int getKeycodeState(int sw) { |
| 4247 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4248 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4249 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4250 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4251 | return mQueue.getKeycodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4252 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4255 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4256 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4257 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4259 | return mQueue.getKeycodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4260 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4261 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4262 | public int getTrackballKeycodeState(int sw) { |
| 4263 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4264 | "getTrackballKeycodeState()")) { |
| 4265 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4266 | } |
| 4267 | return mQueue.getTrackballKeycodeState(sw); |
| 4268 | } |
| 4269 | |
| 4270 | public int getDPadKeycodeState(int sw) { |
| 4271 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4272 | "getDPadKeycodeState()")) { |
| 4273 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4274 | } |
| 4275 | return mQueue.getDPadKeycodeState(sw); |
| 4276 | } |
| 4277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 4279 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4282 | public void enableScreenAfterBoot() { |
| 4283 | synchronized(mWindowMap) { |
| 4284 | if (mSystemBooted) { |
| 4285 | return; |
| 4286 | } |
| 4287 | mSystemBooted = true; |
| 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 | performEnableScreen(); |
| 4291 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4292 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4293 | public void enableScreenIfNeededLocked() { |
| 4294 | if (mDisplayEnabled) { |
| 4295 | return; |
| 4296 | } |
| 4297 | if (!mSystemBooted) { |
| 4298 | return; |
| 4299 | } |
| 4300 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4301 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4303 | public void performEnableScreen() { |
| 4304 | synchronized(mWindowMap) { |
| 4305 | if (mDisplayEnabled) { |
| 4306 | return; |
| 4307 | } |
| 4308 | if (!mSystemBooted) { |
| 4309 | return; |
| 4310 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4312 | // Don't enable the screen until all existing windows |
| 4313 | // have been drawn. |
| 4314 | final int N = mWindows.size(); |
| 4315 | for (int i=0; i<N; i++) { |
| 4316 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4317 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | return; |
| 4319 | } |
| 4320 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4321 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4322 | mDisplayEnabled = true; |
| 4323 | if (false) { |
| 4324 | Log.i(TAG, "ENABLING SCREEN!"); |
| 4325 | StringWriter sw = new StringWriter(); |
| 4326 | PrintWriter pw = new PrintWriter(sw); |
| 4327 | this.dump(null, pw, null); |
| 4328 | Log.i(TAG, sw.toString()); |
| 4329 | } |
| 4330 | try { |
| 4331 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4332 | if (surfaceFlinger != null) { |
| 4333 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 4334 | Parcel data = Parcel.obtain(); |
| 4335 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4336 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4337 | data, null, 0); |
| 4338 | data.recycle(); |
| 4339 | } |
| 4340 | } catch (RemoteException ex) { |
| 4341 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 4342 | } |
| 4343 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4344 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4345 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4346 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4347 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4348 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4349 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4350 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4351 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4352 | public void setInTouchMode(boolean mode) { |
| 4353 | synchronized(mWindowMap) { |
| 4354 | mInTouchMode = mode; |
| 4355 | } |
| 4356 | } |
| 4357 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4358 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4359 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4360 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4361 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4362 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4363 | } |
| 4364 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4365 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4367 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4368 | public void setRotationUnchecked(int rotation, |
| 4369 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4370 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 4371 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4373 | long origId = Binder.clearCallingIdentity(); |
| 4374 | boolean changed; |
| 4375 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4376 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4378 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4379 | if (changed) { |
| 4380 | sendNewConfiguration(); |
| 4381 | synchronized(mWindowMap) { |
| 4382 | mLayoutNeeded = true; |
| 4383 | performLayoutAndPlaceSurfacesLocked(); |
| 4384 | } |
| 4385 | } else if (alwaysSendConfiguration) { |
| 4386 | //update configuration ignoring orientation change |
| 4387 | sendNewConfiguration(); |
| 4388 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | Binder.restoreCallingIdentity(origId); |
| 4391 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4392 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4393 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | boolean changed; |
| 4395 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4396 | rotation = mRequestedRotation; |
| 4397 | } else { |
| 4398 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4399 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4400 | } |
| 4401 | if (DEBUG_ORIENTATION) Log.v(TAG, "Overwriting rotation value from " + rotation); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 4402 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | mRotation, mDisplayEnabled); |
| 4404 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 4405 | changed = mDisplayEnabled && mRotation != rotation; |
| 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 | if (changed) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4408 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4409 | "Rotation changed to " + rotation |
| 4410 | + " from " + mRotation |
| 4411 | + " (forceApp=" + mForcedAppOrientation |
| 4412 | + ", req=" + mRequestedRotation + ")"); |
| 4413 | mRotation = rotation; |
| 4414 | mWindowsFreezingScreen = true; |
| 4415 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4416 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4417 | 2000); |
| 4418 | startFreezingDisplayLocked(); |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4419 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4420 | mQueue.setOrientation(rotation); |
| 4421 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4422 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | } |
| 4424 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4425 | WindowState w = (WindowState)mWindows.get(i); |
| 4426 | if (w.mSurface != null) { |
| 4427 | w.mOrientationChanging = true; |
| 4428 | } |
| 4429 | } |
| 4430 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4431 | try { |
| 4432 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4433 | } catch (RemoteException e) { |
| 4434 | } |
| 4435 | } |
| 4436 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | return changed; |
| 4439 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4440 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4441 | public int getRotation() { |
| 4442 | return mRotation; |
| 4443 | } |
| 4444 | |
| 4445 | public int watchRotation(IRotationWatcher watcher) { |
| 4446 | final IBinder watcherBinder = watcher.asBinder(); |
| 4447 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4448 | public void binderDied() { |
| 4449 | synchronized (mWindowMap) { |
| 4450 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4451 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4452 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4453 | if (removed != null) { |
| 4454 | removed.asBinder().unlinkToDeath(this, 0); |
| 4455 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | i--; |
| 4457 | } |
| 4458 | } |
| 4459 | } |
| 4460 | } |
| 4461 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | synchronized (mWindowMap) { |
| 4464 | try { |
| 4465 | watcher.asBinder().linkToDeath(dr, 0); |
| 4466 | mRotationWatchers.add(watcher); |
| 4467 | } catch (RemoteException e) { |
| 4468 | // Client died, no cleanup needed. |
| 4469 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | return mRotation; |
| 4472 | } |
| 4473 | } |
| 4474 | |
| 4475 | /** |
| 4476 | * Starts the view server on the specified port. |
| 4477 | * |
| 4478 | * @param port The port to listener to. |
| 4479 | * |
| 4480 | * @return True if the server was successfully started, false otherwise. |
| 4481 | * |
| 4482 | * @see com.android.server.ViewServer |
| 4483 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4484 | */ |
| 4485 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4486 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | return false; |
| 4488 | } |
| 4489 | |
| 4490 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4491 | return false; |
| 4492 | } |
| 4493 | |
| 4494 | if (port < 1024) { |
| 4495 | return false; |
| 4496 | } |
| 4497 | |
| 4498 | if (mViewServer != null) { |
| 4499 | if (!mViewServer.isRunning()) { |
| 4500 | try { |
| 4501 | return mViewServer.start(); |
| 4502 | } catch (IOException e) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4503 | Log.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4504 | } |
| 4505 | } |
| 4506 | return false; |
| 4507 | } |
| 4508 | |
| 4509 | try { |
| 4510 | mViewServer = new ViewServer(this, port); |
| 4511 | return mViewServer.start(); |
| 4512 | } catch (IOException e) { |
| 4513 | Log.w(TAG, "View server did not start"); |
| 4514 | } |
| 4515 | return false; |
| 4516 | } |
| 4517 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4518 | private boolean isSystemSecure() { |
| 4519 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4520 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4521 | } |
| 4522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4523 | /** |
| 4524 | * Stops the view server if it exists. |
| 4525 | * |
| 4526 | * @return True if the server stopped, false if it wasn't started or |
| 4527 | * couldn't be stopped. |
| 4528 | * |
| 4529 | * @see com.android.server.ViewServer |
| 4530 | */ |
| 4531 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4532 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | return false; |
| 4534 | } |
| 4535 | |
| 4536 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4537 | return false; |
| 4538 | } |
| 4539 | |
| 4540 | if (mViewServer != null) { |
| 4541 | return mViewServer.stop(); |
| 4542 | } |
| 4543 | return false; |
| 4544 | } |
| 4545 | |
| 4546 | /** |
| 4547 | * Indicates whether the view server is running. |
| 4548 | * |
| 4549 | * @return True if the server is running, false otherwise. |
| 4550 | * |
| 4551 | * @see com.android.server.ViewServer |
| 4552 | */ |
| 4553 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4554 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4555 | return false; |
| 4556 | } |
| 4557 | |
| 4558 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4559 | return false; |
| 4560 | } |
| 4561 | |
| 4562 | return mViewServer != null && mViewServer.isRunning(); |
| 4563 | } |
| 4564 | |
| 4565 | /** |
| 4566 | * Lists all availble windows in the system. The listing is written in the |
| 4567 | * specified Socket's output stream with the following syntax: |
| 4568 | * windowHashCodeInHexadecimal windowName |
| 4569 | * Each line of the ouput represents a different window. |
| 4570 | * |
| 4571 | * @param client The remote client to send the listing to. |
| 4572 | * @return False if an error occured, true otherwise. |
| 4573 | */ |
| 4574 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4575 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4576 | return false; |
| 4577 | } |
| 4578 | |
| 4579 | boolean result = true; |
| 4580 | |
| 4581 | Object[] windows; |
| 4582 | synchronized (mWindowMap) { |
| 4583 | windows = new Object[mWindows.size()]; |
| 4584 | //noinspection unchecked |
| 4585 | windows = mWindows.toArray(windows); |
| 4586 | } |
| 4587 | |
| 4588 | BufferedWriter out = null; |
| 4589 | |
| 4590 | // Any uncaught exception will crash the system process |
| 4591 | try { |
| 4592 | OutputStream clientStream = client.getOutputStream(); |
| 4593 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4594 | |
| 4595 | final int count = windows.length; |
| 4596 | for (int i = 0; i < count; i++) { |
| 4597 | final WindowState w = (WindowState) windows[i]; |
| 4598 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4599 | out.write(' '); |
| 4600 | out.append(w.mAttrs.getTitle()); |
| 4601 | out.write('\n'); |
| 4602 | } |
| 4603 | |
| 4604 | out.write("DONE.\n"); |
| 4605 | out.flush(); |
| 4606 | } catch (Exception e) { |
| 4607 | result = false; |
| 4608 | } finally { |
| 4609 | if (out != null) { |
| 4610 | try { |
| 4611 | out.close(); |
| 4612 | } catch (IOException e) { |
| 4613 | result = false; |
| 4614 | } |
| 4615 | } |
| 4616 | } |
| 4617 | |
| 4618 | return result; |
| 4619 | } |
| 4620 | |
| 4621 | /** |
| 4622 | * Sends a command to a target window. The result of the command, if any, will be |
| 4623 | * written in the output stream of the specified socket. |
| 4624 | * |
| 4625 | * The parameters must follow this syntax: |
| 4626 | * windowHashcode extra |
| 4627 | * |
| 4628 | * Where XX is the length in characeters of the windowTitle. |
| 4629 | * |
| 4630 | * The first parameter is the target window. The window with the specified hashcode |
| 4631 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4632 | * will be delivered to the target window and as parameters to the command itself. |
| 4633 | * |
| 4634 | * @param client The remote client to sent the result, if any, to. |
| 4635 | * @param command The command to execute. |
| 4636 | * @param parameters The command parameters. |
| 4637 | * |
| 4638 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4639 | * not indicate whether the command itself was successful. |
| 4640 | */ |
| 4641 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4642 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4643 | return false; |
| 4644 | } |
| 4645 | |
| 4646 | boolean success = true; |
| 4647 | Parcel data = null; |
| 4648 | Parcel reply = null; |
| 4649 | |
| 4650 | // Any uncaught exception will crash the system process |
| 4651 | try { |
| 4652 | // Find the hashcode of the window |
| 4653 | int index = parameters.indexOf(' '); |
| 4654 | if (index == -1) { |
| 4655 | index = parameters.length(); |
| 4656 | } |
| 4657 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4658 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | |
| 4660 | // Extract the command's parameter after the window description |
| 4661 | if (index < parameters.length()) { |
| 4662 | parameters = parameters.substring(index + 1); |
| 4663 | } else { |
| 4664 | parameters = ""; |
| 4665 | } |
| 4666 | |
| 4667 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4668 | if (window == null) { |
| 4669 | return false; |
| 4670 | } |
| 4671 | |
| 4672 | data = Parcel.obtain(); |
| 4673 | data.writeInterfaceToken("android.view.IWindow"); |
| 4674 | data.writeString(command); |
| 4675 | data.writeString(parameters); |
| 4676 | data.writeInt(1); |
| 4677 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4678 | |
| 4679 | reply = Parcel.obtain(); |
| 4680 | |
| 4681 | final IBinder binder = window.mClient.asBinder(); |
| 4682 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4683 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4684 | |
| 4685 | reply.readException(); |
| 4686 | |
| 4687 | } catch (Exception e) { |
| 4688 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 4689 | success = false; |
| 4690 | } finally { |
| 4691 | if (data != null) { |
| 4692 | data.recycle(); |
| 4693 | } |
| 4694 | if (reply != null) { |
| 4695 | reply.recycle(); |
| 4696 | } |
| 4697 | } |
| 4698 | |
| 4699 | return success; |
| 4700 | } |
| 4701 | |
| 4702 | private WindowState findWindow(int hashCode) { |
| 4703 | if (hashCode == -1) { |
| 4704 | return getFocusedWindow(); |
| 4705 | } |
| 4706 | |
| 4707 | synchronized (mWindowMap) { |
| 4708 | final ArrayList windows = mWindows; |
| 4709 | final int count = windows.size(); |
| 4710 | |
| 4711 | for (int i = 0; i < count; i++) { |
| 4712 | WindowState w = (WindowState) windows.get(i); |
| 4713 | if (System.identityHashCode(w) == hashCode) { |
| 4714 | return w; |
| 4715 | } |
| 4716 | } |
| 4717 | } |
| 4718 | |
| 4719 | return null; |
| 4720 | } |
| 4721 | |
| 4722 | /* |
| 4723 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4724 | * that to config-changed listeners if appropriate. |
| 4725 | */ |
| 4726 | void sendNewConfiguration() { |
| 4727 | try { |
| 4728 | mActivityManager.updateConfiguration(null); |
| 4729 | } catch (RemoteException e) { |
| 4730 | } |
| 4731 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4732 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4733 | public Configuration computeNewConfiguration() { |
| 4734 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4735 | return computeNewConfigurationLocked(); |
| 4736 | } |
| 4737 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4738 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4739 | Configuration computeNewConfigurationLocked() { |
| 4740 | Configuration config = new Configuration(); |
| 4741 | if (!computeNewConfigurationLocked(config)) { |
| 4742 | return null; |
| 4743 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4744 | return config; |
| 4745 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4746 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4747 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4748 | if (mDisplay == null) { |
| 4749 | return false; |
| 4750 | } |
| 4751 | mQueue.getInputConfiguration(config); |
| 4752 | final int dw = mDisplay.getWidth(); |
| 4753 | final int dh = mDisplay.getHeight(); |
| 4754 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4755 | if (dw < dh) { |
| 4756 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4757 | } else if (dw > dh) { |
| 4758 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4759 | } |
| 4760 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4761 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4762 | DisplayMetrics dm = new DisplayMetrics(); |
| 4763 | mDisplay.getMetrics(dm); |
| 4764 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4765 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4766 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4767 | // Note we only do this once because at this point we don't |
| 4768 | // expect the screen to change in this way at runtime, and want |
| 4769 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4770 | int longSize = dw; |
| 4771 | int shortSize = dh; |
| 4772 | if (longSize < shortSize) { |
| 4773 | int tmp = longSize; |
| 4774 | longSize = shortSize; |
| 4775 | shortSize = tmp; |
| 4776 | } |
| 4777 | longSize = (int)(longSize/dm.density); |
| 4778 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4779 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4780 | // These semi-magic numbers define our compatibility modes for |
| 4781 | // applications with different screens. Don't change unless you |
| 4782 | // make sure to test lots and lots of apps! |
| 4783 | if (longSize < 470) { |
| 4784 | // This is shorter than an HVGA normal density screen (which |
| 4785 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4786 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4787 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4788 | } else { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4789 | // Is this a large screen? |
| 4790 | if (longSize > 640 && shortSize >= 480) { |
| 4791 | // VGA or larger screens at medium density are the point |
| 4792 | // at which we consider it to be a large screen. |
| 4793 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4794 | } else { |
| 4795 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4796 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4797 | // If this screen is wider than normal HVGA, or taller |
| 4798 | // than FWVGA, then for old apps we want to run in size |
| 4799 | // compatibility mode. |
| 4800 | if (shortSize > 321 || longSize > 570) { |
| 4801 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4802 | } |
| 4803 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4804 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4805 | // Is this a long screen? |
| 4806 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4807 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4808 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4809 | } else { |
| 4810 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4811 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4812 | } |
| 4813 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4814 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4815 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4816 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4817 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4818 | mPolicy.adjustConfigurationLw(config); |
| 4819 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4821 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | // ------------------------------------------------------------- |
| 4823 | // Input Events and Focus Management |
| 4824 | // ------------------------------------------------------------- |
| 4825 | |
| 4826 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4827 | long curTime = SystemClock.uptimeMillis(); |
| 4828 | |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4829 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4830 | if (mLastTouchEventType == eventType && |
| 4831 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4832 | return; |
| 4833 | } |
| 4834 | mLastUserActivityCallTime = curTime; |
| 4835 | mLastTouchEventType = eventType; |
| 4836 | } |
| 4837 | |
| 4838 | if (targetWin == null |
| 4839 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4840 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | // tells if it's a cheek event or not -- this function is stateful |
| 4845 | private static final int EVENT_NONE = 0; |
| 4846 | private static final int EVENT_UNKNOWN = 0; |
| 4847 | private static final int EVENT_CHEEK = 0; |
| 4848 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4849 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4850 | private int mEventState = EVENT_NONE; |
| 4851 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4852 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4853 | private int eventType(MotionEvent ev) { |
| 4854 | float size = ev.getSize(); |
| 4855 | switch (ev.getAction()) { |
| 4856 | case MotionEvent.ACTION_DOWN: |
| 4857 | mEventSize = size; |
| 4858 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4859 | case MotionEvent.ACTION_UP: |
| 4860 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4861 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4862 | case MotionEvent.ACTION_MOVE: |
| 4863 | final int N = ev.getHistorySize(); |
| 4864 | if (size > mEventSize) mEventSize = size; |
| 4865 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4866 | for (int i=0; i<N; i++) { |
| 4867 | size = ev.getHistoricalSize(i); |
| 4868 | if (size > mEventSize) mEventSize = size; |
| 4869 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4870 | } |
| 4871 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4872 | return TOUCH_EVENT; |
| 4873 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4874 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4875 | } |
| 4876 | default: |
| 4877 | // not good |
| 4878 | return OTHER_EVENT; |
| 4879 | } |
| 4880 | } |
| 4881 | |
| 4882 | /** |
| 4883 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4884 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4885 | private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 4887 | "dispatchPointer " + ev); |
| 4888 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4889 | if (MEASURE_LATENCY) { |
| 4890 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 4891 | } |
| 4892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4894 | ev, true, false, pid, uid); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4895 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4896 | if (MEASURE_LATENCY) { |
| 4897 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 4898 | } |
| 4899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4902 | if (action == MotionEvent.ACTION_UP) { |
| 4903 | // let go of our target |
| 4904 | mKeyWaiter.mMotionTarget = null; |
| 4905 | mPowerManager.logPointerUpEvent(); |
| 4906 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 4907 | mPowerManager.logPointerDownEvent(); |
| 4908 | } |
| 4909 | |
| 4910 | if (targetObj == null) { |
| 4911 | // In this case we are either dropping the event, or have received |
| 4912 | // a move or up without a down. It is common to receive move |
| 4913 | // events in such a way, since this means the user is moving the |
| 4914 | // pointer without actually pressing down. All other cases should |
| 4915 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4916 | if (action != MotionEvent.ACTION_MOVE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4917 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 4918 | } |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 4919 | synchronized (mWindowMap) { |
| 4920 | if (mSendingPointersToWallpaper) { |
| 4921 | Log.i(TAG, "Sending skipped pointer to wallpaper!"); |
| 4922 | sendPointerToWallpaperLocked(null, ev, ev.getEventTime()); |
| 4923 | } |
| 4924 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4925 | if (qev != null) { |
| 4926 | mQueue.recycleEvent(qev); |
| 4927 | } |
| 4928 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4929 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4930 | } |
| 4931 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 4932 | synchronized (mWindowMap) { |
| 4933 | if (mSendingPointersToWallpaper) { |
| 4934 | Log.i(TAG, "Sending skipped pointer to wallpaper!"); |
| 4935 | sendPointerToWallpaperLocked(null, ev, ev.getEventTime()); |
| 4936 | } |
| 4937 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4938 | if (qev != null) { |
| 4939 | mQueue.recycleEvent(qev); |
| 4940 | } |
| 4941 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4942 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4943 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4944 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4945 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | final long eventTime = ev.getEventTime(); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4948 | final long eventTimeNano = ev.getEventTimeNano(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4950 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 4951 | |
| 4952 | if (uid != 0 && uid != target.mSession.mUid) { |
| 4953 | if (mContext.checkPermission( |
| 4954 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4955 | != PackageManager.PERMISSION_GRANTED) { |
| 4956 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 4957 | + pid + " uid " + uid + " to window " + target |
| 4958 | + " owned by uid " + target.mSession.mUid); |
| 4959 | if (qev != null) { |
| 4960 | mQueue.recycleEvent(qev); |
| 4961 | } |
| 4962 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4963 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4964 | } |
| 4965 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4966 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4967 | if (MEASURE_LATENCY) { |
| 4968 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4969 | } |
| 4970 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4971 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4972 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 4973 | //target wants to ignore fat touch events |
| 4974 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 4975 | //explicit flag to return without processing event further |
| 4976 | boolean returnFlag = false; |
| 4977 | if((action == MotionEvent.ACTION_DOWN)) { |
| 4978 | mFatTouch = false; |
| 4979 | if(cheekPress) { |
| 4980 | mFatTouch = true; |
| 4981 | returnFlag = true; |
| 4982 | } |
| 4983 | } else { |
| 4984 | if(action == MotionEvent.ACTION_UP) { |
| 4985 | if(mFatTouch) { |
| 4986 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 4987 | mFatTouch = false; |
| 4988 | returnFlag = true; |
| 4989 | } else if(cheekPress) { |
| 4990 | //cancel the earlier event |
| 4991 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4992 | action = MotionEvent.ACTION_CANCEL; |
| 4993 | } |
| 4994 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 4995 | if(mFatTouch) { |
| 4996 | //two cases here |
| 4997 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4998 | //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] | 4999 | returnFlag = true; |
| 5000 | } else if(cheekPress) { |
| 5001 | //valid down followed by invalid moves |
| 5002 | //an invalid move have to cancel earlier action |
| 5003 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5004 | action = MotionEvent.ACTION_CANCEL; |
| 5005 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 5006 | //note that the subsequent invalid moves will not get here |
| 5007 | mFatTouch = true; |
| 5008 | } |
| 5009 | } |
| 5010 | } //else if action |
| 5011 | if(returnFlag) { |
| 5012 | //recycle que, ev |
| 5013 | if (qev != null) { |
| 5014 | mQueue.recycleEvent(qev); |
| 5015 | } |
| 5016 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5017 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5018 | } |
| 5019 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5020 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 5021 | // Enable this for testing the "right" value |
| 5022 | if (false && action == MotionEvent.ACTION_DOWN) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5023 | int max_events_per_sec = 35; |
| 5024 | try { |
| 5025 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 5026 | .get("windowsmgr.max_events_per_sec")); |
| 5027 | if (max_events_per_sec < 1) { |
| 5028 | max_events_per_sec = 35; |
| 5029 | } |
| 5030 | } catch (NumberFormatException e) { |
| 5031 | } |
| 5032 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 5033 | } |
| 5034 | |
| 5035 | /* |
| 5036 | * Throttle events to minimize CPU usage when there's a flood of events |
| 5037 | * e.g. constant contact with the screen |
| 5038 | */ |
| 5039 | if (action == MotionEvent.ACTION_MOVE) { |
| 5040 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 5041 | long now = SystemClock.uptimeMillis(); |
| 5042 | if (now < nextEventTime) { |
| 5043 | try { |
| 5044 | Thread.sleep(nextEventTime - now); |
| 5045 | } catch (InterruptedException e) { |
| 5046 | } |
| 5047 | mLastTouchEventTime = nextEventTime; |
| 5048 | } else { |
| 5049 | mLastTouchEventTime = now; |
| 5050 | } |
| 5051 | } |
| 5052 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5053 | if (MEASURE_LATENCY) { |
| 5054 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5055 | } |
| 5056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5057 | synchronized(mWindowMap) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5058 | if (!target.isVisibleLw()) { |
| 5059 | // During this motion dispatch, the target window has become |
| 5060 | // invisible. |
| 5061 | if (mSendingPointersToWallpaper) { |
| 5062 | sendPointerToWallpaperLocked(null, ev, eventTime); |
| 5063 | } |
| 5064 | if (qev != null) { |
| 5065 | mQueue.recycleEvent(qev); |
| 5066 | } |
| 5067 | ev.recycle(); |
| 5068 | return INJECT_SUCCEEDED; |
| 5069 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5070 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5071 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 5072 | mKeyWaiter.bindTargetWindowLocked(target, |
| 5073 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 5074 | ev = null; |
| 5075 | } else { |
| 5076 | if (action == MotionEvent.ACTION_DOWN) { |
| 5077 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 5078 | if (out != null) { |
| 5079 | MotionEvent oev = MotionEvent.obtain(ev); |
| 5080 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 5081 | do { |
| 5082 | final Rect frame = out.mFrame; |
| 5083 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5084 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5085 | out.mClient.dispatchPointer(oev, eventTime, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5086 | } catch (android.os.RemoteException e) { |
| 5087 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 5088 | } |
| 5089 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 5090 | out = out.mNextOutsideTouch; |
| 5091 | } while (out != null); |
| 5092 | mKeyWaiter.mOutsideTouchTargets = null; |
| 5093 | } |
| 5094 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5095 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5096 | // If we are on top of the wallpaper, then the wallpaper also |
| 5097 | // gets to see this movement. |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 5098 | if ((mWallpaperTarget == target && |
| 5099 | target.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) |
| 5100 | || mSendingPointersToWallpaper) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5101 | sendPointerToWallpaperLocked(null, ev, eventTime); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5102 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5103 | |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5104 | final Rect frame = target.mFrame; |
| 5105 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5106 | mKeyWaiter.bindTargetWindowLocked(target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5107 | } |
| 5108 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5110 | // finally offset the event to the target's coordinate system and |
| 5111 | // dispatch the event. |
| 5112 | try { |
| 5113 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 5114 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 5115 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5116 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5117 | if (MEASURE_LATENCY) { |
| 5118 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5119 | } |
| 5120 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5121 | target.mClient.dispatchPointer(ev, eventTime, true); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5122 | |
| 5123 | if (MEASURE_LATENCY) { |
| 5124 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5125 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5126 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5127 | } catch (android.os.RemoteException e) { |
| 5128 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 5129 | mKeyWaiter.mMotionTarget = null; |
| 5130 | try { |
| 5131 | removeWindow(target.mSession, target.mClient); |
| 5132 | } catch (java.util.NoSuchElementException ex) { |
| 5133 | // This will happen if the window has already been |
| 5134 | // removed. |
| 5135 | } |
| 5136 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5137 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5138 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5140 | /** |
| 5141 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5142 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5143 | private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5144 | if (DEBUG_INPUT) Log.v( |
| 5145 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5147 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5148 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | if (focusObj == null) { |
| 5150 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 5151 | if (qev != null) { |
| 5152 | mQueue.recycleEvent(qev); |
| 5153 | } |
| 5154 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5155 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | } |
| 5157 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 5158 | if (qev != null) { |
| 5159 | mQueue.recycleEvent(qev); |
| 5160 | } |
| 5161 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5162 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5163 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5164 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5165 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5167 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5168 | if (mContext.checkPermission( |
| 5169 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5170 | != PackageManager.PERMISSION_GRANTED) { |
| 5171 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5172 | + pid + " uid " + uid + " to window " + focus |
| 5173 | + " owned by uid " + focus.mSession.mUid); |
| 5174 | if (qev != null) { |
| 5175 | mQueue.recycleEvent(qev); |
| 5176 | } |
| 5177 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5178 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | } |
| 5180 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5181 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5182 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | synchronized(mWindowMap) { |
| 5185 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5186 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5187 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5188 | // We don't deliver movement events to the client, we hold |
| 5189 | // them and wait for them to call back. |
| 5190 | ev = null; |
| 5191 | } else { |
| 5192 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5193 | } |
| 5194 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5196 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5197 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5198 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5199 | } catch (android.os.RemoteException e) { |
| 5200 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5201 | try { |
| 5202 | removeWindow(focus.mSession, focus.mClient); |
| 5203 | } catch (java.util.NoSuchElementException ex) { |
| 5204 | // This will happen if the window has already been |
| 5205 | // removed. |
| 5206 | } |
| 5207 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5208 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5209 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | /** |
| 5213 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5214 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5215 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5216 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 5217 | |
| 5218 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5219 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5220 | if (focusObj == null) { |
| 5221 | Log.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5222 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5223 | } |
| 5224 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5225 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5227 | |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5228 | // Okay we have finished waiting for the last event to be processed. |
| 5229 | // First off, if this is a repeat event, check to see if there is |
| 5230 | // a corresponding up event in the queue. If there is, we will |
| 5231 | // just drop the repeat, because it makes no sense to repeat after |
| 5232 | // the user has released a key. (This is especially important for |
| 5233 | // long presses.) |
| 5234 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5235 | return INJECT_SUCCEEDED; |
| 5236 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5237 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5238 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5239 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5240 | if (DEBUG_INPUT) Log.v( |
| 5241 | TAG, "Dispatching to " + focus + ": " + event); |
| 5242 | |
| 5243 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5244 | if (mContext.checkPermission( |
| 5245 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5246 | != PackageManager.PERMISSION_GRANTED) { |
| 5247 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5248 | + pid + " uid " + uid + " to window " + focus |
| 5249 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5250 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5251 | } |
| 5252 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5254 | synchronized(mWindowMap) { |
| 5255 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5256 | } |
| 5257 | |
| 5258 | // NOSHIP extra state logging |
| 5259 | mKeyWaiter.recordDispatchState(event, focus); |
| 5260 | // END NOSHIP |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | try { |
| 5263 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 5264 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 5265 | + " to " + focus); |
| 5266 | } |
| 5267 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5268 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5269 | } catch (android.os.RemoteException e) { |
| 5270 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5271 | try { |
| 5272 | removeWindow(focus.mSession, focus.mClient); |
| 5273 | } catch (java.util.NoSuchElementException ex) { |
| 5274 | // This will happen if the window has already been |
| 5275 | // removed. |
| 5276 | } |
| 5277 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5278 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5279 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5282 | public void pauseKeyDispatching(IBinder _token) { |
| 5283 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5284 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5285 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | synchronized (mWindowMap) { |
| 5289 | WindowToken token = mTokenMap.get(_token); |
| 5290 | if (token != null) { |
| 5291 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5292 | } |
| 5293 | } |
| 5294 | } |
| 5295 | |
| 5296 | public void resumeKeyDispatching(IBinder _token) { |
| 5297 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5298 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5299 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | synchronized (mWindowMap) { |
| 5303 | WindowToken token = mTokenMap.get(_token); |
| 5304 | if (token != null) { |
| 5305 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5306 | } |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | public void setEventDispatching(boolean enabled) { |
| 5311 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5312 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5313 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | synchronized (mWindowMap) { |
| 5317 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5318 | } |
| 5319 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5321 | /** |
| 5322 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5323 | * |
| 5324 | * @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] | 5325 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5326 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5327 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5328 | */ |
| 5329 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5330 | long downTime = ev.getDownTime(); |
| 5331 | long eventTime = ev.getEventTime(); |
| 5332 | |
| 5333 | int action = ev.getAction(); |
| 5334 | int code = ev.getKeyCode(); |
| 5335 | int repeatCount = ev.getRepeatCount(); |
| 5336 | int metaState = ev.getMetaState(); |
| 5337 | int deviceId = ev.getDeviceId(); |
| 5338 | int scancode = ev.getScanCode(); |
| 5339 | |
| 5340 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5341 | if (downTime == 0) downTime = eventTime; |
| 5342 | |
| 5343 | 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] | 5344 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5345 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5346 | final int pid = Binder.getCallingPid(); |
| 5347 | final int uid = Binder.getCallingUid(); |
| 5348 | final long ident = Binder.clearCallingIdentity(); |
| 5349 | final int result = dispatchKey(newEvent, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5350 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5351 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5352 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5353 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5354 | switch (result) { |
| 5355 | case INJECT_NO_PERMISSION: |
| 5356 | throw new SecurityException( |
| 5357 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5358 | case INJECT_SUCCEEDED: |
| 5359 | return true; |
| 5360 | } |
| 5361 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | /** |
| 5365 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5366 | * |
| 5367 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5368 | * {@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] | 5369 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5370 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5371 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5372 | */ |
| 5373 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5374 | final int pid = Binder.getCallingPid(); |
| 5375 | final int uid = Binder.getCallingUid(); |
| 5376 | final long ident = Binder.clearCallingIdentity(); |
| 5377 | final int result = dispatchPointer(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5378 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5379 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5381 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5382 | switch (result) { |
| 5383 | case INJECT_NO_PERMISSION: |
| 5384 | throw new SecurityException( |
| 5385 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5386 | case INJECT_SUCCEEDED: |
| 5387 | return true; |
| 5388 | } |
| 5389 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5390 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5391 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5392 | /** |
| 5393 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5394 | * |
| 5395 | * @param ev A motion event describing the trackball action. (As noted in |
| 5396 | * {@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] | 5397 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5398 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5399 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5400 | */ |
| 5401 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5402 | final int pid = Binder.getCallingPid(); |
| 5403 | final int uid = Binder.getCallingUid(); |
| 5404 | final long ident = Binder.clearCallingIdentity(); |
| 5405 | final int result = dispatchTrackball(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5406 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5407 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5408 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5409 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5410 | switch (result) { |
| 5411 | case INJECT_NO_PERMISSION: |
| 5412 | throw new SecurityException( |
| 5413 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5414 | case INJECT_SUCCEEDED: |
| 5415 | return true; |
| 5416 | } |
| 5417 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5418 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5420 | private WindowState getFocusedWindow() { |
| 5421 | synchronized (mWindowMap) { |
| 5422 | return getFocusedWindowLocked(); |
| 5423 | } |
| 5424 | } |
| 5425 | |
| 5426 | private WindowState getFocusedWindowLocked() { |
| 5427 | return mCurrentFocus; |
| 5428 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5429 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5430 | /** |
| 5431 | * This class holds the state for dispatching key events. This state |
| 5432 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 5433 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 5434 | * but not the other way around. |
| 5435 | */ |
| 5436 | final class KeyWaiter { |
| 5437 | // NOSHIP debugging |
| 5438 | public class DispatchState { |
| 5439 | private KeyEvent event; |
| 5440 | private WindowState focus; |
| 5441 | private long time; |
| 5442 | private WindowState lastWin; |
| 5443 | private IBinder lastBinder; |
| 5444 | private boolean finished; |
| 5445 | private boolean gotFirstWindow; |
| 5446 | private boolean eventDispatching; |
| 5447 | private long timeToSwitch; |
| 5448 | private boolean wasFrozen; |
| 5449 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5450 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5452 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5453 | focus = theFocus; |
| 5454 | event = theEvent; |
| 5455 | time = System.currentTimeMillis(); |
| 5456 | // snapshot KeyWaiter state |
| 5457 | lastWin = mLastWin; |
| 5458 | lastBinder = mLastBinder; |
| 5459 | finished = mFinished; |
| 5460 | gotFirstWindow = mGotFirstWindow; |
| 5461 | eventDispatching = mEventDispatching; |
| 5462 | timeToSwitch = mTimeToSwitch; |
| 5463 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5464 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5465 | // cache the paused state at ctor time as well |
| 5466 | if (theFocus == null || theFocus.mToken == null) { |
| 5467 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 5468 | focusPaused = false; |
| 5469 | } else { |
| 5470 | focusPaused = theFocus.mToken.paused; |
| 5471 | } |
| 5472 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5474 | public String toString() { |
| 5475 | return "{{" + event + " to " + focus + " @ " + time |
| 5476 | + " lw=" + lastWin + " lb=" + lastBinder |
| 5477 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 5478 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5479 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 5480 | + " mcf=" + mCurrentFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5481 | } |
| 5482 | }; |
| 5483 | private DispatchState mDispatchState = null; |
| 5484 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5485 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 5486 | } |
| 5487 | // END NOSHIP |
| 5488 | |
| 5489 | public static final int RETURN_NOTHING = 0; |
| 5490 | public static final int RETURN_PENDING_POINTER = 1; |
| 5491 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 5494 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5496 | private WindowState mLastWin = null; |
| 5497 | private IBinder mLastBinder = null; |
| 5498 | private boolean mFinished = true; |
| 5499 | private boolean mGotFirstWindow = false; |
| 5500 | private boolean mEventDispatching = true; |
| 5501 | private long mTimeToSwitch = 0; |
| 5502 | /* package */ boolean mWasFrozen = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5504 | // Target of Motion events |
| 5505 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5507 | // Windows above the target who would like to receive an "outside" |
| 5508 | // touch event for any down events outside of them. |
| 5509 | WindowState mOutsideTouchTargets; |
| 5510 | |
| 5511 | /** |
| 5512 | * Wait for the last event dispatch to complete, then find the next |
| 5513 | * target that should receive the given event and wait for that one |
| 5514 | * to be ready to receive it. |
| 5515 | */ |
| 5516 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5517 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5518 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5519 | long startTime = SystemClock.uptimeMillis(); |
| 5520 | long keyDispatchingTimeout = 5 * 1000; |
| 5521 | long waitedFor = 0; |
| 5522 | |
| 5523 | while (true) { |
| 5524 | // Figure out which window we care about. It is either the |
| 5525 | // last window we are waiting to have process the event or, |
| 5526 | // if none, then the next window we think the event should go |
| 5527 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5528 | // it may change before we lock. Thus we must check it again. |
| 5529 | WindowState targetWin = mLastWin; |
| 5530 | boolean targetIsNew = targetWin == null; |
| 5531 | if (DEBUG_INPUT) Log.v( |
| 5532 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5533 | ", mLastWin=" + mLastWin); |
| 5534 | if (targetIsNew) { |
| 5535 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5536 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5537 | if (target == SKIP_TARGET_TOKEN) { |
| 5538 | // The user has pressed a special key, and we are |
| 5539 | // dropping all pending events before it. |
| 5540 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 5541 | + " " + nextMotion); |
| 5542 | return null; |
| 5543 | } |
| 5544 | if (target == CONSUMED_EVENT_TOKEN) { |
| 5545 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 5546 | + " " + nextMotion); |
| 5547 | return target; |
| 5548 | } |
| 5549 | targetWin = (WindowState)target; |
| 5550 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | AppWindowToken targetApp = null; |
| 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 | // Now: is it okay to send the next event to this window? |
| 5555 | synchronized (this) { |
| 5556 | // First: did we come here based on the last window not |
| 5557 | // being null, but it changed by the time we got here? |
| 5558 | // If so, try again. |
| 5559 | if (!targetIsNew && mLastWin == null) { |
| 5560 | continue; |
| 5561 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5562 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5563 | // We never dispatch events if not finished with the |
| 5564 | // last one, or the display is frozen. |
| 5565 | if (mFinished && !mDisplayFrozen) { |
| 5566 | // If event dispatching is disabled, then we |
| 5567 | // just consume the events. |
| 5568 | if (!mEventDispatching) { |
| 5569 | if (DEBUG_INPUT) Log.v(TAG, |
| 5570 | "Skipping event; dispatching disabled: " |
| 5571 | + nextKey + " " + nextMotion); |
| 5572 | return null; |
| 5573 | } |
| 5574 | if (targetWin != null) { |
| 5575 | // If this is a new target, and that target is not |
| 5576 | // paused or unresponsive, then all looks good to |
| 5577 | // handle the event. |
| 5578 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5579 | return targetWin; |
| 5580 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5581 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | // If we didn't find a target window, and there is no |
| 5583 | // focused app window, then just eat the events. |
| 5584 | } else if (mFocusedApp == null) { |
| 5585 | if (DEBUG_INPUT) Log.v(TAG, |
| 5586 | "Skipping event; no focused app: " |
| 5587 | + nextKey + " " + nextMotion); |
| 5588 | return null; |
| 5589 | } |
| 5590 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5592 | if (DEBUG_INPUT) Log.v( |
| 5593 | TAG, "Waiting for last key in " + mLastBinder |
| 5594 | + " target=" + targetWin |
| 5595 | + " mFinished=" + mFinished |
| 5596 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5597 | + " targetIsNew=" + targetIsNew |
| 5598 | + " paused=" |
| 5599 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5600 | + " mFocusedApp=" + mFocusedApp |
| 5601 | + " mCurrentFocus=" + mCurrentFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5602 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5603 | targetApp = targetWin != null |
| 5604 | ? targetWin.mAppToken : mFocusedApp; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5605 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | long curTimeout = keyDispatchingTimeout; |
| 5607 | if (mTimeToSwitch != 0) { |
| 5608 | long now = SystemClock.uptimeMillis(); |
| 5609 | if (mTimeToSwitch <= now) { |
| 5610 | // If an app switch key has been pressed, and we have |
| 5611 | // waited too long for the current app to finish |
| 5612 | // processing keys, then wait no more! |
| 5613 | doFinishedKeyLocked(true); |
| 5614 | continue; |
| 5615 | } |
| 5616 | long switchTimeout = mTimeToSwitch - now; |
| 5617 | if (curTimeout > switchTimeout) { |
| 5618 | curTimeout = switchTimeout; |
| 5619 | } |
| 5620 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5621 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5622 | try { |
| 5623 | // after that continue |
| 5624 | // processing keys, so we don't get stuck. |
| 5625 | if (DEBUG_INPUT) Log.v( |
| 5626 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5627 | wait(curTimeout); |
| 5628 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 5629 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5630 | + startTime + " switchTime=" + mTimeToSwitch |
| 5631 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5632 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5633 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5634 | } catch (InterruptedException e) { |
| 5635 | } |
| 5636 | } |
| 5637 | |
| 5638 | // If we were frozen during configuration change, restart the |
| 5639 | // timeout checks from now; otherwise look at whether we timed |
| 5640 | // out before awakening. |
| 5641 | if (mWasFrozen) { |
| 5642 | waitedFor = 0; |
| 5643 | mWasFrozen = false; |
| 5644 | } else { |
| 5645 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5646 | } |
| 5647 | |
| 5648 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5649 | IApplicationToken at = null; |
| 5650 | synchronized (this) { |
| 5651 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 5652 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 5653 | : "<null>")); |
| 5654 | // NOSHIP debugging |
| 5655 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 5656 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 5657 | // END NOSHIP |
| 5658 | //dump(); |
| 5659 | if (targetWin != null) { |
| 5660 | at = targetWin.getAppToken(); |
| 5661 | } else if (targetApp != null) { |
| 5662 | at = targetApp.appToken; |
| 5663 | } |
| 5664 | } |
| 5665 | |
| 5666 | boolean abort = true; |
| 5667 | if (at != null) { |
| 5668 | try { |
| 5669 | long timeout = at.getKeyDispatchingTimeout(); |
| 5670 | if (timeout > waitedFor) { |
| 5671 | // we did not wait the proper amount of time for this application. |
| 5672 | // set the timeout to be the real timeout and wait again. |
| 5673 | keyDispatchingTimeout = timeout - waitedFor; |
| 5674 | continue; |
| 5675 | } else { |
| 5676 | abort = at.keyDispatchingTimedOut(); |
| 5677 | } |
| 5678 | } catch (RemoteException ex) { |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | synchronized (this) { |
| 5683 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5684 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5685 | if (mLastWin != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5686 | if (DEBUG_INPUT) Log.v(TAG, |
| 5687 | "Window " + mLastWin + |
| 5688 | " timed out on key input"); |
| 5689 | if (mLastWin.mToken.paused) { |
| 5690 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 5691 | mLastWin.mToken.paused = false; |
| 5692 | } |
| 5693 | } |
| 5694 | if (mMotionTarget == targetWin) { |
| 5695 | mMotionTarget = null; |
| 5696 | } |
| 5697 | mLastWin = null; |
| 5698 | mLastBinder = null; |
| 5699 | if (failIfTimeout || targetWin == null) { |
| 5700 | return null; |
| 5701 | } |
| 5702 | } else { |
| 5703 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 5704 | startTime = SystemClock.uptimeMillis(); |
| 5705 | } |
| 5706 | } |
| 5707 | } |
| 5708 | } |
| 5709 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5710 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5711 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5712 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5713 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5714 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5715 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5716 | if (nextKey != null) { |
| 5717 | // Find the target window for a normal key event. |
| 5718 | final int keycode = nextKey.getKeyCode(); |
| 5719 | final int repeatCount = nextKey.getRepeatCount(); |
| 5720 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5721 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5722 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5723 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5724 | if (callingUid == 0 || |
| 5725 | mContext.checkPermission( |
| 5726 | android.Manifest.permission.INJECT_EVENTS, |
| 5727 | callingPid, callingUid) |
| 5728 | == PackageManager.PERMISSION_GRANTED) { |
| 5729 | mPolicy.interceptKeyTi(null, keycode, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5730 | nextKey.getMetaState(), down, repeatCount, |
| 5731 | nextKey.getFlags()); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5732 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5733 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 5734 | + nextKey); |
| 5735 | return SKIP_TARGET_TOKEN; |
| 5736 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5740 | WindowState focus = null; |
| 5741 | synchronized(mWindowMap) { |
| 5742 | focus = getFocusedWindowLocked(); |
| 5743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5745 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5746 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5747 | if (callingUid == 0 || |
| 5748 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5749 | mContext.checkPermission( |
| 5750 | android.Manifest.permission.INJECT_EVENTS, |
| 5751 | callingPid, callingUid) |
| 5752 | == PackageManager.PERMISSION_GRANTED) { |
| 5753 | if (mPolicy.interceptKeyTi(focus, |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5754 | keycode, nextKey.getMetaState(), down, repeatCount, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5755 | nextKey.getFlags())) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5756 | return CONSUMED_EVENT_TOKEN; |
| 5757 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5759 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5760 | return focus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5762 | } else if (!isPointerEvent) { |
| 5763 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5764 | if (!dispatch) { |
| 5765 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 5766 | + nextMotion); |
| 5767 | return SKIP_TARGET_TOKEN; |
| 5768 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5769 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5770 | WindowState focus = null; |
| 5771 | synchronized(mWindowMap) { |
| 5772 | focus = getFocusedWindowLocked(); |
| 5773 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5774 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5775 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5776 | return focus; |
| 5777 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5778 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5779 | if (nextMotion == null) { |
| 5780 | return SKIP_TARGET_TOKEN; |
| 5781 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5782 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5783 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5784 | KeyEvent.KEYCODE_UNKNOWN); |
| 5785 | if (!dispatch) { |
| 5786 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 5787 | + nextMotion); |
| 5788 | return SKIP_TARGET_TOKEN; |
| 5789 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5790 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | // Find the target window for a pointer event. |
| 5792 | int action = nextMotion.getAction(); |
| 5793 | final float xf = nextMotion.getX(); |
| 5794 | final float yf = nextMotion.getY(); |
| 5795 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5796 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | final boolean screenWasOff = qev != null |
| 5798 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5799 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5800 | WindowState target = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5801 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5802 | synchronized(mWindowMap) { |
| 5803 | synchronized (this) { |
| 5804 | if (action == MotionEvent.ACTION_DOWN) { |
| 5805 | if (mMotionTarget != null) { |
| 5806 | // this is weird, we got a pen down, but we thought it was |
| 5807 | // already down! |
| 5808 | // XXX: We should probably send an ACTION_UP to the current |
| 5809 | // target. |
| 5810 | Log.w(TAG, "Pointer down received while already down in: " |
| 5811 | + mMotionTarget); |
| 5812 | mMotionTarget = null; |
| 5813 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5814 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5815 | // ACTION_DOWN is special, because we need to lock next events to |
| 5816 | // the window we'll land onto. |
| 5817 | final int x = (int)xf; |
| 5818 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5819 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | final ArrayList windows = mWindows; |
| 5821 | final int N = windows.size(); |
| 5822 | WindowState topErrWindow = null; |
| 5823 | final Rect tmpRect = mTempRect; |
| 5824 | for (int i=N-1; i>=0; i--) { |
| 5825 | WindowState child = (WindowState)windows.get(i); |
| 5826 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 5827 | final int flags = child.mAttrs.flags; |
| 5828 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5829 | if (topErrWindow == null) { |
| 5830 | topErrWindow = child; |
| 5831 | } |
| 5832 | } |
| 5833 | if (!child.isVisibleLw()) { |
| 5834 | //Log.i(TAG, "Not visible!"); |
| 5835 | continue; |
| 5836 | } |
| 5837 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 5838 | //Log.i(TAG, "Not touchable!"); |
| 5839 | if ((flags & WindowManager.LayoutParams |
| 5840 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5841 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5842 | mOutsideTouchTargets = child; |
| 5843 | } |
| 5844 | continue; |
| 5845 | } |
| 5846 | tmpRect.set(child.mFrame); |
| 5847 | if (child.mTouchableInsets == ViewTreeObserver |
| 5848 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5849 | // The touch is inside of the window if it is |
| 5850 | // inside the frame, AND the content part of that |
| 5851 | // frame that was given by the application. |
| 5852 | tmpRect.left += child.mGivenContentInsets.left; |
| 5853 | tmpRect.top += child.mGivenContentInsets.top; |
| 5854 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5855 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5856 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5857 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5858 | // The touch is inside of the window if it is |
| 5859 | // inside the frame, AND the visible part of that |
| 5860 | // frame that was given by the application. |
| 5861 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5862 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5863 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5864 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5865 | } |
| 5866 | final int touchFlags = flags & |
| 5867 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5868 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5869 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 5870 | //Log.i(TAG, "Using this target!"); |
| 5871 | if (!screenWasOff || (flags & |
| 5872 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5873 | mMotionTarget = child; |
| 5874 | } else { |
| 5875 | //Log.i(TAG, "Waking, skip!"); |
| 5876 | mMotionTarget = null; |
| 5877 | } |
| 5878 | break; |
| 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 ((flags & WindowManager.LayoutParams |
| 5882 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5883 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5884 | mOutsideTouchTargets = child; |
| 5885 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | // if there's an error window but it's not accepting |
| 5890 | // focus (typically because it is not yet visible) just |
| 5891 | // wait for it -- any other focused window may in fact |
| 5892 | // be in ANR state. |
| 5893 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5894 | mMotionTarget = null; |
| 5895 | } |
| 5896 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5897 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5898 | target = mMotionTarget; |
| 5899 | } |
| 5900 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5902 | wakeupIfNeeded(target, eventType(nextMotion)); |
| 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 | // Pointer events are a little different -- if there isn't a |
| 5905 | // target found for any event, then just drop it. |
| 5906 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 5907 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5909 | boolean checkShouldDispatchKey(int keycode) { |
| 5910 | synchronized (this) { |
| 5911 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 5912 | mTimeToSwitch = 0; |
| 5913 | return true; |
| 5914 | } |
| 5915 | if (mTimeToSwitch != 0 |
| 5916 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 5917 | return false; |
| 5918 | } |
| 5919 | return true; |
| 5920 | } |
| 5921 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5923 | void bindTargetWindowLocked(WindowState win, |
| 5924 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5925 | synchronized (this) { |
| 5926 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 5927 | } |
| 5928 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5929 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5930 | void bindTargetWindowLocked(WindowState win) { |
| 5931 | synchronized (this) { |
| 5932 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 5933 | } |
| 5934 | } |
| 5935 | |
| 5936 | void bindTargetWindowLockedLocked(WindowState win, |
| 5937 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5938 | mLastWin = win; |
| 5939 | mLastBinder = win.mClient.asBinder(); |
| 5940 | mFinished = false; |
| 5941 | if (pendingMotion != null) { |
| 5942 | final Session s = win.mSession; |
| 5943 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 5944 | releasePendingPointerLocked(s); |
| 5945 | s.mPendingPointerMove = pendingMotion; |
| 5946 | s.mPendingPointerWindow = win; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5947 | if (DEBUG_INPUT) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 5949 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 5950 | releasePendingTrackballLocked(s); |
| 5951 | s.mPendingTrackballMove = pendingMotion; |
| 5952 | s.mPendingTrackballWindow = win; |
| 5953 | } |
| 5954 | } |
| 5955 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5956 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5957 | void releasePendingPointerLocked(Session s) { |
| 5958 | if (DEBUG_INPUT) Log.v(TAG, |
| 5959 | "releasePendingPointer " + s.mPendingPointerMove); |
| 5960 | if (s.mPendingPointerMove != null) { |
| 5961 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 5962 | s.mPendingPointerMove = null; |
| 5963 | } |
| 5964 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5965 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5966 | void releasePendingTrackballLocked(Session s) { |
| 5967 | if (s.mPendingTrackballMove != null) { |
| 5968 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 5969 | s.mPendingTrackballMove = null; |
| 5970 | } |
| 5971 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5973 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 5974 | int returnWhat) { |
| 5975 | if (DEBUG_INPUT) Log.v( |
| 5976 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 5977 | |
| 5978 | if (client == null) { |
| 5979 | return null; |
| 5980 | } |
| 5981 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5982 | MotionEvent res = null; |
| 5983 | QueuedEvent qev = null; |
| 5984 | WindowState win = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5985 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5986 | synchronized (this) { |
| 5987 | if (DEBUG_INPUT) Log.v( |
| 5988 | TAG, "finishedKey: client=" + client.asBinder() |
| 5989 | + ", force=" + force + ", last=" + mLastBinder |
| 5990 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 5991 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 5993 | qev = session.mPendingPointerMove; |
| 5994 | win = session.mPendingPointerWindow; |
| 5995 | session.mPendingPointerMove = null; |
| 5996 | session.mPendingPointerWindow = null; |
| 5997 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 5998 | qev = session.mPendingTrackballMove; |
| 5999 | win = session.mPendingTrackballWindow; |
| 6000 | session.mPendingTrackballMove = null; |
| 6001 | session.mPendingTrackballWindow = null; |
| 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 | if (mLastBinder == client.asBinder()) { |
| 6005 | if (DEBUG_INPUT) Log.v( |
| 6006 | TAG, "finishedKey: last paused=" |
| 6007 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 6008 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 6009 | || !mEventDispatching)) { |
| 6010 | doFinishedKeyLocked(false); |
| 6011 | } else { |
| 6012 | // Make sure to wake up anyone currently waiting to |
| 6013 | // dispatch a key, so they can re-evaluate their |
| 6014 | // current situation. |
| 6015 | mFinished = true; |
| 6016 | notifyAll(); |
| 6017 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6018 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6020 | if (qev != null) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6021 | res = (MotionEvent)qev.event; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6022 | if (DEBUG_INPUT) Log.v(TAG, |
| 6023 | "Returning pending motion: " + res); |
| 6024 | mQueue.recycleEvent(qev); |
| 6025 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6026 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 6027 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | } |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6029 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6030 | |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6031 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6032 | synchronized (mWindowMap) { |
| 6033 | if ((mWallpaperTarget == win && |
| 6034 | win.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) |
| 6035 | || mSendingPointersToWallpaper) { |
| 6036 | sendPointerToWallpaperLocked(win, res, res.getEventTime()); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6037 | } |
| 6038 | } |
| 6039 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6040 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6041 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | void tickle() { |
| 6045 | synchronized (this) { |
| 6046 | notifyAll(); |
| 6047 | } |
| 6048 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6049 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6050 | void handleNewWindowLocked(WindowState newWindow) { |
| 6051 | if (!newWindow.canReceiveKeys()) { |
| 6052 | return; |
| 6053 | } |
| 6054 | synchronized (this) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6055 | if (DEBUG_INPUT) Log.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6056 | TAG, "New key dispatch window: win=" |
| 6057 | + newWindow.mClient.asBinder() |
| 6058 | + ", last=" + mLastBinder |
| 6059 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6060 | + "), finished=" + mFinished + ", paused=" |
| 6061 | + newWindow.mToken.paused); |
| 6062 | |
| 6063 | // Displaying a window implicitly causes dispatching to |
| 6064 | // be unpaused. (This is to protect against bugs if someone |
| 6065 | // pauses dispatching but forgets to resume.) |
| 6066 | newWindow.mToken.paused = false; |
| 6067 | |
| 6068 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6069 | |
| 6070 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 6071 | if (DEBUG_INPUT) Log.v(TAG, |
| 6072 | "New SYSTEM_ERROR window; resetting state"); |
| 6073 | mLastWin = null; |
| 6074 | mLastBinder = null; |
| 6075 | mMotionTarget = null; |
| 6076 | mFinished = true; |
| 6077 | } else if (mLastWin != null) { |
| 6078 | // If the new window is above the window we are |
| 6079 | // waiting on, then stop waiting and let key dispatching |
| 6080 | // start on the new guy. |
| 6081 | if (DEBUG_INPUT) Log.v( |
| 6082 | TAG, "Last win layer=" + mLastWin.mLayer |
| 6083 | + ", new win layer=" + newWindow.mLayer); |
| 6084 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6085 | // The new window is above the old; finish pending input to the last |
| 6086 | // window and start directing it to the new one. |
| 6087 | mLastWin.mToken.paused = false; |
| 6088 | doFinishedKeyLocked(true); // does a notifyAll() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6089 | } |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6090 | // Either the new window is lower, so there is no need to wake key waiters, |
| 6091 | // or we just finished key input to the previous window, which implicitly |
| 6092 | // notified the key waiters. In both cases, we don't need to issue the |
| 6093 | // notification here. |
| 6094 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6095 | } |
| 6096 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6097 | // Now that we've put a new window state in place, make the event waiter |
| 6098 | // take notice and retarget its attentions. |
| 6099 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | } |
| 6101 | } |
| 6102 | |
| 6103 | void pauseDispatchingLocked(WindowToken token) { |
| 6104 | synchronized (this) |
| 6105 | { |
| 6106 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 6107 | token.paused = true; |
| 6108 | |
| 6109 | /* |
| 6110 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 6111 | mPaused = true; |
| 6112 | } else { |
| 6113 | if (mLastWin == null) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6114 | Log.i(TAG, "Key dispatching not paused: no last window."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6115 | } else if (mFinished) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6116 | Log.i(TAG, "Key dispatching not paused: finished last key."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6117 | } else { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6118 | Log.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] | 6119 | } |
| 6120 | } |
| 6121 | */ |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | void resumeDispatchingLocked(WindowToken token) { |
| 6126 | synchronized (this) { |
| 6127 | if (token.paused) { |
| 6128 | if (DEBUG_INPUT) Log.v( |
| 6129 | TAG, "Resuming WindowToken " + token |
| 6130 | + ", last=" + mLastBinder |
| 6131 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6132 | + "), finished=" + mFinished + ", paused=" |
| 6133 | + token.paused); |
| 6134 | token.paused = false; |
| 6135 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 6136 | doFinishedKeyLocked(true); |
| 6137 | } else { |
| 6138 | notifyAll(); |
| 6139 | } |
| 6140 | } |
| 6141 | } |
| 6142 | } |
| 6143 | |
| 6144 | void setEventDispatchingLocked(boolean enabled) { |
| 6145 | synchronized (this) { |
| 6146 | mEventDispatching = enabled; |
| 6147 | notifyAll(); |
| 6148 | } |
| 6149 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6150 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6151 | void appSwitchComing() { |
| 6152 | synchronized (this) { |
| 6153 | // Don't wait for more than .5 seconds for app to finish |
| 6154 | // processing the pending events. |
| 6155 | long now = SystemClock.uptimeMillis() + 500; |
| 6156 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 6157 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 6158 | mTimeToSwitch = now; |
| 6159 | } |
| 6160 | notifyAll(); |
| 6161 | } |
| 6162 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 6165 | if (mLastWin != null) { |
| 6166 | releasePendingPointerLocked(mLastWin.mSession); |
| 6167 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6168 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6169 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | if (mLastWin == null || !mLastWin.mToken.paused |
| 6171 | || !mLastWin.isVisibleLw()) { |
| 6172 | // If the current window has been paused, we aren't -really- |
| 6173 | // finished... so let the waiters still wait. |
| 6174 | mLastWin = null; |
| 6175 | mLastBinder = null; |
| 6176 | } |
| 6177 | mFinished = true; |
| 6178 | notifyAll(); |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | private class KeyQ extends KeyInputQueue |
| 6183 | implements KeyInputQueue.FilterCallback { |
| 6184 | PowerManager.WakeLock mHoldingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | KeyQ() { |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6187 | super(mContext, WindowManagerService.this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 6189 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 6190 | "KEEP_SCREEN_ON_FLAG"); |
| 6191 | mHoldingScreen.setReferenceCounted(false); |
| 6192 | } |
| 6193 | |
| 6194 | @Override |
| 6195 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6196 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6197 | return true; |
| 6198 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6199 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6200 | switch (event.type) { |
| 6201 | case RawInputEvent.EV_KEY: { |
| 6202 | // XXX begin hack |
| 6203 | if (DEBUG) { |
| 6204 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6205 | if (event.value != 0) { |
| 6206 | // G down |
| 6207 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6208 | } |
| 6209 | return false; |
| 6210 | } |
| 6211 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6212 | if (event.value != 0) { |
| 6213 | //dump(); |
| 6214 | } |
| 6215 | return false; |
| 6216 | } |
| 6217 | } |
| 6218 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6219 | |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6220 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6221 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6225 | mPowerManager.goToSleep(event.when); |
| 6226 | } |
| 6227 | |
| 6228 | if (screenIsOff) { |
| 6229 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6230 | } |
| 6231 | if (screenIsDim) { |
| 6232 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6233 | } |
| 6234 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6235 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6236 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6237 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6239 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6240 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6241 | filterQueue(this); |
| 6242 | mKeyWaiter.appSwitchComing(); |
| 6243 | } |
| 6244 | return true; |
| 6245 | } else { |
| 6246 | return false; |
| 6247 | } |
| 6248 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6249 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6250 | case RawInputEvent.EV_REL: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6251 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6252 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6253 | if (screenIsOff) { |
| 6254 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6255 | device.classes, event)) { |
| 6256 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6257 | return false; |
| 6258 | } |
| 6259 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6260 | } |
| 6261 | if (screenIsDim) { |
| 6262 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6263 | } |
| 6264 | return true; |
| 6265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | case RawInputEvent.EV_ABS: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6268 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6269 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6270 | if (screenIsOff) { |
| 6271 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6272 | device.classes, event)) { |
| 6273 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6274 | return false; |
| 6275 | } |
| 6276 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6277 | } |
| 6278 | if (screenIsDim) { |
| 6279 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6280 | } |
| 6281 | return true; |
| 6282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6284 | default: |
| 6285 | return true; |
| 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | public int filterEvent(QueuedEvent ev) { |
| 6290 | switch (ev.classType) { |
| 6291 | case RawInputEvent.CLASS_KEYBOARD: |
| 6292 | KeyEvent ke = (KeyEvent)ev.event; |
| 6293 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 6294 | Log.w(TAG, "Dropping movement key during app switch: " |
| 6295 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6296 | return FILTER_REMOVE; |
| 6297 | } |
| 6298 | return FILTER_ABORT; |
| 6299 | default: |
| 6300 | return FILTER_KEEP; |
| 6301 | } |
| 6302 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | /** |
| 6305 | * Must be called with the main window manager lock held. |
| 6306 | */ |
| 6307 | void setHoldScreenLocked(boolean holding) { |
| 6308 | boolean state = mHoldingScreen.isHeld(); |
| 6309 | if (holding != state) { |
| 6310 | if (holding) { |
| 6311 | mHoldingScreen.acquire(); |
| 6312 | } else { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6313 | mPolicy.screenOnStoppedLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6314 | mHoldingScreen.release(); |
| 6315 | } |
| 6316 | } |
| 6317 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6318 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6319 | |
| 6320 | public boolean detectSafeMode() { |
| 6321 | mSafeMode = mPolicy.detectSafeMode(); |
| 6322 | return mSafeMode; |
| 6323 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6325 | public void systemReady() { |
| 6326 | mPolicy.systemReady(); |
| 6327 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | private final class InputDispatcherThread extends Thread { |
| 6330 | // Time to wait when there is nothing to do: 9999 seconds. |
| 6331 | static final int LONG_WAIT=9999*1000; |
| 6332 | |
| 6333 | public InputDispatcherThread() { |
| 6334 | super("InputDispatcher"); |
| 6335 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6336 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6337 | @Override |
| 6338 | public void run() { |
| 6339 | while (true) { |
| 6340 | try { |
| 6341 | process(); |
| 6342 | } catch (Exception e) { |
| 6343 | Log.e(TAG, "Exception in input dispatcher", e); |
| 6344 | } |
| 6345 | } |
| 6346 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6347 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6348 | private void process() { |
| 6349 | android.os.Process.setThreadPriority( |
| 6350 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6351 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6352 | // The last key event we saw |
| 6353 | KeyEvent lastKey = null; |
| 6354 | |
| 6355 | // Last keydown time for auto-repeating keys |
| 6356 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 6357 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6358 | long downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6360 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | int keyRepeatCount = 0; |
| 6362 | |
| 6363 | // Need to report that configuration has changed? |
| 6364 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6365 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6366 | while (true) { |
| 6367 | long curTime = SystemClock.uptimeMillis(); |
| 6368 | |
| 6369 | if (DEBUG_INPUT) Log.v( |
| 6370 | TAG, "Waiting for next key: now=" + curTime |
| 6371 | + ", repeat @ " + nextKeyTime); |
| 6372 | |
| 6373 | // Retrieve next event, waiting only as long as the next |
| 6374 | // repeat timeout. If the configuration has changed, then |
| 6375 | // don't wait at all -- we'll report the change as soon as |
| 6376 | // we have processed all events. |
| 6377 | QueuedEvent ev = mQueue.getEvent( |
| 6378 | (int)((!configChanged && curTime < nextKeyTime) |
| 6379 | ? (nextKeyTime-curTime) : 0)); |
| 6380 | |
| 6381 | if (DEBUG_INPUT && ev != null) Log.v( |
| 6382 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 6383 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6384 | if (MEASURE_LATENCY) { |
| 6385 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 6386 | } |
| 6387 | |
| Mike Lockwood | 3d0ea72 | 2009-10-21 22:58:29 -0400 | [diff] [blame] | 6388 | if (lastKey != null && !mPolicy.allowKeyRepeat()) { |
| 6389 | // cancel key repeat at the request of the policy. |
| 6390 | lastKey = null; |
| 6391 | downTime = 0; |
| 6392 | lastKeyTime = curTime; |
| 6393 | nextKeyTime = curTime + LONG_WAIT; |
| 6394 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6395 | try { |
| 6396 | if (ev != null) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6397 | curTime = SystemClock.uptimeMillis(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | int eventType; |
| 6399 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 6400 | eventType = eventType((MotionEvent)ev.event); |
| 6401 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 6402 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 6403 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 6404 | } else { |
| 6405 | eventType = LocalPowerManager.OTHER_EVENT; |
| 6406 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6407 | try { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6408 | if ((curTime - mLastBatteryStatsCallTime) |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6409 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6410 | mLastBatteryStatsCallTime = curTime; |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6411 | mBatteryStats.noteInputEvent(); |
| 6412 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6413 | } catch (RemoteException e) { |
| 6414 | // Ignore |
| 6415 | } |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6416 | |
| Mike Lockwood | 5db4240 | 2009-11-30 14:51:51 -0500 | [diff] [blame] | 6417 | if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) { |
| 6418 | // do not wake screen in this case |
| 6419 | } else if (eventType != TOUCH_EVENT |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6420 | && eventType != LONG_TOUCH_EVENT |
| 6421 | && eventType != CHEEK_EVENT) { |
| 6422 | mPowerManager.userActivity(curTime, false, |
| 6423 | eventType, false); |
| 6424 | } else if (mLastTouchEventType != eventType |
| 6425 | || (curTime - mLastUserActivityCallTime) |
| 6426 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 6427 | mLastUserActivityCallTime = curTime; |
| 6428 | mLastTouchEventType = eventType; |
| 6429 | mPowerManager.userActivity(curTime, false, |
| 6430 | eventType, false); |
| 6431 | } |
| 6432 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6433 | switch (ev.classType) { |
| 6434 | case RawInputEvent.CLASS_KEYBOARD: |
| 6435 | KeyEvent ke = (KeyEvent)ev.event; |
| 6436 | if (ke.isDown()) { |
| 6437 | lastKey = ke; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6438 | downTime = curTime; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6439 | keyRepeatCount = 0; |
| 6440 | lastKeyTime = curTime; |
| 6441 | nextKeyTime = lastKeyTime |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6442 | + ViewConfiguration.getLongPressTimeout(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6443 | if (DEBUG_INPUT) Log.v( |
| 6444 | TAG, "Received key down: first repeat @ " |
| 6445 | + nextKeyTime); |
| 6446 | } else { |
| 6447 | lastKey = null; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6448 | downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6449 | // Arbitrary long timeout. |
| 6450 | lastKeyTime = curTime; |
| 6451 | nextKeyTime = curTime + LONG_WAIT; |
| 6452 | if (DEBUG_INPUT) Log.v( |
| 6453 | TAG, "Received key up: ignore repeat @ " |
| 6454 | + nextKeyTime); |
| 6455 | } |
| 6456 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 6457 | mQueue.recycleEvent(ev); |
| 6458 | break; |
| 6459 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 6460 | //Log.i(TAG, "Read next event " + ev); |
| 6461 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 6462 | break; |
| 6463 | case RawInputEvent.CLASS_TRACKBALL: |
| 6464 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 6465 | break; |
| 6466 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 6467 | configChanged = true; |
| 6468 | break; |
| 6469 | default: |
| 6470 | mQueue.recycleEvent(ev); |
| 6471 | break; |
| 6472 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6474 | } else if (configChanged) { |
| 6475 | configChanged = false; |
| 6476 | sendNewConfiguration(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6477 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6478 | } else if (lastKey != null) { |
| 6479 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6480 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | // Timeout occurred while key was down. If it is at or |
| 6482 | // past the key repeat time, dispatch the repeat. |
| 6483 | if (DEBUG_INPUT) Log.v( |
| 6484 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 6485 | + ", now=" + curTime); |
| 6486 | if (curTime < nextKeyTime) { |
| 6487 | continue; |
| 6488 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6490 | lastKeyTime = nextKeyTime; |
| 6491 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 6492 | keyRepeatCount++; |
| 6493 | if (DEBUG_INPUT) Log.v( |
| 6494 | TAG, "Key repeat: count=" + keyRepeatCount |
| 6495 | + ", next @ " + nextKeyTime); |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6496 | KeyEvent newEvent; |
| 6497 | if (downTime != 0 && (downTime |
| 6498 | + ViewConfiguration.getLongPressTimeout()) |
| 6499 | <= curTime) { |
| 6500 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6501 | curTime, keyRepeatCount, |
| 6502 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6503 | downTime = 0; |
| 6504 | } else { |
| 6505 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6506 | curTime, keyRepeatCount); |
| 6507 | } |
| 6508 | dispatchKey(newEvent, 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | } else { |
| 6511 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6512 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6513 | lastKeyTime = curTime; |
| 6514 | nextKeyTime = curTime + LONG_WAIT; |
| 6515 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6516 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6517 | } catch (Exception e) { |
| 6518 | Log.e(TAG, |
| 6519 | "Input thread received uncaught exception: " + e, e); |
| 6520 | } |
| 6521 | } |
| 6522 | } |
| 6523 | } |
| 6524 | |
| 6525 | // ------------------------------------------------------------- |
| 6526 | // Client Session State |
| 6527 | // ------------------------------------------------------------- |
| 6528 | |
| 6529 | private final class Session extends IWindowSession.Stub |
| 6530 | implements IBinder.DeathRecipient { |
| 6531 | final IInputMethodClient mClient; |
| 6532 | final IInputContext mInputContext; |
| 6533 | final int mUid; |
| 6534 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6535 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6536 | SurfaceSession mSurfaceSession; |
| 6537 | int mNumWindow = 0; |
| 6538 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6539 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6540 | /** |
| 6541 | * Current pointer move event being dispatched to client window... must |
| 6542 | * hold key lock to access. |
| 6543 | */ |
| 6544 | QueuedEvent mPendingPointerMove; |
| 6545 | WindowState mPendingPointerWindow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6547 | /** |
| 6548 | * Current trackball move event being dispatched to client window... must |
| 6549 | * hold key lock to access. |
| 6550 | */ |
| 6551 | QueuedEvent mPendingTrackballMove; |
| 6552 | WindowState mPendingTrackballWindow; |
| 6553 | |
| 6554 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6555 | mClient = client; |
| 6556 | mInputContext = inputContext; |
| 6557 | mUid = Binder.getCallingUid(); |
| 6558 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6559 | StringBuilder sb = new StringBuilder(); |
| 6560 | sb.append("Session{"); |
| 6561 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6562 | sb.append(" uid "); |
| 6563 | sb.append(mUid); |
| 6564 | sb.append("}"); |
| 6565 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6566 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6567 | synchronized (mWindowMap) { |
| 6568 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6569 | IBinder b = ServiceManager.getService( |
| 6570 | Context.INPUT_METHOD_SERVICE); |
| 6571 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6572 | } |
| 6573 | } |
| 6574 | long ident = Binder.clearCallingIdentity(); |
| 6575 | try { |
| 6576 | // Note: it is safe to call in to the input method manager |
| 6577 | // here because we are not holding our lock. |
| 6578 | if (mInputMethodManager != null) { |
| 6579 | mInputMethodManager.addClient(client, inputContext, |
| 6580 | mUid, mPid); |
| 6581 | } else { |
| 6582 | client.setUsingInputMethod(false); |
| 6583 | } |
| 6584 | client.asBinder().linkToDeath(this, 0); |
| 6585 | } catch (RemoteException e) { |
| 6586 | // The caller has died, so we can just forget about this. |
| 6587 | try { |
| 6588 | if (mInputMethodManager != null) { |
| 6589 | mInputMethodManager.removeClient(client); |
| 6590 | } |
| 6591 | } catch (RemoteException ee) { |
| 6592 | } |
| 6593 | } finally { |
| 6594 | Binder.restoreCallingIdentity(ident); |
| 6595 | } |
| 6596 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6598 | @Override |
| 6599 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6600 | throws RemoteException { |
| 6601 | try { |
| 6602 | return super.onTransact(code, data, reply, flags); |
| 6603 | } catch (RuntimeException e) { |
| 6604 | // Log all 'real' exceptions thrown to the caller |
| 6605 | if (!(e instanceof SecurityException)) { |
| 6606 | Log.e(TAG, "Window Session Crash", e); |
| 6607 | } |
| 6608 | throw e; |
| 6609 | } |
| 6610 | } |
| 6611 | |
| 6612 | public void binderDied() { |
| 6613 | // Note: it is safe to call in to the input method manager |
| 6614 | // here because we are not holding our lock. |
| 6615 | try { |
| 6616 | if (mInputMethodManager != null) { |
| 6617 | mInputMethodManager.removeClient(mClient); |
| 6618 | } |
| 6619 | } catch (RemoteException e) { |
| 6620 | } |
| 6621 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6622 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6623 | mClientDead = true; |
| 6624 | killSessionLocked(); |
| 6625 | } |
| 6626 | } |
| 6627 | |
| 6628 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6629 | int viewVisibility, Rect outContentInsets) { |
| 6630 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6631 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | public void remove(IWindow window) { |
| 6634 | removeWindow(this, window); |
| 6635 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6637 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6638 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6639 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 6640 | Rect outVisibleInsets, Surface outSurface) { |
| 6641 | return relayoutWindow(this, window, attrs, |
| 6642 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 6643 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 6644 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6646 | public void setTransparentRegion(IWindow window, Region region) { |
| 6647 | setTransparentRegionWindow(this, window, region); |
| 6648 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6649 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6650 | public void setInsets(IWindow window, int touchableInsets, |
| 6651 | Rect contentInsets, Rect visibleInsets) { |
| 6652 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6653 | visibleInsets); |
| 6654 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6655 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6656 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6657 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6658 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6660 | public void finishDrawing(IWindow window) { |
| 6661 | if (localLOGV) Log.v( |
| 6662 | TAG, "IWindow finishDrawing called for " + window); |
| 6663 | finishDrawingWindow(this, window); |
| 6664 | } |
| 6665 | |
| 6666 | public void finishKey(IWindow window) { |
| 6667 | if (localLOGV) Log.v( |
| 6668 | TAG, "IWindow finishKey called for " + window); |
| 6669 | mKeyWaiter.finishedKey(this, window, false, |
| 6670 | KeyWaiter.RETURN_NOTHING); |
| 6671 | } |
| 6672 | |
| 6673 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 6674 | if (localLOGV) Log.v( |
| 6675 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6676 | return mKeyWaiter.finishedKey(this, window, false, |
| 6677 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6678 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6680 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 6681 | if (localLOGV) Log.v( |
| 6682 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6683 | return mKeyWaiter.finishedKey(this, window, false, |
| 6684 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6685 | } |
| 6686 | |
| 6687 | public void setInTouchMode(boolean mode) { |
| 6688 | synchronized(mWindowMap) { |
| 6689 | mInTouchMode = mode; |
| 6690 | } |
| 6691 | } |
| 6692 | |
| 6693 | public boolean getInTouchMode() { |
| 6694 | synchronized(mWindowMap) { |
| 6695 | return mInTouchMode; |
| 6696 | } |
| 6697 | } |
| 6698 | |
| 6699 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6700 | boolean always) { |
| 6701 | synchronized(mWindowMap) { |
| 6702 | long ident = Binder.clearCallingIdentity(); |
| 6703 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6704 | return mPolicy.performHapticFeedbackLw( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6705 | windowForClientLocked(this, window), effectId, always); |
| 6706 | } finally { |
| 6707 | Binder.restoreCallingIdentity(ident); |
| 6708 | } |
| 6709 | } |
| 6710 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6711 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6712 | 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] | 6713 | synchronized(mWindowMap) { |
| 6714 | long ident = Binder.clearCallingIdentity(); |
| 6715 | try { |
| 6716 | setWindowWallpaperPositionLocked(windowForClientLocked(this, window), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6717 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(ident); |
| 6720 | } |
| 6721 | } |
| 6722 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6723 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6724 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6725 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6726 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6727 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6728 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6729 | int z, Bundle extras, boolean sync) { |
| 6730 | synchronized(mWindowMap) { |
| 6731 | long ident = Binder.clearCallingIdentity(); |
| 6732 | try { |
| 6733 | return sendWindowWallpaperCommandLocked( |
| 6734 | windowForClientLocked(this, window), |
| 6735 | action, x, y, z, extras, sync); |
| 6736 | } finally { |
| 6737 | Binder.restoreCallingIdentity(ident); |
| 6738 | } |
| 6739 | } |
| 6740 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6741 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6742 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6743 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6744 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6745 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6746 | void windowAddedLocked() { |
| 6747 | if (mSurfaceSession == null) { |
| 6748 | if (localLOGV) Log.v( |
| 6749 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6750 | mSurfaceSession = new SurfaceSession(); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6751 | if (SHOW_TRANSACTIONS) Log.i( |
| 6752 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6753 | mSessions.add(this); |
| 6754 | } |
| 6755 | mNumWindow++; |
| 6756 | } |
| 6757 | |
| 6758 | void windowRemovedLocked() { |
| 6759 | mNumWindow--; |
| 6760 | killSessionLocked(); |
| 6761 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6763 | void killSessionLocked() { |
| 6764 | if (mNumWindow <= 0 && mClientDead) { |
| 6765 | mSessions.remove(this); |
| 6766 | if (mSurfaceSession != null) { |
| 6767 | if (localLOGV) Log.v( |
| 6768 | TAG, "Last window removed from " + this |
| 6769 | + ", destroying " + mSurfaceSession); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6770 | if (SHOW_TRANSACTIONS) Log.i( |
| 6771 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | try { |
| 6773 | mSurfaceSession.kill(); |
| 6774 | } catch (Exception e) { |
| 6775 | Log.w(TAG, "Exception thrown when killing surface session " |
| 6776 | + mSurfaceSession + " in session " + this |
| 6777 | + ": " + e.toString()); |
| 6778 | } |
| 6779 | mSurfaceSession = null; |
| 6780 | } |
| 6781 | } |
| 6782 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6785 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6786 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6787 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6788 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6789 | pw.print(prefix); |
| 6790 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6791 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6792 | } |
| 6793 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6794 | pw.print(prefix); |
| 6795 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6796 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6797 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6798 | } |
| 6799 | |
| 6800 | @Override |
| 6801 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6802 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | // ------------------------------------------------------------- |
| 6807 | // Client Window State |
| 6808 | // ------------------------------------------------------------- |
| 6809 | |
| 6810 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6811 | final Session mSession; |
| 6812 | final IWindow mClient; |
| 6813 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6814 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6815 | AppWindowToken mAppToken; |
| 6816 | AppWindowToken mTargetAppToken; |
| 6817 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6818 | final DeathRecipient mDeathRecipient; |
| 6819 | final WindowState mAttachedWindow; |
| 6820 | final ArrayList mChildWindows = new ArrayList(); |
| 6821 | final int mBaseLayer; |
| 6822 | final int mSubLayer; |
| 6823 | final boolean mLayoutAttached; |
| 6824 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6825 | final boolean mIsWallpaper; |
| 6826 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | int mViewVisibility; |
| 6828 | boolean mPolicyVisibility = true; |
| 6829 | boolean mPolicyVisibilityAfterAnim = true; |
| 6830 | boolean mAppFreezing; |
| 6831 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6832 | boolean mReportDestroySurface; |
| 6833 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6834 | boolean mAttachedHidden; // is our parent window hidden? |
| 6835 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6836 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6837 | int mRequestedWidth; |
| 6838 | int mRequestedHeight; |
| 6839 | int mLastRequestedWidth; |
| 6840 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6841 | int mLayer; |
| 6842 | int mAnimLayer; |
| 6843 | int mLastLayer; |
| 6844 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6845 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6846 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6847 | |
| 6848 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | // Actual frame shown on-screen (may be modified by animation) |
| 6851 | final Rect mShownFrame = new Rect(); |
| 6852 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6854 | /** |
| 6855 | * Insets that determine the actually visible area |
| 6856 | */ |
| 6857 | final Rect mVisibleInsets = new Rect(); |
| 6858 | final Rect mLastVisibleInsets = new Rect(); |
| 6859 | boolean mVisibleInsetsChanged; |
| 6860 | |
| 6861 | /** |
| 6862 | * Insets that are covered by system windows |
| 6863 | */ |
| 6864 | final Rect mContentInsets = new Rect(); |
| 6865 | final Rect mLastContentInsets = new Rect(); |
| 6866 | boolean mContentInsetsChanged; |
| 6867 | |
| 6868 | /** |
| 6869 | * Set to true if we are waiting for this window to receive its |
| 6870 | * given internal insets before laying out other windows based on it. |
| 6871 | */ |
| 6872 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6874 | /** |
| 6875 | * These are the content insets that were given during layout for |
| 6876 | * this window, to be applied to windows behind it. |
| 6877 | */ |
| 6878 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6879 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | /** |
| 6881 | * These are the visible insets that were given during layout for |
| 6882 | * this window, to be applied to windows behind it. |
| 6883 | */ |
| 6884 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6886 | /** |
| 6887 | * Flag indicating whether the touchable region should be adjusted by |
| 6888 | * the visible insets; if false the area outside the visible insets is |
| 6889 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6890 | * tests. |
| 6891 | */ |
| 6892 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6893 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6894 | // Current transformation being applied. |
| 6895 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6896 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6897 | float mHScale=1, mVScale=1; |
| 6898 | float mLastHScale=1, mLastVScale=1; |
| 6899 | final Matrix mTmpMatrix = new Matrix(); |
| 6900 | |
| 6901 | // "Real" frame that the application sees. |
| 6902 | final Rect mFrame = new Rect(); |
| 6903 | final Rect mLastFrame = new Rect(); |
| 6904 | |
| 6905 | final Rect mContainingFrame = new Rect(); |
| 6906 | final Rect mDisplayFrame = new Rect(); |
| 6907 | final Rect mContentFrame = new Rect(); |
| 6908 | final Rect mVisibleFrame = new Rect(); |
| 6909 | |
| 6910 | float mShownAlpha = 1; |
| 6911 | float mAlpha = 1; |
| 6912 | float mLastAlpha = 1; |
| 6913 | |
| 6914 | // Set to true if, when the window gets displayed, it should perform |
| 6915 | // an enter animation. |
| 6916 | boolean mEnterAnimationPending; |
| 6917 | |
| 6918 | // Currently running animation. |
| 6919 | boolean mAnimating; |
| 6920 | boolean mLocalAnimating; |
| 6921 | Animation mAnimation; |
| 6922 | boolean mAnimationIsEntrance; |
| 6923 | boolean mHasTransformation; |
| 6924 | boolean mHasLocalTransformation; |
| 6925 | final Transformation mTransformation = new Transformation(); |
| 6926 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6927 | // If a window showing a wallpaper: the requested offset for the |
| 6928 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6929 | float mWallpaperX = -1; |
| 6930 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6931 | |
| 6932 | // If a window showing a wallpaper: what fraction of the offset |
| 6933 | // range corresponds to a full virtual screen. |
| 6934 | float mWallpaperXStep = -1; |
| 6935 | float mWallpaperYStep = -1; |
| 6936 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6937 | // Wallpaper windows: pixels offset based on above variables. |
| 6938 | int mXOffset; |
| 6939 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6940 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | // This is set after IWindowSession.relayout() has been called at |
| 6942 | // least once for the window. It allows us to detect the situation |
| 6943 | // where we don't yet have a surface, but should have one soon, so |
| 6944 | // we can give the window focus before waiting for the relayout. |
| 6945 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | // This is set after the Surface has been created but before the |
| 6948 | // window has been drawn. During this time the surface is hidden. |
| 6949 | boolean mDrawPending; |
| 6950 | |
| 6951 | // This is set after the window has finished drawing for the first |
| 6952 | // time but before its surface is shown. The surface will be |
| 6953 | // displayed when the next layout is run. |
| 6954 | boolean mCommitDrawPending; |
| 6955 | |
| 6956 | // This is set during the time after the window's drawing has been |
| 6957 | // committed, and before its surface is actually shown. It is used |
| 6958 | // to delay showing the surface until all windows in a token are ready |
| 6959 | // to be shown. |
| 6960 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6961 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | // Set when the window has been shown in the screen the first time. |
| 6963 | boolean mHasDrawn; |
| 6964 | |
| 6965 | // Currently running an exit animation? |
| 6966 | boolean mExiting; |
| 6967 | |
| 6968 | // Currently on the mDestroySurface list? |
| 6969 | boolean mDestroying; |
| 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 | // Completely remove from window manager after exit animation? |
| 6972 | boolean mRemoveOnExit; |
| 6973 | |
| 6974 | // Set when the orientation is changing and this window has not yet |
| 6975 | // been updated for the new orientation. |
| 6976 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | // Is this window now (or just being) removed? |
| 6979 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6980 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6981 | WindowState(Session s, IWindow c, WindowToken token, |
| 6982 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6983 | int viewVisibility) { |
| 6984 | mSession = s; |
| 6985 | mClient = c; |
| 6986 | mToken = token; |
| 6987 | mAttrs.copyFrom(a); |
| 6988 | mViewVisibility = viewVisibility; |
| 6989 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6990 | mAlpha = a.alpha; |
| 6991 | if (localLOGV) Log.v( |
| 6992 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6993 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6994 | try { |
| 6995 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6996 | } catch (RemoteException e) { |
| 6997 | mDeathRecipient = null; |
| 6998 | mAttachedWindow = null; |
| 6999 | mLayoutAttached = false; |
| 7000 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7001 | mIsWallpaper = false; |
| 7002 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7003 | mBaseLayer = 0; |
| 7004 | mSubLayer = 0; |
| 7005 | return; |
| 7006 | } |
| 7007 | mDeathRecipient = deathRecipient; |
| 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 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7010 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7011 | // The multiplier here is to reserve space for multiple |
| 7012 | // windows in the same type layer. |
| 7013 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7014 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7015 | + TYPE_LAYER_OFFSET; |
| 7016 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7017 | mAttachedWindow = attachedWindow; |
| 7018 | mAttachedWindow.mChildWindows.add(this); |
| 7019 | mLayoutAttached = mAttrs.type != |
| 7020 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7021 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7022 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7023 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7024 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7025 | } else { |
| 7026 | // The multiplier here is to reserve space for multiple |
| 7027 | // windows in the same type layer. |
| 7028 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7029 | * TYPE_LAYER_MULTIPLIER |
| 7030 | + TYPE_LAYER_OFFSET; |
| 7031 | mSubLayer = 0; |
| 7032 | mAttachedWindow = null; |
| 7033 | mLayoutAttached = false; |
| 7034 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7035 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7036 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7037 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7038 | } |
| 7039 | |
| 7040 | WindowState appWin = this; |
| 7041 | while (appWin.mAttachedWindow != null) { |
| 7042 | appWin = mAttachedWindow; |
| 7043 | } |
| 7044 | WindowToken appToken = appWin.mToken; |
| 7045 | while (appToken.appWindowToken == null) { |
| 7046 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7047 | if (parent == null || appToken == parent) { |
| 7048 | break; |
| 7049 | } |
| 7050 | appToken = parent; |
| 7051 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7052 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7053 | mAppToken = appToken.appWindowToken; |
| 7054 | |
| 7055 | mSurface = null; |
| 7056 | mRequestedWidth = 0; |
| 7057 | mRequestedHeight = 0; |
| 7058 | mLastRequestedWidth = 0; |
| 7059 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7060 | mXOffset = 0; |
| 7061 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7062 | mLayer = 0; |
| 7063 | mAnimLayer = 0; |
| 7064 | mLastLayer = 0; |
| 7065 | } |
| 7066 | |
| 7067 | void attach() { |
| 7068 | if (localLOGV) Log.v( |
| 7069 | TAG, "Attaching " + this + " token=" + mToken |
| 7070 | + ", list=" + mToken.windows); |
| 7071 | mSession.windowAddedLocked(); |
| 7072 | } |
| 7073 | |
| 7074 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7075 | mHaveFrame = true; |
| 7076 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7077 | final Rect container = mContainingFrame; |
| 7078 | container.set(pf); |
| 7079 | |
| 7080 | final Rect display = mDisplayFrame; |
| 7081 | display.set(df); |
| 7082 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7083 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7084 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7085 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7086 | display.intersect(mCompatibleScreenFrame); |
| 7087 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7088 | } |
| 7089 | |
| 7090 | final int pw = container.right - container.left; |
| 7091 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7092 | |
| 7093 | int w,h; |
| 7094 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7095 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7096 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7097 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7098 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7099 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7100 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7102 | final Rect content = mContentFrame; |
| 7103 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7104 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7105 | final Rect visible = mVisibleFrame; |
| 7106 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7107 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7108 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7109 | final int fw = frame.width(); |
| 7110 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7112 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7113 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7114 | |
| 7115 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7116 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7117 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7118 | |
| 7119 | //System.out.println("Out: " + mFrame); |
| 7120 | |
| 7121 | // Now make sure the window fits in the overall display. |
| 7122 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7124 | // Make sure the content and visible frames are inside of the |
| 7125 | // final window frame. |
| 7126 | if (content.left < frame.left) content.left = frame.left; |
| 7127 | if (content.top < frame.top) content.top = frame.top; |
| 7128 | if (content.right > frame.right) content.right = frame.right; |
| 7129 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7130 | if (visible.left < frame.left) visible.left = frame.left; |
| 7131 | if (visible.top < frame.top) visible.top = frame.top; |
| 7132 | if (visible.right > frame.right) visible.right = frame.right; |
| 7133 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7134 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7135 | final Rect contentInsets = mContentInsets; |
| 7136 | contentInsets.left = content.left-frame.left; |
| 7137 | contentInsets.top = content.top-frame.top; |
| 7138 | contentInsets.right = frame.right-content.right; |
| 7139 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7140 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7141 | final Rect visibleInsets = mVisibleInsets; |
| 7142 | visibleInsets.left = visible.left-frame.left; |
| 7143 | visibleInsets.top = visible.top-frame.top; |
| 7144 | visibleInsets.right = frame.right-visible.right; |
| 7145 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7146 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7147 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7148 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7149 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7150 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7151 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7152 | if (localLOGV) { |
| 7153 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7154 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 7155 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 7156 | + mRequestedWidth + ", mRequestedheight=" |
| 7157 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7158 | + "): frame=" + mFrame.toShortString() |
| 7159 | + " ci=" + contentInsets.toShortString() |
| 7160 | + " vi=" + visibleInsets.toShortString()); |
| 7161 | //} |
| 7162 | } |
| 7163 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7164 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7165 | public Rect getFrameLw() { |
| 7166 | return mFrame; |
| 7167 | } |
| 7168 | |
| 7169 | public Rect getShownFrameLw() { |
| 7170 | return mShownFrame; |
| 7171 | } |
| 7172 | |
| 7173 | public Rect getDisplayFrameLw() { |
| 7174 | return mDisplayFrame; |
| 7175 | } |
| 7176 | |
| 7177 | public Rect getContentFrameLw() { |
| 7178 | return mContentFrame; |
| 7179 | } |
| 7180 | |
| 7181 | public Rect getVisibleFrameLw() { |
| 7182 | return mVisibleFrame; |
| 7183 | } |
| 7184 | |
| 7185 | public boolean getGivenInsetsPendingLw() { |
| 7186 | return mGivenInsetsPending; |
| 7187 | } |
| 7188 | |
| 7189 | public Rect getGivenContentInsetsLw() { |
| 7190 | return mGivenContentInsets; |
| 7191 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7192 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7193 | public Rect getGivenVisibleInsetsLw() { |
| 7194 | return mGivenVisibleInsets; |
| 7195 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7196 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7197 | public WindowManager.LayoutParams getAttrs() { |
| 7198 | return mAttrs; |
| 7199 | } |
| 7200 | |
| 7201 | public int getSurfaceLayer() { |
| 7202 | return mLayer; |
| 7203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | public IApplicationToken getAppToken() { |
| 7206 | return mAppToken != null ? mAppToken.appToken : null; |
| 7207 | } |
| 7208 | |
| 7209 | public boolean hasAppShownWindows() { |
| 7210 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7211 | } |
| 7212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7213 | public void setAnimation(Animation anim) { |
| 7214 | if (localLOGV) Log.v( |
| 7215 | TAG, "Setting animation in " + this + ": " + anim); |
| 7216 | mAnimating = false; |
| 7217 | mLocalAnimating = false; |
| 7218 | mAnimation = anim; |
| 7219 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7220 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7221 | } |
| 7222 | |
| 7223 | public void clearAnimation() { |
| 7224 | if (mAnimation != null) { |
| 7225 | mAnimating = true; |
| 7226 | mLocalAnimating = false; |
| 7227 | mAnimation = null; |
| 7228 | } |
| 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 | Surface createSurfaceLocked() { |
| 7232 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7233 | mReportDestroySurface = false; |
| 7234 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7235 | mDrawPending = true; |
| 7236 | mCommitDrawPending = false; |
| 7237 | mReadyToShow = false; |
| 7238 | if (mAppToken != null) { |
| 7239 | mAppToken.allDrawn = false; |
| 7240 | } |
| 7241 | |
| 7242 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7243 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7244 | flags |= Surface.PUSH_BUFFERS; |
| 7245 | } |
| 7246 | |
| 7247 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7248 | flags |= Surface.SECURE; |
| 7249 | } |
| 7250 | if (DEBUG_VISIBILITY) Log.v( |
| 7251 | TAG, "Creating surface in session " |
| 7252 | + mSession.mSurfaceSession + " window " + this |
| 7253 | + " w=" + mFrame.width() |
| 7254 | + " h=" + mFrame.height() + " format=" |
| 7255 | + mAttrs.format + " flags=" + flags); |
| 7256 | |
| 7257 | int w = mFrame.width(); |
| 7258 | int h = mFrame.height(); |
| 7259 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7260 | // for a scaled surface, we always want the requested |
| 7261 | // size. |
| 7262 | w = mRequestedWidth; |
| 7263 | h = mRequestedHeight; |
| 7264 | } |
| 7265 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7266 | // Something is wrong and SurfaceFlinger will not like this, |
| 7267 | // try to revert to sane values |
| 7268 | if (w <= 0) w = 1; |
| 7269 | if (h <= 0) h = 1; |
| 7270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7271 | try { |
| 7272 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7273 | mSession.mSurfaceSession, mSession.mPid, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7274 | 0, w, h, mAttrs.format, flags); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7275 | if (SHOW_TRANSACTIONS) Log.i(TAG, " CREATE SURFACE " |
| 7276 | + mSurface + " IN SESSION " |
| 7277 | + mSession.mSurfaceSession |
| 7278 | + ": pid=" + mSession.mPid + " format=" |
| 7279 | + mAttrs.format + " flags=0x" |
| 7280 | + Integer.toHexString(flags)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7281 | } catch (Surface.OutOfResourcesException e) { |
| 7282 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 7283 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7284 | return null; |
| 7285 | } catch (Exception e) { |
| 7286 | Log.e(TAG, "Exception creating surface", e); |
| 7287 | return null; |
| 7288 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7289 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7290 | if (localLOGV) Log.v( |
| 7291 | TAG, "Got surface: " + mSurface |
| 7292 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7293 | + ", animLayer=" + mAnimLayer); |
| 7294 | if (SHOW_TRANSACTIONS) { |
| 7295 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 7296 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 7297 | + mAttrs.getTitle() + ") pos=(" + |
| 7298 | mFrame.left + "," + mFrame.top + ") (" + |
| 7299 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7300 | mAnimLayer + " HIDE"); |
| 7301 | } |
| 7302 | Surface.openTransaction(); |
| 7303 | try { |
| 7304 | try { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7305 | mSurface.setPosition(mFrame.left + mXOffset, |
| 7306 | mFrame.top + mYOffset); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7307 | mSurface.setLayer(mAnimLayer); |
| 7308 | mSurface.hide(); |
| 7309 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7310 | if (SHOW_TRANSACTIONS) Log.i(TAG, " SURFACE " |
| 7311 | + mSurface + ": DITHER"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7312 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7313 | Surface.SURFACE_DITHER); |
| 7314 | } |
| 7315 | } catch (RuntimeException e) { |
| 7316 | Log.w(TAG, "Error creating surface in " + w, e); |
| 7317 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7318 | } |
| 7319 | mLastHidden = true; |
| 7320 | } finally { |
| 7321 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 7322 | Surface.closeTransaction(); |
| 7323 | } |
| 7324 | if (localLOGV) Log.v( |
| 7325 | TAG, "Created surface " + this); |
| 7326 | } |
| 7327 | return mSurface; |
| 7328 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7329 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7330 | void destroySurfaceLocked() { |
| 7331 | // Window is no longer on-screen, so can no longer receive |
| 7332 | // key events... if we were waiting for it to finish |
| 7333 | // handling a key event, the wait is over! |
| 7334 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 7335 | KeyWaiter.RETURN_NOTHING); |
| 7336 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7337 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 7338 | |
| 7339 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7340 | mAppToken.startingDisplayed = false; |
| 7341 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7342 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7343 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7344 | mDrawPending = false; |
| 7345 | mCommitDrawPending = false; |
| 7346 | mReadyToShow = false; |
| 7347 | |
| 7348 | int i = mChildWindows.size(); |
| 7349 | while (i > 0) { |
| 7350 | i--; |
| 7351 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7352 | c.mAttachedHidden = true; |
| 7353 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7354 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7355 | if (mReportDestroySurface) { |
| 7356 | mReportDestroySurface = false; |
| 7357 | mSurfacePendingDestroy = true; |
| 7358 | try { |
| 7359 | mClient.dispatchGetNewSurface(); |
| 7360 | // We'll really destroy on the next time around. |
| 7361 | return; |
| 7362 | } catch (RemoteException e) { |
| 7363 | } |
| 7364 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7365 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7366 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7367 | if (DEBUG_VISIBILITY) { |
| 7368 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7369 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7370 | Log.w(TAG, "Window " + this + " destroying surface " |
| 7371 | + mSurface + ", session " + mSession, e); |
| 7372 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7373 | if (SHOW_TRANSACTIONS) { |
| 7374 | RuntimeException ex = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7375 | if (!HIDE_STACK_CRAWLS) ex.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7376 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 7377 | + mAttrs.getTitle() + ")", ex); |
| 7378 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7379 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7380 | } catch (RuntimeException e) { |
| 7381 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 7382 | + " surface " + mSurface + " session " + mSession |
| 7383 | + ": " + e.toString()); |
| 7384 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7386 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | } |
| 7388 | } |
| 7389 | |
| 7390 | boolean finishDrawingLocked() { |
| 7391 | if (mDrawPending) { |
| 7392 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 7393 | TAG, "finishDrawingLocked: " + mSurface); |
| 7394 | mCommitDrawPending = true; |
| 7395 | mDrawPending = false; |
| 7396 | return true; |
| 7397 | } |
| 7398 | return false; |
| 7399 | } |
| 7400 | |
| 7401 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7402 | boolean commitFinishDrawingLocked(long currentTime) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7403 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 7404 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7405 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7406 | } |
| 7407 | mCommitDrawPending = false; |
| 7408 | mReadyToShow = true; |
| 7409 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7410 | final AppWindowToken atoken = mAppToken; |
| 7411 | if (atoken == null || atoken.allDrawn || starting) { |
| 7412 | performShowLocked(); |
| 7413 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7414 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7415 | } |
| 7416 | |
| 7417 | // This must be called while inside a transaction. |
| 7418 | boolean performShowLocked() { |
| 7419 | if (DEBUG_VISIBILITY) { |
| 7420 | RuntimeException e = new RuntimeException(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7421 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7422 | Log.v(TAG, "performShow on " + this |
| 7423 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7424 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7425 | } |
| 7426 | if (mReadyToShow && isReadyForDisplay()) { |
| 7427 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 7428 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 7429 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 7430 | + " during animation: policyVis=" + mPolicyVisibility |
| 7431 | + " attHidden=" + mAttachedHidden |
| 7432 | + " tok.hiddenRequested=" |
| 7433 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7434 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7435 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7436 | + " animating=" + mAnimating |
| 7437 | + " tok animating=" |
| 7438 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7439 | if (!showSurfaceRobustlyLocked(this)) { |
| 7440 | return false; |
| 7441 | } |
| 7442 | mLastAlpha = -1; |
| 7443 | mHasDrawn = true; |
| 7444 | mLastHidden = false; |
| 7445 | mReadyToShow = false; |
| 7446 | enableScreenIfNeededLocked(); |
| 7447 | |
| 7448 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7450 | int i = mChildWindows.size(); |
| 7451 | while (i > 0) { |
| 7452 | i--; |
| 7453 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7454 | if (c.mSurface != null && c.mAttachedHidden) { |
| 7455 | c.mAttachedHidden = false; |
| 7456 | c.performShowLocked(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7457 | // It hadn't been shown, which means layout not |
| 7458 | // performed on it, so now we want to make sure to |
| 7459 | // do a layout. If called from within the transaction |
| 7460 | // loop, this will cause it to restart with a new |
| 7461 | // layout. |
| 7462 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7463 | } |
| 7464 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7466 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7467 | && mAppToken != null) { |
| 7468 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7469 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7470 | if (mAppToken.startingData != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7471 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Log.v(TAG, |
| 7472 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7473 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7474 | // If this initial window is animating, stop it -- we |
| 7475 | // will do an animation to reveal it from behind the |
| 7476 | // starting window, so there is no need for it to also |
| 7477 | // be doing its own stuff. |
| 7478 | if (mAnimation != null) { |
| 7479 | mAnimation = null; |
| 7480 | // Make sure we clean up the animation. |
| 7481 | mAnimating = true; |
| 7482 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | mFinishedStarting.add(mAppToken); |
| 7484 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7485 | } |
| 7486 | mAppToken.updateReportedVisibilityLocked(); |
| 7487 | } |
| 7488 | } |
| 7489 | return true; |
| 7490 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7491 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7492 | // This must be called while inside a transaction. Returns true if |
| 7493 | // there is more animation to run. |
| 7494 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7495 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7496 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7497 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7498 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7499 | mHasTransformation = true; |
| 7500 | mHasLocalTransformation = true; |
| 7501 | if (!mLocalAnimating) { |
| 7502 | if (DEBUG_ANIM) Log.v( |
| 7503 | TAG, "Starting animation in " + this + |
| 7504 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7505 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7506 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7507 | mAnimation.setStartTime(currentTime); |
| 7508 | mLocalAnimating = true; |
| 7509 | mAnimating = true; |
| 7510 | } |
| 7511 | mTransformation.clear(); |
| 7512 | final boolean more = mAnimation.getTransformation( |
| 7513 | currentTime, mTransformation); |
| 7514 | if (DEBUG_ANIM) Log.v( |
| 7515 | TAG, "Stepped animation in " + this + |
| 7516 | ": more=" + more + ", xform=" + mTransformation); |
| 7517 | if (more) { |
| 7518 | // we're not done! |
| 7519 | return true; |
| 7520 | } |
| 7521 | if (DEBUG_ANIM) Log.v( |
| 7522 | TAG, "Finished animation in " + this + |
| 7523 | " @ " + currentTime); |
| 7524 | mAnimation = null; |
| 7525 | //WindowManagerService.this.dump(); |
| 7526 | } |
| 7527 | mHasLocalTransformation = false; |
| 7528 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7529 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7530 | // When our app token is animating, we kind-of pretend like |
| 7531 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7532 | // part of this check means that we will only do this if |
| 7533 | // our window is not currently exiting, or it is not |
| 7534 | // locally animating itself. The idea being that one that |
| 7535 | // is exiting and doing a local animation should be removed |
| 7536 | // once that animation is done. |
| 7537 | mAnimating = true; |
| 7538 | mHasTransformation = true; |
| 7539 | mTransformation.clear(); |
| 7540 | return false; |
| 7541 | } else if (mHasTransformation) { |
| 7542 | // Little trick to get through the path below to act like |
| 7543 | // we have finished an animation. |
| 7544 | mAnimating = true; |
| 7545 | } else if (isAnimating()) { |
| 7546 | mAnimating = true; |
| 7547 | } |
| 7548 | } else if (mAnimation != null) { |
| 7549 | // If the display is frozen, and there is a pending animation, |
| 7550 | // clear it and make sure we run the cleanup code. |
| 7551 | mAnimating = true; |
| 7552 | mLocalAnimating = true; |
| 7553 | mAnimation = null; |
| 7554 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7555 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7556 | if (!mAnimating && !mLocalAnimating) { |
| 7557 | return false; |
| 7558 | } |
| 7559 | |
| 7560 | if (DEBUG_ANIM) Log.v( |
| 7561 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7562 | + ", reportedVisible=" |
| 7563 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7564 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | mAnimating = false; |
| 7566 | mLocalAnimating = false; |
| 7567 | mAnimation = null; |
| 7568 | mAnimLayer = mLayer; |
| 7569 | if (mIsImWindow) { |
| 7570 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7571 | } else if (mIsWallpaper) { |
| 7572 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7573 | } |
| 7574 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 7575 | + " anim layer: " + mAnimLayer); |
| 7576 | mHasTransformation = false; |
| 7577 | mHasLocalTransformation = false; |
| 7578 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7579 | if (!mPolicyVisibility) { |
| 7580 | // Window is no longer visible -- make sure if we were waiting |
| 7581 | // for it to be displayed before enabling the display, that |
| 7582 | // we allow the display to be enabled now. |
| 7583 | enableScreenIfNeededLocked(); |
| 7584 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7585 | mTransformation.clear(); |
| 7586 | if (mHasDrawn |
| 7587 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7588 | && mAppToken != null |
| 7589 | && mAppToken.firstWindowDrawn |
| 7590 | && mAppToken.startingData != null) { |
| 7591 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 7592 | + mToken + ": first real window done animating"); |
| 7593 | mFinishedStarting.add(mAppToken); |
| 7594 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7595 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7596 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7597 | finishExit(); |
| 7598 | |
| 7599 | if (mAppToken != null) { |
| 7600 | mAppToken.updateReportedVisibilityLocked(); |
| 7601 | } |
| 7602 | |
| 7603 | return false; |
| 7604 | } |
| 7605 | |
| 7606 | void finishExit() { |
| 7607 | if (DEBUG_ANIM) Log.v( |
| 7608 | TAG, "finishExit in " + this |
| 7609 | + ": exiting=" + mExiting |
| 7610 | + " remove=" + mRemoveOnExit |
| 7611 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7612 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | final int N = mChildWindows.size(); |
| 7614 | for (int i=0; i<N; i++) { |
| 7615 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 7616 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7617 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7618 | if (!mExiting) { |
| 7619 | return; |
| 7620 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7621 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7622 | if (isWindowAnimating()) { |
| 7623 | return; |
| 7624 | } |
| 7625 | |
| 7626 | if (localLOGV) Log.v( |
| 7627 | TAG, "Exit animation finished in " + this |
| 7628 | + ": remove=" + mRemoveOnExit); |
| 7629 | if (mSurface != null) { |
| 7630 | mDestroySurface.add(this); |
| 7631 | mDestroying = true; |
| 7632 | if (SHOW_TRANSACTIONS) Log.i( |
| 7633 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 7634 | try { |
| 7635 | mSurface.hide(); |
| 7636 | } catch (RuntimeException e) { |
| 7637 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 7638 | } |
| 7639 | mLastHidden = true; |
| 7640 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7641 | } |
| 7642 | mExiting = false; |
| 7643 | if (mRemoveOnExit) { |
| 7644 | mPendingRemove.add(this); |
| 7645 | mRemoveOnExit = false; |
| 7646 | } |
| 7647 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7648 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7650 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7651 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7652 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7653 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7654 | return true; |
| 7655 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7656 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7657 | void computeShownFrameLocked() { |
| 7658 | final boolean selfTransformation = mHasLocalTransformation; |
| 7659 | Transformation attachedTransformation = |
| 7660 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7661 | ? mAttachedWindow.mTransformation : null; |
| 7662 | Transformation appTransformation = |
| 7663 | (mAppToken != null && mAppToken.hasTransformation) |
| 7664 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7665 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7666 | // Wallpapers are animated based on the "real" window they |
| 7667 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7668 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7669 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7670 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7671 | mWallpaperTarget.mAnimation != null && |
| 7672 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7673 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7674 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| 7675 | Log.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 7676 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7677 | } |
| 7678 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7679 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7680 | mWallpaperTarget.mAppToken.animation != null && |
| 7681 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7682 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7683 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| 7684 | Log.v(TAG, "WP target app xform: " + appTransformation); |
| 7685 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7686 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7687 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7688 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7689 | if (selfTransformation || attachedTransformation != null |
| 7690 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7691 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7692 | final Rect frame = mFrame; |
| 7693 | final float tmpFloats[] = mTmpFloats; |
| 7694 | final Matrix tmpMatrix = mTmpMatrix; |
| 7695 | |
| 7696 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7697 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7698 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7699 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7700 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7701 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7702 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7703 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7704 | } |
| 7705 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7706 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7707 | } |
| 7708 | |
| 7709 | // "convert" it into SurfaceFlinger's format |
| 7710 | // (a 2x2 matrix + an offset) |
| 7711 | // Here we must not transform the position of the surface |
| 7712 | // since it is already included in the transformation. |
| 7713 | //Log.i(TAG, "Transform: " + matrix); |
| 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 | tmpMatrix.getValues(tmpFloats); |
| 7716 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7717 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7718 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7719 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7720 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7721 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7722 | int w = frame.width(); |
| 7723 | int h = frame.height(); |
| 7724 | mShownFrame.set(x, y, x+w, y+h); |
| 7725 | |
| 7726 | // Now set the alpha... but because our current hardware |
| 7727 | // can't do alpha transformation on a non-opaque surface, |
| 7728 | // turn it off if we are running an animation that is also |
| 7729 | // transforming since it is more important to have that |
| 7730 | // animation be smooth. |
| 7731 | mShownAlpha = mAlpha; |
| 7732 | if (!mLimitedAlphaCompositing |
| 7733 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7734 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7735 | && x == frame.left && y == frame.top))) { |
| 7736 | //Log.i(TAG, "Applying alpha transform"); |
| 7737 | if (selfTransformation) { |
| 7738 | mShownAlpha *= mTransformation.getAlpha(); |
| 7739 | } |
| 7740 | if (attachedTransformation != null) { |
| 7741 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7742 | } |
| 7743 | if (appTransformation != null) { |
| 7744 | mShownAlpha *= appTransformation.getAlpha(); |
| 7745 | } |
| 7746 | } else { |
| 7747 | //Log.i(TAG, "Not applying alpha transform"); |
| 7748 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | if (localLOGV) Log.v( |
| 7751 | TAG, "Continuing animation in " + this + |
| 7752 | ": " + mShownFrame + |
| 7753 | ", alpha=" + mTransformation.getAlpha()); |
| 7754 | return; |
| 7755 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7757 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7758 | if (mXOffset != 0 || mYOffset != 0) { |
| 7759 | mShownFrame.offset(mXOffset, mYOffset); |
| 7760 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7761 | mShownAlpha = mAlpha; |
| 7762 | mDsDx = 1; |
| 7763 | mDtDx = 0; |
| 7764 | mDsDy = 0; |
| 7765 | mDtDy = 1; |
| 7766 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7767 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7768 | /** |
| 7769 | * Is this window visible? It is not visible if there is no |
| 7770 | * surface, or we are in the process of running an exit animation |
| 7771 | * that will remove the surface, or its app token has been hidden. |
| 7772 | */ |
| 7773 | public boolean isVisibleLw() { |
| 7774 | final AppWindowToken atoken = mAppToken; |
| 7775 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7776 | && (atoken == null || !atoken.hiddenRequested) |
| 7777 | && !mExiting && !mDestroying; |
| 7778 | } |
| 7779 | |
| 7780 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7781 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7782 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7783 | * things like window flags that impact the keyguard. |
| 7784 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7785 | * for this "hidden behind keyguard" state rather than overloading |
| 7786 | * mPolicyVisibility. Ungh. |
| 7787 | */ |
| 7788 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7789 | final AppWindowToken atoken = mAppToken; |
| 7790 | return mSurface != null && !mAttachedHidden |
| 7791 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| 7792 | && !mExiting && !mDestroying; |
| 7793 | } |
| 7794 | |
| 7795 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | * Is this window visible, ignoring its app token? It is not visible |
| 7797 | * if there is no surface, or we are in the process of running an exit animation |
| 7798 | * that will remove the surface. |
| 7799 | */ |
| 7800 | public boolean isWinVisibleLw() { |
| 7801 | final AppWindowToken atoken = mAppToken; |
| 7802 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7803 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7804 | && !mExiting && !mDestroying; |
| 7805 | } |
| 7806 | |
| 7807 | /** |
| 7808 | * The same as isVisible(), but follows the current hidden state of |
| 7809 | * the associated app token, not the pending requested hidden state. |
| 7810 | */ |
| 7811 | boolean isVisibleNow() { |
| 7812 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7813 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7814 | } |
| 7815 | |
| 7816 | /** |
| 7817 | * Same as isVisible(), but we also count it as visible between the |
| 7818 | * call to IWindowSession.add() and the first relayout(). |
| 7819 | */ |
| 7820 | boolean isVisibleOrAdding() { |
| 7821 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7822 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7823 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7824 | && mPolicyVisibility && !mAttachedHidden |
| 7825 | && (atoken == null || !atoken.hiddenRequested) |
| 7826 | && !mExiting && !mDestroying; |
| 7827 | } |
| 7828 | |
| 7829 | /** |
| 7830 | * Is this window currently on-screen? It is on-screen either if it |
| 7831 | * is visible or it is currently running an animation before no longer |
| 7832 | * being visible. |
| 7833 | */ |
| 7834 | boolean isOnScreen() { |
| 7835 | final AppWindowToken atoken = mAppToken; |
| 7836 | if (atoken != null) { |
| 7837 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7838 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7839 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | } else { |
| 7841 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7842 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7843 | } |
| 7844 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7845 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7846 | /** |
| 7847 | * Like isOnScreen(), but we don't return true if the window is part |
| 7848 | * of a transition that has not yet been started. |
| 7849 | */ |
| 7850 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7851 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7852 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7853 | return false; |
| 7854 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7855 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7856 | final boolean animating = atoken != null |
| 7857 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7858 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7859 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7860 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7861 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7862 | } |
| 7863 | |
| 7864 | /** Is the window or its container currently animating? */ |
| 7865 | boolean isAnimating() { |
| 7866 | final WindowState attached = mAttachedWindow; |
| 7867 | final AppWindowToken atoken = mAppToken; |
| 7868 | return mAnimation != null |
| 7869 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7870 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7871 | (atoken.animation != null |
| 7872 | || atoken.inPendingTransaction)); |
| 7873 | } |
| 7874 | |
| 7875 | /** Is this window currently animating? */ |
| 7876 | boolean isWindowAnimating() { |
| 7877 | return mAnimation != null; |
| 7878 | } |
| 7879 | |
| 7880 | /** |
| 7881 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7882 | * been drawn. |
| 7883 | */ |
| 7884 | public boolean isDisplayedLw() { |
| 7885 | final AppWindowToken atoken = mAppToken; |
| 7886 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7887 | && !mDrawPending && !mCommitDrawPending |
| 7888 | && ((!mAttachedHidden && |
| 7889 | (atoken == null || !atoken.hiddenRequested)) |
| 7890 | || mAnimating); |
| 7891 | } |
| 7892 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7893 | /** |
| 7894 | * Returns true if the window has a surface that it has drawn a |
| 7895 | * complete UI in to. |
| 7896 | */ |
| 7897 | public boolean isDrawnLw() { |
| 7898 | final AppWindowToken atoken = mAppToken; |
| 7899 | return mSurface != null && !mDestroying |
| 7900 | && !mDrawPending && !mCommitDrawPending; |
| 7901 | } |
| 7902 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7903 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 7904 | boolean shownFrame, boolean onlyOpaque) { |
| 7905 | if (mSurface == null) { |
| 7906 | return false; |
| 7907 | } |
| 7908 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 7909 | return false; |
| 7910 | } |
| 7911 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 7912 | return false; |
| 7913 | } |
| 7914 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7915 | |
| 7916 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7917 | return frame.left <= mCompatibleScreenFrame.left && |
| 7918 | frame.top <= mCompatibleScreenFrame.top && |
| 7919 | frame.right >= mCompatibleScreenFrame.right && |
| 7920 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 7921 | } else { |
| 7922 | return frame.left <= 0 && frame.top <= 0 |
| 7923 | && frame.right >= screenWidth |
| 7924 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7925 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7927 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7928 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7929 | * Return true if the window is opaque and fully drawn. This indicates |
| 7930 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7931 | */ |
| 7932 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7933 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7934 | || mAttrs.type == TYPE_WALLPAPER) |
| 7935 | && mSurface != null && mAnimation == null |
| 7936 | && (mAppToken == null || mAppToken.animation == null) |
| 7937 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7938 | } |
| 7939 | |
| 7940 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7941 | return |
| 7942 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7943 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7944 | // only if it's visible |
| 7945 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7946 | // and only if the application fills the compatible screen |
| 7947 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7948 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7949 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7950 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7951 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7952 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7953 | } |
| 7954 | |
| 7955 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7956 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7957 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7958 | } |
| 7959 | |
| 7960 | void removeLocked() { |
| 7961 | if (mAttachedWindow != null) { |
| 7962 | mAttachedWindow.mChildWindows.remove(this); |
| 7963 | } |
| 7964 | destroySurfaceLocked(); |
| 7965 | mSession.windowRemovedLocked(); |
| 7966 | try { |
| 7967 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7968 | } catch (RuntimeException e) { |
| 7969 | // Ignore if it has already been removed (usually because |
| 7970 | // we are doing this as part of processing a death note.) |
| 7971 | } |
| 7972 | } |
| 7973 | |
| 7974 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7975 | public void binderDied() { |
| 7976 | try { |
| 7977 | synchronized(mWindowMap) { |
| 7978 | WindowState win = windowForClientLocked(mSession, mClient); |
| 7979 | Log.i(TAG, "WIN DEATH: " + win); |
| 7980 | if (win != null) { |
| 7981 | removeWindowLocked(mSession, win); |
| 7982 | } |
| 7983 | } |
| 7984 | } catch (IllegalArgumentException ex) { |
| 7985 | // This will happen if the window has already been |
| 7986 | // removed. |
| 7987 | } |
| 7988 | } |
| 7989 | } |
| 7990 | |
| 7991 | /** Returns true if this window desires key events. */ |
| 7992 | public final boolean canReceiveKeys() { |
| 7993 | return isVisibleOrAdding() |
| 7994 | && (mViewVisibility == View.VISIBLE) |
| 7995 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7996 | } |
| 7997 | |
| 7998 | public boolean hasDrawnLw() { |
| 7999 | return mHasDrawn; |
| 8000 | } |
| 8001 | |
| 8002 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8003 | return showLw(doAnimation, true); |
| 8004 | } |
| 8005 | |
| 8006 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8007 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8008 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8009 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8010 | mPolicyVisibility = true; |
| 8011 | mPolicyVisibilityAfterAnim = true; |
| 8012 | if (doAnimation) { |
| 8013 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8014 | } |
| 8015 | if (requestAnim) { |
| 8016 | requestAnimationLocked(0); |
| 8017 | } |
| 8018 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8019 | } |
| 8020 | |
| 8021 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8022 | return hideLw(doAnimation, true); |
| 8023 | } |
| 8024 | |
| 8025 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8026 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8027 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8028 | if (!current) { |
| 8029 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8030 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8031 | if (doAnimation) { |
| 8032 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8033 | if (mAnimation == null) { |
| 8034 | doAnimation = false; |
| 8035 | } |
| 8036 | } |
| 8037 | if (doAnimation) { |
| 8038 | mPolicyVisibilityAfterAnim = false; |
| 8039 | } else { |
| 8040 | mPolicyVisibilityAfterAnim = false; |
| 8041 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8042 | // Window is no longer visible -- make sure if we were waiting |
| 8043 | // for it to be displayed before enabling the display, that |
| 8044 | // we allow the display to be enabled now. |
| 8045 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8046 | } |
| 8047 | if (requestAnim) { |
| 8048 | requestAnimationLocked(0); |
| 8049 | } |
| 8050 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8051 | } |
| 8052 | |
| 8053 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8054 | StringBuilder sb = new StringBuilder(64); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8055 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8056 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8057 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8058 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8059 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8060 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8061 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8062 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8063 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8064 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8065 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8066 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8067 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8068 | } |
| 8069 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8070 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8071 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8072 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8073 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8074 | pw.print("="); pw.print(mAnimLayer); |
| 8075 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8076 | if (mSurface != null) { |
| 8077 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 8078 | } |
| 8079 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8080 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8081 | if (mAppToken != null) { |
| 8082 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8083 | } |
| 8084 | if (mTargetAppToken != null) { |
| 8085 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8086 | } |
| 8087 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8088 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8089 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8090 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8091 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8092 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8093 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8094 | pw.print(mPolicyVisibility); |
| 8095 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8096 | pw.print(mPolicyVisibilityAfterAnim); |
| 8097 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8098 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8099 | if (!mRelayoutCalled) { |
| 8100 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8101 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8102 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8103 | pw.print(" h="); pw.println(mRequestedHeight); |
| 8104 | if (mXOffset != 0 || mYOffset != 0) { |
| 8105 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8106 | pw.print(" y="); pw.println(mYOffset); |
| 8107 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8108 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8109 | mGivenContentInsets.printShortString(pw); |
| 8110 | pw.print(" mGivenVisibleInsets="); |
| 8111 | mGivenVisibleInsets.printShortString(pw); |
| 8112 | pw.println(); |
| 8113 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8114 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8115 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8116 | } |
| 8117 | pw.print(prefix); pw.print("mShownFrame="); |
| 8118 | mShownFrame.printShortString(pw); |
| 8119 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8120 | pw.println(); |
| 8121 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8122 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8123 | pw.println(); |
| 8124 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8125 | mContainingFrame.printShortString(pw); |
| 8126 | pw.print(" mDisplayFrame="); |
| 8127 | mDisplayFrame.printShortString(pw); |
| 8128 | pw.println(); |
| 8129 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8130 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8131 | pw.println(); |
| 8132 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8133 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8134 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8135 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8136 | pw.println(); |
| 8137 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8138 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8139 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8140 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8141 | } |
| 8142 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8143 | || mAnimation != null) { |
| 8144 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8145 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8146 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8147 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8148 | } |
| 8149 | if (mHasTransformation || mHasLocalTransformation) { |
| 8150 | pw.print(prefix); pw.print("XForm: has="); |
| 8151 | pw.print(mHasTransformation); |
| 8152 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8153 | pw.print(" "); mTransformation.printShortString(pw); |
| 8154 | pw.println(); |
| 8155 | } |
| 8156 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8157 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8158 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8159 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8160 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8161 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8162 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8163 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8164 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8165 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8166 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8167 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8168 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8169 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8170 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8171 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8172 | if (mHScale != 1 || mVScale != 1) { |
| 8173 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8174 | pw.print(" mVScale="); pw.println(mVScale); |
| 8175 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8176 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8177 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8178 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8179 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8180 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8181 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8182 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8183 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8184 | } |
| 8185 | |
| 8186 | @Override |
| 8187 | public String toString() { |
| 8188 | return "Window{" |
| 8189 | + Integer.toHexString(System.identityHashCode(this)) |
| 8190 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 8191 | } |
| 8192 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8193 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8194 | // ------------------------------------------------------------- |
| 8195 | // Window Token State |
| 8196 | // ------------------------------------------------------------- |
| 8197 | |
| 8198 | class WindowToken { |
| 8199 | // The actual token. |
| 8200 | final IBinder token; |
| 8201 | |
| 8202 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8203 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8205 | // Set if this token was explicitly added by a client, so should |
| 8206 | // not be removed when all windows are removed. |
| 8207 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8208 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8209 | // For printing. |
| 8210 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8212 | // If this is an AppWindowToken, this is non-null. |
| 8213 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8214 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8215 | // All of the windows associated with this token. |
| 8216 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8217 | |
| 8218 | // Is key dispatching paused for this token? |
| 8219 | boolean paused = false; |
| 8220 | |
| 8221 | // Should this token's windows be hidden? |
| 8222 | boolean hidden; |
| 8223 | |
| 8224 | // Temporary for finding which tokens no longer have visible windows. |
| 8225 | boolean hasVisible; |
| 8226 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8227 | // Set to true when this token is in a pending transaction where it |
| 8228 | // will be shown. |
| 8229 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8230 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8231 | // Set to true when this token is in a pending transaction where it |
| 8232 | // will be hidden. |
| 8233 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8234 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8235 | // Set to true when this token is in a pending transaction where its |
| 8236 | // windows will be put to the bottom of the list. |
| 8237 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8238 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8239 | // Set to true when this token is in a pending transaction where its |
| 8240 | // windows will be put to the top of the list. |
| 8241 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8242 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8243 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8244 | token = _token; |
| 8245 | windowType = type; |
| 8246 | explicit = _explicit; |
| 8247 | } |
| 8248 | |
| 8249 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8250 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8251 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8252 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8253 | pw.print(" hidden="); pw.print(hidden); |
| 8254 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8255 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8256 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8257 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8258 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8259 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8260 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8261 | } |
| 8262 | |
| 8263 | @Override |
| 8264 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8265 | if (stringName == null) { |
| 8266 | StringBuilder sb = new StringBuilder(); |
| 8267 | sb.append("WindowToken{"); |
| 8268 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8269 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8270 | stringName = sb.toString(); |
| 8271 | } |
| 8272 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8273 | } |
| 8274 | }; |
| 8275 | |
| 8276 | class AppWindowToken extends WindowToken { |
| 8277 | // Non-null only for application tokens. |
| 8278 | final IApplicationToken appToken; |
| 8279 | |
| 8280 | // All of the windows and child windows that are included in this |
| 8281 | // application token. Note this list is NOT sorted! |
| 8282 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8283 | |
| 8284 | int groupId = -1; |
| 8285 | boolean appFullscreen; |
| 8286 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8288 | // These are used for determining when all windows associated with |
| 8289 | // an activity have been drawn, so they can be made visible together |
| 8290 | // at the same time. |
| 8291 | int lastTransactionSequence = mTransactionSequence-1; |
| 8292 | int numInterestingWindows; |
| 8293 | int numDrawnWindows; |
| 8294 | boolean inPendingTransaction; |
| 8295 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8296 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8297 | // Is this token going to be hidden in a little while? If so, it |
| 8298 | // won't be taken into account for setting the screen orientation. |
| 8299 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8300 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8301 | // Is this window's surface needed? This is almost like hidden, except |
| 8302 | // it will sometimes be true a little earlier: when the token has |
| 8303 | // been shown, but is still waiting for its app transition to execute |
| 8304 | // before making its windows shown. |
| 8305 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8306 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8307 | // Have we told the window clients to hide themselves? |
| 8308 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8310 | // Last visibility state we reported to the app token. |
| 8311 | boolean reportedVisible; |
| 8312 | |
| 8313 | // Set to true when the token has been removed from the window mgr. |
| 8314 | boolean removed; |
| 8315 | |
| 8316 | // Have we been asked to have this token keep the screen frozen? |
| 8317 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8319 | boolean animating; |
| 8320 | Animation animation; |
| 8321 | boolean hasTransformation; |
| 8322 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8324 | // Offset to the window of all layers in the token, for use by |
| 8325 | // AppWindowToken animations. |
| 8326 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8327 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8328 | // Information about an application starting window if displayed. |
| 8329 | StartingData startingData; |
| 8330 | WindowState startingWindow; |
| 8331 | View startingView; |
| 8332 | boolean startingDisplayed; |
| 8333 | boolean startingMoved; |
| 8334 | boolean firstWindowDrawn; |
| 8335 | |
| 8336 | AppWindowToken(IApplicationToken _token) { |
| 8337 | super(_token.asBinder(), |
| 8338 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8339 | appWindowToken = this; |
| 8340 | appToken = _token; |
| 8341 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8342 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8343 | public void setAnimation(Animation anim) { |
| 8344 | if (localLOGV) Log.v( |
| 8345 | TAG, "Setting animation in " + this + ": " + anim); |
| 8346 | animation = anim; |
| 8347 | animating = false; |
| 8348 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8349 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8350 | int zorder = anim.getZAdjustment(); |
| 8351 | int adj = 0; |
| 8352 | if (zorder == Animation.ZORDER_TOP) { |
| 8353 | adj = TYPE_LAYER_OFFSET; |
| 8354 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8355 | adj = -TYPE_LAYER_OFFSET; |
| 8356 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8358 | if (animLayerAdjustment != adj) { |
| 8359 | animLayerAdjustment = adj; |
| 8360 | updateLayers(); |
| 8361 | } |
| 8362 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8363 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8364 | public void setDummyAnimation() { |
| 8365 | if (animation == null) { |
| 8366 | if (localLOGV) Log.v( |
| 8367 | TAG, "Setting dummy animation in " + this); |
| 8368 | animation = sDummyAnimation; |
| 8369 | } |
| 8370 | } |
| 8371 | |
| 8372 | public void clearAnimation() { |
| 8373 | if (animation != null) { |
| 8374 | animation = null; |
| 8375 | animating = true; |
| 8376 | } |
| 8377 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8378 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8379 | void updateLayers() { |
| 8380 | final int N = allAppWindows.size(); |
| 8381 | final int adj = animLayerAdjustment; |
| 8382 | for (int i=0; i<N; i++) { |
| 8383 | WindowState w = allAppWindows.get(i); |
| 8384 | w.mAnimLayer = w.mLayer + adj; |
| 8385 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 8386 | + w.mAnimLayer); |
| 8387 | if (w == mInputMethodTarget) { |
| 8388 | setInputMethodAnimLayerAdjustment(adj); |
| 8389 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8390 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8391 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8392 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8393 | } |
| 8394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8396 | void sendAppVisibilityToClients() { |
| 8397 | final int N = allAppWindows.size(); |
| 8398 | for (int i=0; i<N; i++) { |
| 8399 | WindowState win = allAppWindows.get(i); |
| 8400 | if (win == startingWindow && clientHidden) { |
| 8401 | // Don't hide the starting window. |
| 8402 | continue; |
| 8403 | } |
| 8404 | try { |
| 8405 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8406 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8407 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8408 | } catch (RemoteException e) { |
| 8409 | } |
| 8410 | } |
| 8411 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8412 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8413 | void showAllWindowsLocked() { |
| 8414 | final int NW = allAppWindows.size(); |
| 8415 | for (int i=0; i<NW; i++) { |
| 8416 | WindowState w = allAppWindows.get(i); |
| 8417 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8418 | "performing show on: " + w); |
| 8419 | w.performShowLocked(); |
| 8420 | } |
| 8421 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8422 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8423 | // This must be called while inside a transaction. |
| 8424 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8425 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8426 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8427 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8428 | if (animation == sDummyAnimation) { |
| 8429 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8430 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8431 | // when it is really time to animate, this will be set to |
| 8432 | // a real animation and the next call will execute normally. |
| 8433 | return false; |
| 8434 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8436 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8437 | if (!animating) { |
| 8438 | if (DEBUG_ANIM) Log.v( |
| 8439 | TAG, "Starting animation in " + this + |
| 8440 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8441 | + " scale=" + mTransitionAnimationScale |
| 8442 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8443 | animation.initialize(dw, dh, dw, dh); |
| 8444 | animation.setStartTime(currentTime); |
| 8445 | animating = true; |
| 8446 | } |
| 8447 | transformation.clear(); |
| 8448 | final boolean more = animation.getTransformation( |
| 8449 | currentTime, transformation); |
| 8450 | if (DEBUG_ANIM) Log.v( |
| 8451 | TAG, "Stepped animation in " + this + |
| 8452 | ": more=" + more + ", xform=" + transformation); |
| 8453 | if (more) { |
| 8454 | // we're done! |
| 8455 | hasTransformation = true; |
| 8456 | return true; |
| 8457 | } |
| 8458 | if (DEBUG_ANIM) Log.v( |
| 8459 | TAG, "Finished animation in " + this + |
| 8460 | " @ " + currentTime); |
| 8461 | animation = null; |
| 8462 | } |
| 8463 | } else if (animation != null) { |
| 8464 | // If the display is frozen, and there is a pending animation, |
| 8465 | // clear it and make sure we run the cleanup code. |
| 8466 | animating = true; |
| 8467 | animation = null; |
| 8468 | } |
| 8469 | |
| 8470 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8472 | if (!animating) { |
| 8473 | return false; |
| 8474 | } |
| 8475 | |
| 8476 | clearAnimation(); |
| 8477 | animating = false; |
| 8478 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8479 | moveInputMethodWindowsIfNeededLocked(true); |
| 8480 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8481 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8482 | if (DEBUG_ANIM) Log.v( |
| 8483 | TAG, "Animation done in " + this |
| 8484 | + ": reportedVisible=" + reportedVisible); |
| 8485 | |
| 8486 | transformation.clear(); |
| 8487 | if (animLayerAdjustment != 0) { |
| 8488 | animLayerAdjustment = 0; |
| 8489 | updateLayers(); |
| 8490 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8491 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8492 | final int N = windows.size(); |
| 8493 | for (int i=0; i<N; i++) { |
| 8494 | ((WindowState)windows.get(i)).finishExit(); |
| 8495 | } |
| 8496 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8497 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8498 | return false; |
| 8499 | } |
| 8500 | |
| 8501 | void updateReportedVisibilityLocked() { |
| 8502 | if (appToken == null) { |
| 8503 | return; |
| 8504 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8506 | int numInteresting = 0; |
| 8507 | int numVisible = 0; |
| 8508 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8510 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 8511 | final int N = allAppWindows.size(); |
| 8512 | for (int i=0; i<N; i++) { |
| 8513 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8514 | if (win == startingWindow || win.mAppFreezing |
| 8515 | || win.mViewVisibility != View.VISIBLE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8516 | continue; |
| 8517 | } |
| 8518 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8519 | Log.v(TAG, "Win " + win + ": isDrawn=" |
| 8520 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8521 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8522 | if (!win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8523 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 8524 | + " pv=" + win.mPolicyVisibility |
| 8525 | + " dp=" + win.mDrawPending |
| 8526 | + " cdp=" + win.mCommitDrawPending |
| 8527 | + " ah=" + win.mAttachedHidden |
| 8528 | + " th=" |
| 8529 | + (win.mAppToken != null |
| 8530 | ? win.mAppToken.hiddenRequested : false) |
| 8531 | + " a=" + win.mAnimating); |
| 8532 | } |
| 8533 | } |
| 8534 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8535 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8536 | if (!win.isAnimating()) { |
| 8537 | numVisible++; |
| 8538 | } |
| 8539 | nowGone = false; |
| 8540 | } else if (win.isAnimating()) { |
| 8541 | nowGone = false; |
| 8542 | } |
| 8543 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8545 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 8546 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 8547 | + numInteresting + " visible=" + numVisible); |
| 8548 | if (nowVisible != reportedVisible) { |
| 8549 | if (DEBUG_VISIBILITY) Log.v( |
| 8550 | TAG, "Visibility changed in " + this |
| 8551 | + ": vis=" + nowVisible); |
| 8552 | reportedVisible = nowVisible; |
| 8553 | Message m = mH.obtainMessage( |
| 8554 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8555 | nowVisible ? 1 : 0, |
| 8556 | nowGone ? 1 : 0, |
| 8557 | this); |
| 8558 | mH.sendMessage(m); |
| 8559 | } |
| 8560 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8561 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8562 | WindowState findMainWindow() { |
| 8563 | int j = windows.size(); |
| 8564 | while (j > 0) { |
| 8565 | j--; |
| 8566 | WindowState win = windows.get(j); |
| 8567 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8568 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8569 | return win; |
| 8570 | } |
| 8571 | } |
| 8572 | return null; |
| 8573 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8575 | void dump(PrintWriter pw, String prefix) { |
| 8576 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8577 | if (appToken != null) { |
| 8578 | pw.print(prefix); pw.println("app=true"); |
| 8579 | } |
| 8580 | if (allAppWindows.size() > 0) { |
| 8581 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8582 | } |
| 8583 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8584 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8585 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8586 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8587 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8588 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8589 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8590 | if (paused || freezingScreen) { |
| 8591 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8592 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8593 | } |
| 8594 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8595 | || inPendingTransaction || allDrawn) { |
| 8596 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8597 | pw.print(numInterestingWindows); |
| 8598 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8599 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8600 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8601 | } |
| 8602 | if (animating || animation != null) { |
| 8603 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8604 | pw.print(" animation="); pw.println(animation); |
| 8605 | } |
| 8606 | if (animLayerAdjustment != 0) { |
| 8607 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8608 | } |
| 8609 | if (hasTransformation) { |
| 8610 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8611 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8612 | pw.println(); |
| 8613 | } |
| 8614 | if (startingData != null || removed || firstWindowDrawn) { |
| 8615 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8616 | pw.print(" removed="); pw.print(removed); |
| 8617 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8618 | } |
| 8619 | if (startingWindow != null || startingView != null |
| 8620 | || startingDisplayed || startingMoved) { |
| 8621 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8622 | pw.print(" startingView="); pw.print(startingView); |
| 8623 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8624 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8625 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8626 | } |
| 8627 | |
| 8628 | @Override |
| 8629 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8630 | if (stringName == null) { |
| 8631 | StringBuilder sb = new StringBuilder(); |
| 8632 | sb.append("AppWindowToken{"); |
| 8633 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8634 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8635 | stringName = sb.toString(); |
| 8636 | } |
| 8637 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | } |
| 8639 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8640 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8641 | // ------------------------------------------------------------- |
| 8642 | // DummyAnimation |
| 8643 | // ------------------------------------------------------------- |
| 8644 | |
| 8645 | // This is an animation that does nothing: it just immediately finishes |
| 8646 | // itself every time it is called. It is used as a stub animation in cases |
| 8647 | // where we want to synchronize multiple things that may be animating. |
| 8648 | static final class DummyAnimation extends Animation { |
| 8649 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8650 | return false; |
| 8651 | } |
| 8652 | } |
| 8653 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8655 | // ------------------------------------------------------------- |
| 8656 | // Async Handler |
| 8657 | // ------------------------------------------------------------- |
| 8658 | |
| 8659 | static final class StartingData { |
| 8660 | final String pkg; |
| 8661 | final int theme; |
| 8662 | final CharSequence nonLocalizedLabel; |
| 8663 | final int labelRes; |
| 8664 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8665 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8666 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8667 | int _labelRes, int _icon) { |
| 8668 | pkg = _pkg; |
| 8669 | theme = _theme; |
| 8670 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8671 | labelRes = _labelRes; |
| 8672 | icon = _icon; |
| 8673 | } |
| 8674 | } |
| 8675 | |
| 8676 | private final class H extends Handler { |
| 8677 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8678 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8679 | public static final int ANIMATE = 4; |
| 8680 | public static final int ADD_STARTING = 5; |
| 8681 | public static final int REMOVE_STARTING = 6; |
| 8682 | public static final int FINISHED_STARTING = 7; |
| 8683 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8684 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8685 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8686 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8687 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8688 | public static final int FORCE_GC = 15; |
| 8689 | public static final int ENABLE_SCREEN = 16; |
| 8690 | public static final int APP_FREEZE_TIMEOUT = 17; |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8691 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8693 | private Session mLastReportedHold; |
| 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 | public H() { |
| 8696 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8697 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8698 | @Override |
| 8699 | public void handleMessage(Message msg) { |
| 8700 | switch (msg.what) { |
| 8701 | case REPORT_FOCUS_CHANGE: { |
| 8702 | WindowState lastFocus; |
| 8703 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8704 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8705 | synchronized(mWindowMap) { |
| 8706 | lastFocus = mLastFocus; |
| 8707 | newFocus = mCurrentFocus; |
| 8708 | if (lastFocus == newFocus) { |
| 8709 | // Focus is not changing, so nothing to do. |
| 8710 | return; |
| 8711 | } |
| 8712 | mLastFocus = newFocus; |
| 8713 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 8714 | // + " to " + newFocus); |
| 8715 | if (newFocus != null && lastFocus != null |
| 8716 | && !newFocus.isDisplayedLw()) { |
| 8717 | //Log.i(TAG, "Delaying loss of focus..."); |
| 8718 | mLosingFocus.add(lastFocus); |
| 8719 | lastFocus = null; |
| 8720 | } |
| 8721 | } |
| 8722 | |
| 8723 | if (lastFocus != newFocus) { |
| 8724 | //System.out.println("Changing focus from " + lastFocus |
| 8725 | // + " to " + newFocus); |
| 8726 | if (newFocus != null) { |
| 8727 | try { |
| 8728 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 8729 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8730 | } catch (RemoteException e) { |
| 8731 | // Ignore if process has died. |
| 8732 | } |
| 8733 | } |
| 8734 | |
| 8735 | if (lastFocus != null) { |
| 8736 | try { |
| 8737 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 8738 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8739 | } catch (RemoteException e) { |
| 8740 | // Ignore if process has died. |
| 8741 | } |
| 8742 | } |
| 8743 | } |
| 8744 | } break; |
| 8745 | |
| 8746 | case REPORT_LOSING_FOCUS: { |
| 8747 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8749 | synchronized(mWindowMap) { |
| 8750 | losers = mLosingFocus; |
| 8751 | mLosingFocus = new ArrayList<WindowState>(); |
| 8752 | } |
| 8753 | |
| 8754 | final int N = losers.size(); |
| 8755 | for (int i=0; i<N; i++) { |
| 8756 | try { |
| 8757 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 8758 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8759 | } catch (RemoteException e) { |
| 8760 | // Ignore if process has died. |
| 8761 | } |
| 8762 | } |
| 8763 | } break; |
| 8764 | |
| 8765 | case ANIMATE: { |
| 8766 | synchronized(mWindowMap) { |
| 8767 | mAnimationPending = false; |
| 8768 | performLayoutAndPlaceSurfacesLocked(); |
| 8769 | } |
| 8770 | } break; |
| 8771 | |
| 8772 | case ADD_STARTING: { |
| 8773 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8774 | final StartingData sd = wtoken.startingData; |
| 8775 | |
| 8776 | if (sd == null) { |
| 8777 | // Animation has been canceled... do nothing. |
| 8778 | return; |
| 8779 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8781 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 8782 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8784 | View view = null; |
| 8785 | try { |
| 8786 | view = mPolicy.addStartingWindow( |
| 8787 | wtoken.token, sd.pkg, |
| 8788 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8789 | sd.icon); |
| 8790 | } catch (Exception e) { |
| 8791 | Log.w(TAG, "Exception when adding starting window", e); |
| 8792 | } |
| 8793 | |
| 8794 | if (view != null) { |
| 8795 | boolean abort = false; |
| 8796 | |
| 8797 | synchronized(mWindowMap) { |
| 8798 | if (wtoken.removed || wtoken.startingData == null) { |
| 8799 | // If the window was successfully added, then |
| 8800 | // we need to remove it. |
| 8801 | if (wtoken.startingWindow != null) { |
| 8802 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8803 | "Aborted starting " + wtoken |
| 8804 | + ": removed=" + wtoken.removed |
| 8805 | + " startingData=" + wtoken.startingData); |
| 8806 | wtoken.startingWindow = null; |
| 8807 | wtoken.startingData = null; |
| 8808 | abort = true; |
| 8809 | } |
| 8810 | } else { |
| 8811 | wtoken.startingView = view; |
| 8812 | } |
| 8813 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 8814 | "Added starting " + wtoken |
| 8815 | + ": startingWindow=" |
| 8816 | + wtoken.startingWindow + " startingView=" |
| 8817 | + wtoken.startingView); |
| 8818 | } |
| 8819 | |
| 8820 | if (abort) { |
| 8821 | try { |
| 8822 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8823 | } catch (Exception e) { |
| 8824 | Log.w(TAG, "Exception when removing starting window", e); |
| 8825 | } |
| 8826 | } |
| 8827 | } |
| 8828 | } break; |
| 8829 | |
| 8830 | case REMOVE_STARTING: { |
| 8831 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8832 | IBinder token = null; |
| 8833 | View view = null; |
| 8834 | synchronized (mWindowMap) { |
| 8835 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 8836 | + wtoken + ": startingWindow=" |
| 8837 | + wtoken.startingWindow + " startingView=" |
| 8838 | + wtoken.startingView); |
| 8839 | if (wtoken.startingWindow != null) { |
| 8840 | view = wtoken.startingView; |
| 8841 | token = wtoken.token; |
| 8842 | wtoken.startingData = null; |
| 8843 | wtoken.startingView = null; |
| 8844 | wtoken.startingWindow = null; |
| 8845 | } |
| 8846 | } |
| 8847 | if (view != null) { |
| 8848 | try { |
| 8849 | mPolicy.removeStartingWindow(token, view); |
| 8850 | } catch (Exception e) { |
| 8851 | Log.w(TAG, "Exception when removing starting window", e); |
| 8852 | } |
| 8853 | } |
| 8854 | } break; |
| 8855 | |
| 8856 | case FINISHED_STARTING: { |
| 8857 | IBinder token = null; |
| 8858 | View view = null; |
| 8859 | while (true) { |
| 8860 | synchronized (mWindowMap) { |
| 8861 | final int N = mFinishedStarting.size(); |
| 8862 | if (N <= 0) { |
| 8863 | break; |
| 8864 | } |
| 8865 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8866 | |
| 8867 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8868 | "Finished starting " + wtoken |
| 8869 | + ": startingWindow=" + wtoken.startingWindow |
| 8870 | + " startingView=" + wtoken.startingView); |
| 8871 | |
| 8872 | if (wtoken.startingWindow == null) { |
| 8873 | continue; |
| 8874 | } |
| 8875 | |
| 8876 | view = wtoken.startingView; |
| 8877 | token = wtoken.token; |
| 8878 | wtoken.startingData = null; |
| 8879 | wtoken.startingView = null; |
| 8880 | wtoken.startingWindow = null; |
| 8881 | } |
| 8882 | |
| 8883 | try { |
| 8884 | mPolicy.removeStartingWindow(token, view); |
| 8885 | } catch (Exception e) { |
| 8886 | Log.w(TAG, "Exception when removing starting window", e); |
| 8887 | } |
| 8888 | } |
| 8889 | } break; |
| 8890 | |
| 8891 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8892 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8893 | |
| 8894 | boolean nowVisible = msg.arg1 != 0; |
| 8895 | boolean nowGone = msg.arg2 != 0; |
| 8896 | |
| 8897 | try { |
| 8898 | if (DEBUG_VISIBILITY) Log.v( |
| 8899 | TAG, "Reporting visible in " + wtoken |
| 8900 | + " visible=" + nowVisible |
| 8901 | + " gone=" + nowGone); |
| 8902 | if (nowVisible) { |
| 8903 | wtoken.appToken.windowsVisible(); |
| 8904 | } else { |
| 8905 | wtoken.appToken.windowsGone(); |
| 8906 | } |
| 8907 | } catch (RemoteException ex) { |
| 8908 | } |
| 8909 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8911 | case WINDOW_FREEZE_TIMEOUT: { |
| 8912 | synchronized (mWindowMap) { |
| 8913 | Log.w(TAG, "Window freeze timeout expired."); |
| 8914 | int i = mWindows.size(); |
| 8915 | while (i > 0) { |
| 8916 | i--; |
| 8917 | WindowState w = (WindowState)mWindows.get(i); |
| 8918 | if (w.mOrientationChanging) { |
| 8919 | w.mOrientationChanging = false; |
| 8920 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 8921 | } |
| 8922 | } |
| 8923 | performLayoutAndPlaceSurfacesLocked(); |
| 8924 | } |
| 8925 | break; |
| 8926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | case HOLD_SCREEN_CHANGED: { |
| 8929 | Session oldHold; |
| 8930 | Session newHold; |
| 8931 | synchronized (mWindowMap) { |
| 8932 | oldHold = mLastReportedHold; |
| 8933 | newHold = (Session)msg.obj; |
| 8934 | mLastReportedHold = newHold; |
| 8935 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8936 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8937 | if (oldHold != newHold) { |
| 8938 | try { |
| 8939 | if (oldHold != null) { |
| 8940 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8941 | "window", |
| 8942 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8943 | } |
| 8944 | if (newHold != null) { |
| 8945 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8946 | "window", |
| 8947 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8948 | } |
| 8949 | } catch (RemoteException e) { |
| 8950 | } |
| 8951 | } |
| 8952 | break; |
| 8953 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8955 | case APP_TRANSITION_TIMEOUT: { |
| 8956 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8957 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8958 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8959 | "*** APP TRANSITION TIMEOUT"); |
| 8960 | mAppTransitionReady = true; |
| 8961 | mAppTransitionTimeout = true; |
| 8962 | performLayoutAndPlaceSurfacesLocked(); |
| 8963 | } |
| 8964 | } |
| 8965 | break; |
| 8966 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8967 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8968 | case PERSIST_ANIMATION_SCALE: { |
| 8969 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8970 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8971 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8972 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8973 | break; |
| 8974 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8976 | case FORCE_GC: { |
| 8977 | synchronized(mWindowMap) { |
| 8978 | if (mAnimationPending) { |
| 8979 | // If we are animating, don't do the gc now but |
| 8980 | // delay a bit so we don't interrupt the animation. |
| 8981 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8982 | 2000); |
| 8983 | return; |
| 8984 | } |
| 8985 | // If we are currently rotating the display, it will |
| 8986 | // schedule a new message when done. |
| 8987 | if (mDisplayFrozen) { |
| 8988 | return; |
| 8989 | } |
| 8990 | mFreezeGcPending = 0; |
| 8991 | } |
| 8992 | Runtime.getRuntime().gc(); |
| 8993 | break; |
| 8994 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8995 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8996 | case ENABLE_SCREEN: { |
| 8997 | performEnableScreen(); |
| 8998 | break; |
| 8999 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9001 | case APP_FREEZE_TIMEOUT: { |
| 9002 | synchronized (mWindowMap) { |
| 9003 | Log.w(TAG, "App freeze timeout expired."); |
| 9004 | int i = mAppTokens.size(); |
| 9005 | while (i > 0) { |
| 9006 | i--; |
| 9007 | AppWindowToken tok = mAppTokens.get(i); |
| 9008 | if (tok.freezingScreen) { |
| 9009 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 9010 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9011 | } |
| 9012 | } |
| 9013 | } |
| 9014 | break; |
| 9015 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9016 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9017 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 9018 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9019 | sendNewConfiguration(); |
| 9020 | } |
| 9021 | break; |
| 9022 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9023 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9024 | } |
| 9025 | } |
| 9026 | } |
| 9027 | |
| 9028 | // ------------------------------------------------------------- |
| 9029 | // IWindowManager API |
| 9030 | // ------------------------------------------------------------- |
| 9031 | |
| 9032 | public IWindowSession openSession(IInputMethodClient client, |
| 9033 | IInputContext inputContext) { |
| 9034 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9035 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 9036 | return new Session(client, inputContext); |
| 9037 | } |
| 9038 | |
| 9039 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9040 | synchronized (mWindowMap) { |
| 9041 | // The focus for the client is the window immediately below |
| 9042 | // where we would place the input method window. |
| 9043 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9044 | WindowState imFocus; |
| 9045 | if (idx > 0) { |
| 9046 | imFocus = (WindowState)mWindows.get(idx-1); |
| 9047 | if (imFocus != null) { |
| 9048 | if (imFocus.mSession.mClient != null && |
| 9049 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9050 | return true; |
| 9051 | } |
| 9052 | } |
| 9053 | } |
| 9054 | } |
| 9055 | return false; |
| 9056 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9057 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9058 | // ------------------------------------------------------------- |
| 9059 | // Internals |
| 9060 | // ------------------------------------------------------------- |
| 9061 | |
| 9062 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 9063 | return windowForClientLocked(session, client.asBinder()); |
| 9064 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9065 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9066 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 9067 | WindowState win = mWindowMap.get(client); |
| 9068 | if (localLOGV) Log.v( |
| 9069 | TAG, "Looking up client " + client + ": " + win); |
| 9070 | if (win == null) { |
| 9071 | RuntimeException ex = new RuntimeException(); |
| 9072 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 9073 | return null; |
| 9074 | } |
| 9075 | if (session != null && win.mSession != session) { |
| 9076 | RuntimeException ex = new RuntimeException(); |
| 9077 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 9078 | win.mSession + ", not " + session, ex); |
| 9079 | return null; |
| 9080 | } |
| 9081 | |
| 9082 | return win; |
| 9083 | } |
| 9084 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9085 | final void rebuildAppWindowListLocked() { |
| 9086 | int NW = mWindows.size(); |
| 9087 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9088 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9089 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9090 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9091 | // First remove all existing app windows. |
| 9092 | i=0; |
| 9093 | while (i < NW) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9094 | WindowState w = (WindowState)mWindows.get(i); |
| 9095 | if (w.mAppToken != null) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9096 | WindowState win = (WindowState)mWindows.remove(i); |
| 9097 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 9098 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9099 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9100 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9101 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9102 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9103 | && lastWallpaper == i-1) { |
| 9104 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9105 | } |
| 9106 | i++; |
| 9107 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9108 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9109 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9110 | // so skip them before adding app tokens. |
| 9111 | lastWallpaper++; |
| 9112 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9113 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9114 | // First add all of the exiting app tokens... these are no longer |
| 9115 | // in the main app list, but still have windows shown. We put them |
| 9116 | // in the back because now that the animation is over we no longer |
| 9117 | // will care about them. |
| 9118 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9119 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9120 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9121 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9122 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9123 | // And add in the still active app tokens in Z order. |
| 9124 | NT = mAppTokens.size(); |
| 9125 | for (int j=0; j<NT; j++) { |
| 9126 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9127 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9128 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9129 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9130 | if (i != numRemoved) { |
| 9131 | Log.w(TAG, "Rebuild removed " + numRemoved |
| 9132 | + " windows but added " + i); |
| 9133 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9134 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9135 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9136 | private final void assignLayersLocked() { |
| 9137 | int N = mWindows.size(); |
| 9138 | int curBaseLayer = 0; |
| 9139 | int curLayer = 0; |
| 9140 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9141 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9142 | for (i=0; i<N; i++) { |
| 9143 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9144 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9145 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9146 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9147 | w.mLayer = curLayer; |
| 9148 | } else { |
| 9149 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9150 | w.mLayer = curLayer; |
| 9151 | } |
| 9152 | if (w.mTargetAppToken != null) { |
| 9153 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9154 | } else if (w.mAppToken != null) { |
| 9155 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9156 | } else { |
| 9157 | w.mAnimLayer = w.mLayer; |
| 9158 | } |
| 9159 | if (w.mIsImWindow) { |
| 9160 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9161 | } else if (w.mIsWallpaper) { |
| 9162 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9163 | } |
| 9164 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 9165 | + w.mAnimLayer); |
| 9166 | //System.out.println( |
| 9167 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9168 | } |
| 9169 | } |
| 9170 | |
| 9171 | private boolean mInLayout = false; |
| 9172 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9173 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9174 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9175 | throw new RuntimeException("Recursive call!"); |
| 9176 | } |
| 9177 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 9178 | return; |
| 9179 | } |
| 9180 | |
| 9181 | boolean recoveringMemory = false; |
| 9182 | if (mForceRemoves != null) { |
| 9183 | recoveringMemory = true; |
| 9184 | // Wait a little it for things to settle down, and off we go. |
| 9185 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9186 | WindowState ws = mForceRemoves.get(i); |
| 9187 | Log.i(TAG, "Force removing: " + ws); |
| 9188 | removeWindowInnerLocked(ws.mSession, ws); |
| 9189 | } |
| 9190 | mForceRemoves = null; |
| 9191 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 9192 | Object tmp = new Object(); |
| 9193 | synchronized (tmp) { |
| 9194 | try { |
| 9195 | tmp.wait(250); |
| 9196 | } catch (InterruptedException e) { |
| 9197 | } |
| 9198 | } |
| 9199 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9200 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9201 | mInLayout = true; |
| 9202 | try { |
| 9203 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9205 | int i = mPendingRemove.size()-1; |
| 9206 | if (i >= 0) { |
| 9207 | while (i >= 0) { |
| 9208 | WindowState w = mPendingRemove.get(i); |
| 9209 | removeWindowInnerLocked(w.mSession, w); |
| 9210 | i--; |
| 9211 | } |
| 9212 | mPendingRemove.clear(); |
| 9213 | |
| 9214 | mInLayout = false; |
| 9215 | assignLayersLocked(); |
| 9216 | mLayoutNeeded = true; |
| 9217 | performLayoutAndPlaceSurfacesLocked(); |
| 9218 | |
| 9219 | } else { |
| 9220 | mInLayout = false; |
| 9221 | if (mLayoutNeeded) { |
| 9222 | requestAnimationLocked(0); |
| 9223 | } |
| 9224 | } |
| 9225 | } catch (RuntimeException e) { |
| 9226 | mInLayout = false; |
| 9227 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 9228 | } |
| 9229 | } |
| 9230 | |
| 9231 | private final void performLayoutLockedInner() { |
| 9232 | final int dw = mDisplay.getWidth(); |
| 9233 | final int dh = mDisplay.getHeight(); |
| 9234 | |
| 9235 | final int N = mWindows.size(); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9236 | int repeats = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9237 | int i; |
| 9238 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9239 | if (DEBUG_LAYOUT) Log.v(TAG, "performLayout: needed=" |
| 9240 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9242 | // FIRST LOOP: Perform a layout, if needed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9243 | |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9244 | while (mLayoutNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9245 | mPolicy.beginLayoutLw(dw, dh); |
| 9246 | |
| 9247 | // First perform layout of any root windows (not attached |
| 9248 | // to another window). |
| 9249 | int topAttached = -1; |
| 9250 | for (i = N-1; i >= 0; i--) { |
| 9251 | WindowState win = (WindowState) mWindows.get(i); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9252 | |
| 9253 | // Don't do layout of a window if it is not visible, or |
| 9254 | // soon won't be visible, to avoid wasting time and funky |
| 9255 | // changes while a window is animating away. |
| 9256 | final AppWindowToken atoken = win.mAppToken; |
| 9257 | final boolean gone = win.mViewVisibility == View.GONE |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9258 | || !win.mRelayoutCalled |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9259 | || win.mRootToken.hidden |
| 9260 | || (atoken != null && atoken.hiddenRequested) |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9261 | || win.mAttachedHidden |
| 9262 | || win.mExiting || win.mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9263 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9264 | if (win.mLayoutAttached) { |
| 9265 | if (DEBUG_LAYOUT) Log.v(TAG, "First pass " + win |
| 9266 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9267 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9268 | if (DEBUG_LAYOUT && gone) Log.v(TAG, " (mViewVisibility=" |
| 9269 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9270 | + win.mRelayoutCalled + " hidden=" |
| 9271 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9272 | + (atoken != null && atoken.hiddenRequested) |
| 9273 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9274 | } |
| 9275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9276 | // If this view is GONE, then skip it -- keep the current |
| 9277 | // frame, and let the caller know so they can ignore it |
| 9278 | // if they want. (We do the normal layout for INVISIBLE |
| 9279 | // windows, since that means "perform layout as normal, |
| 9280 | // just don't display"). |
| 9281 | if (!gone || !win.mHaveFrame) { |
| 9282 | if (!win.mLayoutAttached) { |
| 9283 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9284 | if (DEBUG_LAYOUT) Log.v(TAG, "-> mFrame=" |
| 9285 | + win.mFrame + " mContainingFrame=" |
| 9286 | + win.mContainingFrame + " mDisplayFrame=" |
| 9287 | + win.mDisplayFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9288 | } else { |
| 9289 | if (topAttached < 0) topAttached = i; |
| 9290 | } |
| 9291 | } |
| 9292 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9294 | // Now perform layout of attached windows, which usually |
| 9295 | // depend on the position of the window they are attached to. |
| 9296 | // XXX does not deal with windows that are attached to windows |
| 9297 | // that are themselves attached. |
| 9298 | for (i = topAttached; i >= 0; i--) { |
| 9299 | WindowState win = (WindowState) mWindows.get(i); |
| 9300 | |
| 9301 | // If this view is GONE, then skip it -- keep the current |
| 9302 | // frame, and let the caller know so they can ignore it |
| 9303 | // if they want. (We do the normal layout for INVISIBLE |
| 9304 | // windows, since that means "perform layout as normal, |
| 9305 | // just don't display"). |
| 9306 | if (win.mLayoutAttached) { |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9307 | if (DEBUG_LAYOUT) Log.v(TAG, "Second pass " + win |
| 9308 | + " mHaveFrame=" + win.mHaveFrame |
| 9309 | + " mViewVisibility=" + win.mViewVisibility |
| 9310 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9311 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9312 | || !win.mHaveFrame) { |
| 9313 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9314 | if (DEBUG_LAYOUT) Log.v(TAG, "-> mFrame=" |
| 9315 | + win.mFrame + " mContainingFrame=" |
| 9316 | + win.mContainingFrame + " mDisplayFrame=" |
| 9317 | + win.mDisplayFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9318 | } |
| 9319 | } |
| 9320 | } |
| 9321 | |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9322 | int changes = mPolicy.finishLayoutLw(); |
| 9323 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9324 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9325 | assignLayersLocked(); |
| 9326 | } |
| 9327 | } |
| 9328 | if (changes == 0) { |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9329 | mLayoutNeeded = false; |
| 9330 | } else if (repeats > 2) { |
| 9331 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 9332 | mLayoutNeeded = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9333 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9334 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9335 | null, null); |
| 9336 | if (newConfig != null) { |
| 9337 | mLayoutNeeded = true; |
| 9338 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9339 | } |
| 9340 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9341 | } else { |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9342 | if (DEBUG_LAYOUT) Log.v(TAG, "Repeating layout because changes=0x" |
| 9343 | + Integer.toHexString(changes)); |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9344 | repeats++; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9345 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9346 | if (DEBUG_LAYOUT) Log.v(TAG, "Computing new config from layout"); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9347 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9348 | null, null); |
| 9349 | if (newConfig != null) { |
| 9350 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9351 | } |
| 9352 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9353 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9354 | } |
| 9355 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9356 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9357 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9358 | boolean recoveringMemory) { |
| 9359 | final long currentTime = SystemClock.uptimeMillis(); |
| 9360 | final int dw = mDisplay.getWidth(); |
| 9361 | final int dh = mDisplay.getHeight(); |
| 9362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9363 | int i; |
| 9364 | |
| 9365 | // FIRST LOOP: Perform a layout, if needed. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9366 | performLayoutLockedInner(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9367 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9368 | if (mFxSession == null) { |
| 9369 | mFxSession = new SurfaceSession(); |
| 9370 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9371 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9372 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 9373 | |
| 9374 | // Initialize state of exiting tokens. |
| 9375 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9376 | mExitingTokens.get(i).hasVisible = false; |
| 9377 | } |
| 9378 | |
| 9379 | // Initialize state of exiting applications. |
| 9380 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9381 | mExitingAppTokens.get(i).hasVisible = false; |
| 9382 | } |
| 9383 | |
| 9384 | // SECOND LOOP: Execute animations and update visibility of windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9385 | boolean orientationChangeComplete = true; |
| 9386 | Session holdScreen = null; |
| 9387 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9388 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9389 | boolean focusDisplayed = false; |
| 9390 | boolean animating = false; |
| 9391 | |
| 9392 | Surface.openTransaction(); |
| 9393 | try { |
| 9394 | boolean restart; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9395 | boolean forceHiding = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9396 | boolean wallpaperForceHidingChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9397 | |
| 9398 | do { |
| 9399 | final int transactionSequence = ++mTransactionSequence; |
| 9400 | |
| 9401 | // Update animations of all applications, including those |
| 9402 | // associated with exiting/removed apps |
| 9403 | boolean tokensAnimating = false; |
| 9404 | final int NAT = mAppTokens.size(); |
| 9405 | for (i=0; i<NAT; i++) { |
| 9406 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9407 | tokensAnimating = true; |
| 9408 | } |
| 9409 | } |
| 9410 | final int NEAT = mExitingAppTokens.size(); |
| 9411 | for (i=0; i<NEAT; i++) { |
| 9412 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9413 | tokensAnimating = true; |
| 9414 | } |
| 9415 | } |
| 9416 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9417 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "*** ANIM STEP: seq=" |
| 9418 | + transactionSequence + " tokensAnimating=" |
| 9419 | + tokensAnimating); |
| 9420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9421 | animating = tokensAnimating; |
| 9422 | restart = false; |
| 9423 | |
| 9424 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9425 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9426 | boolean focusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9427 | |
| 9428 | mPolicy.beginAnimationLw(dw, dh); |
| 9429 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9430 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9432 | for (i=N-1; i>=0; i--) { |
| 9433 | WindowState w = (WindowState)mWindows.get(i); |
| 9434 | |
| 9435 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9436 | |
| 9437 | if (w.mSurface != null) { |
| 9438 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9439 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9440 | if ((w.mAttrs.flags |
| 9441 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9442 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9443 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9444 | wallpaperMayChange = true; |
| 9445 | } |
| 9446 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9447 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9448 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9449 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9450 | animating = true; |
| 9451 | //w.dump(" "); |
| 9452 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9453 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9454 | wallpaperMayChange = true; |
| 9455 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9456 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9457 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9458 | if (!wasAnimating && animating) { |
| 9459 | wallpaperForceHidingChanged = true; |
| 9460 | focusMayChange = true; |
| 9461 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9462 | forceHiding = true; |
| 9463 | } |
| 9464 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9465 | boolean changed; |
| 9466 | if (forceHiding) { |
| 9467 | changed = w.hideLw(false, false); |
| 9468 | } else { |
| 9469 | changed = w.showLw(false, false); |
| 9470 | if (changed && wallpaperForceHidingChanged |
| 9471 | && w.isReadyForDisplay()) { |
| 9472 | // Assume we will need to animate. If |
| 9473 | // we don't (because the wallpaper will |
| 9474 | // stay with the lock screen), then we will |
| 9475 | // clean up later. |
| 9476 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9477 | if (a != null) { |
| 9478 | w.setAnimation(a); |
| 9479 | } |
| 9480 | } |
| 9481 | } |
| 9482 | if (changed && (attrs.flags |
| 9483 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9484 | wallpaperMayChange = true; |
| 9485 | } |
| 9486 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9487 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9488 | mPolicy.animatingWindowLw(w, attrs); |
| 9489 | } |
| 9490 | |
| 9491 | final AppWindowToken atoken = w.mAppToken; |
| 9492 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9493 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9494 | atoken.lastTransactionSequence = transactionSequence; |
| 9495 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9496 | atoken.startingDisplayed = false; |
| 9497 | } |
| 9498 | if ((w.isOnScreen() || w.mAttrs.type |
| 9499 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9500 | && !w.mExiting && !w.mDestroying) { |
| 9501 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9502 | Log.v(TAG, "Eval win " + w + ": isDrawn=" |
| 9503 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9504 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9505 | if (!w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9506 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 9507 | + " pv=" + w.mPolicyVisibility |
| 9508 | + " dp=" + w.mDrawPending |
| 9509 | + " cdp=" + w.mCommitDrawPending |
| 9510 | + " ah=" + w.mAttachedHidden |
| 9511 | + " th=" + atoken.hiddenRequested |
| 9512 | + " a=" + w.mAnimating); |
| 9513 | } |
| 9514 | } |
| 9515 | if (w != atoken.startingWindow) { |
| 9516 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9517 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9518 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9519 | atoken.numDrawnWindows++; |
| 9520 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 9521 | "tokenMayBeDrawn: " + atoken |
| 9522 | + " freezingScreen=" + atoken.freezingScreen |
| 9523 | + " mAppFreezing=" + w.mAppFreezing); |
| 9524 | tokenMayBeDrawn = true; |
| 9525 | } |
| 9526 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9527 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9528 | atoken.startingDisplayed = true; |
| 9529 | } |
| 9530 | } |
| 9531 | } else if (w.mReadyToShow) { |
| 9532 | w.performShowLocked(); |
| 9533 | } |
| 9534 | } |
| 9535 | |
| 9536 | if (mPolicy.finishAnimationLw()) { |
| 9537 | restart = true; |
| 9538 | } |
| 9539 | |
| 9540 | if (tokenMayBeDrawn) { |
| 9541 | // See if any windows have been drawn, so they (and others |
| 9542 | // associated with them) can now be shown. |
| 9543 | final int NT = mTokenList.size(); |
| 9544 | for (i=0; i<NT; i++) { |
| 9545 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9546 | if (wtoken == null) { |
| 9547 | continue; |
| 9548 | } |
| 9549 | if (wtoken.freezingScreen) { |
| 9550 | int numInteresting = wtoken.numInterestingWindows; |
| 9551 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9552 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9553 | "allDrawn: " + wtoken |
| 9554 | + " interesting=" + numInteresting |
| 9555 | + " drawn=" + wtoken.numDrawnWindows); |
| 9556 | wtoken.showAllWindowsLocked(); |
| 9557 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9558 | orientationChangeComplete = true; |
| 9559 | } |
| 9560 | } else if (!wtoken.allDrawn) { |
| 9561 | int numInteresting = wtoken.numInterestingWindows; |
| 9562 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9563 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9564 | "allDrawn: " + wtoken |
| 9565 | + " interesting=" + numInteresting |
| 9566 | + " drawn=" + wtoken.numDrawnWindows); |
| 9567 | wtoken.allDrawn = true; |
| 9568 | restart = true; |
| 9569 | |
| 9570 | // We can now show all of the drawn windows! |
| 9571 | if (!mOpeningApps.contains(wtoken)) { |
| 9572 | wtoken.showAllWindowsLocked(); |
| 9573 | } |
| 9574 | } |
| 9575 | } |
| 9576 | } |
| 9577 | } |
| 9578 | |
| 9579 | // If we are ready to perform an app transition, check through |
| 9580 | // all of the app tokens to be shown and see if they are ready |
| 9581 | // to go. |
| 9582 | if (mAppTransitionReady) { |
| 9583 | int NN = mOpeningApps.size(); |
| 9584 | boolean goodToGo = true; |
| 9585 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9586 | "Checking " + NN + " opening apps (frozen=" |
| 9587 | + mDisplayFrozen + " timeout=" |
| 9588 | + mAppTransitionTimeout + ")..."); |
| 9589 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9590 | // If the display isn't frozen, wait to do anything until |
| 9591 | // all of the apps are ready. Otherwise just go because |
| 9592 | // we'll unfreeze the display when everyone is ready. |
| 9593 | for (i=0; i<NN && goodToGo; i++) { |
| 9594 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9595 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9596 | "Check opening app" + wtoken + ": allDrawn=" |
| 9597 | + wtoken.allDrawn + " startingDisplayed=" |
| 9598 | + wtoken.startingDisplayed); |
| 9599 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9600 | && !wtoken.startingMoved) { |
| 9601 | goodToGo = false; |
| 9602 | } |
| 9603 | } |
| 9604 | } |
| 9605 | if (goodToGo) { |
| 9606 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 9607 | int transit = mNextAppTransition; |
| 9608 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9609 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9610 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9611 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9612 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9613 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9614 | mAppTransitionTimeout = false; |
| 9615 | mStartingIconInTransition = false; |
| 9616 | mSkipAppTransitionAnimation = false; |
| 9617 | |
| 9618 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9619 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9620 | // If there are applications waiting to come to the |
| 9621 | // top of the stack, now is the time to move their windows. |
| 9622 | // (Note that we don't do apps going to the bottom |
| 9623 | // here -- we want to keep their windows in the old |
| 9624 | // Z-order until the animation completes.) |
| 9625 | if (mToTopApps.size() > 0) { |
| 9626 | NN = mAppTokens.size(); |
| 9627 | for (i=0; i<NN; i++) { |
| 9628 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9629 | if (wtoken.sendingToTop) { |
| 9630 | wtoken.sendingToTop = false; |
| 9631 | moveAppWindowsLocked(wtoken, NN, false); |
| 9632 | } |
| 9633 | } |
| 9634 | mToTopApps.clear(); |
| 9635 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9636 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9637 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9638 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9639 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9640 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9641 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9642 | // The top-most window will supply the layout params, |
| 9643 | // and we will determine it below. |
| 9644 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9645 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9646 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9647 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9648 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9649 | "New wallpaper target=" + mWallpaperTarget |
| 9650 | + ", lower target=" + mLowerWallpaperTarget |
| 9651 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9652 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9653 | // Do a first pass through the tokens for two |
| 9654 | // things: |
| 9655 | // (1) Determine if both the closing and opening |
| 9656 | // app token sets are wallpaper targets, in which |
| 9657 | // case special animations are needed |
| 9658 | // (since the wallpaper needs to stay static |
| 9659 | // behind them). |
| 9660 | // (2) Find the layout params of the top-most |
| 9661 | // application window in the tokens, which is |
| 9662 | // what will control the animation theme. |
| 9663 | final int NC = mClosingApps.size(); |
| 9664 | NN = NC + mOpeningApps.size(); |
| 9665 | for (i=0; i<NN; i++) { |
| 9666 | AppWindowToken wtoken; |
| 9667 | int mode; |
| 9668 | if (i < NC) { |
| 9669 | wtoken = mClosingApps.get(i); |
| 9670 | mode = 1; |
| 9671 | } else { |
| 9672 | wtoken = mOpeningApps.get(i-NC); |
| 9673 | mode = 2; |
| 9674 | } |
| 9675 | if (mLowerWallpaperTarget != null) { |
| 9676 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9677 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9678 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9679 | } |
| 9680 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9681 | if (wtoken.appFullscreen) { |
| 9682 | WindowState ws = wtoken.findMainWindow(); |
| 9683 | if (ws != null) { |
| 9684 | // If this is a compatibility mode |
| 9685 | // window, we will always use its anim. |
| 9686 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9687 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9688 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9689 | bestAnimLayer = Integer.MAX_VALUE; |
| 9690 | } else if (ws.mLayer > bestAnimLayer) { |
| 9691 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9692 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9693 | bestAnimLayer = ws.mLayer; |
| 9694 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9695 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9696 | } |
| 9697 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9698 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9699 | if (foundWallpapers == 3) { |
| 9700 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9701 | "Wallpaper animation!"); |
| 9702 | switch (transit) { |
| 9703 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9704 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9705 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9706 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9707 | break; |
| 9708 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9709 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9710 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9711 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9712 | break; |
| 9713 | } |
| 9714 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9715 | "New transit: " + transit); |
| 9716 | } else if (oldWallpaper != null) { |
| 9717 | // We are transitioning from an activity with |
| 9718 | // a wallpaper to one without. |
| 9719 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| 9720 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9721 | "New transit away from wallpaper: " + transit); |
| 9722 | } else if (mWallpaperTarget != null) { |
| 9723 | // We are transitioning from an activity without |
| 9724 | // a wallpaper to now showing the wallpaper |
| 9725 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| 9726 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9727 | "New transit into wallpaper: " + transit); |
| 9728 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9729 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9730 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9731 | mLastEnterAnimToken = animToken; |
| 9732 | mLastEnterAnimParams = animLp; |
| 9733 | } else if (mLastEnterAnimParams != null) { |
| 9734 | animLp = mLastEnterAnimParams; |
| 9735 | mLastEnterAnimToken = null; |
| 9736 | mLastEnterAnimParams = null; |
| 9737 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9738 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9739 | // If all closing windows are obscured, then there is |
| 9740 | // no need to do an animation. This is the case, for |
| 9741 | // example, when this transition is being done behind |
| 9742 | // the lock screen. |
| 9743 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9744 | animLp = null; |
| 9745 | } |
| 9746 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9747 | NN = mOpeningApps.size(); |
| 9748 | for (i=0; i<NN; i++) { |
| 9749 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9750 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9751 | "Now opening app" + wtoken); |
| 9752 | wtoken.reportedVisible = false; |
| 9753 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9754 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9755 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9756 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9757 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9758 | wtoken.showAllWindowsLocked(); |
| 9759 | } |
| 9760 | NN = mClosingApps.size(); |
| 9761 | for (i=0; i<NN; i++) { |
| 9762 | AppWindowToken wtoken = mClosingApps.get(i); |
| 9763 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9764 | "Now closing app" + wtoken); |
| 9765 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9766 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9767 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9768 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9769 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9770 | // Force the allDrawn flag, because we want to start |
| 9771 | // this guy's animations regardless of whether it's |
| 9772 | // gotten drawn. |
| 9773 | wtoken.allDrawn = true; |
| 9774 | } |
| 9775 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9776 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9777 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9778 | mOpeningApps.clear(); |
| 9779 | mClosingApps.clear(); |
| 9780 | |
| 9781 | // This has changed the visibility of windows, so perform |
| 9782 | // a new layout to get them all up-to-date. |
| 9783 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9784 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9785 | assignLayersLocked(); |
| 9786 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9787 | performLayoutLockedInner(); |
| 9788 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9789 | focusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9790 | |
| 9791 | restart = true; |
| 9792 | } |
| 9793 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9794 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9795 | if (!animating && mAppTransitionRunning) { |
| 9796 | // We have finished the animation of an app transition. To do |
| 9797 | // this, we have delayed a lot of operations like showing and |
| 9798 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9799 | // reflects the correct Z-order, but the window list may now |
| 9800 | // be out of sync with it. So here we will just rebuild the |
| 9801 | // entire app window list. Fun! |
| 9802 | mAppTransitionRunning = false; |
| 9803 | // Clear information about apps that were moving. |
| 9804 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9805 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9806 | rebuildAppWindowListLocked(); |
| 9807 | restart = true; |
| 9808 | moveInputMethodWindowsIfNeededLocked(false); |
| 9809 | wallpaperMayChange = true; |
| 9810 | mLayoutNeeded = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9811 | // Since the window list has been rebuilt, focus might |
| 9812 | // have to be recomputed since the actual order of windows |
| 9813 | // might have changed again. |
| 9814 | focusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9815 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9816 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9817 | int adjResult = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9818 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9819 | if (wallpaperForceHidingChanged && !restart && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9820 | // At this point, there was a window with a wallpaper that |
| 9821 | // was force hiding other windows behind it, but now it |
| 9822 | // is going away. This may be simple -- just animate |
| 9823 | // away the wallpaper and its window -- or it may be |
| 9824 | // hard -- the wallpaper now needs to be shown behind |
| 9825 | // something that was hidden. |
| 9826 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9827 | if (mLowerWallpaperTarget != null |
| 9828 | && mLowerWallpaperTarget.mAppToken != null) { |
| 9829 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9830 | "wallpaperForceHiding changed with lower=" |
| 9831 | + mLowerWallpaperTarget); |
| 9832 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9833 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9834 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9835 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9836 | // The lower target has become hidden before we |
| 9837 | // actually started the animation... let's completely |
| 9838 | // re-evaluate everything. |
| 9839 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| 9840 | restart = true; |
| 9841 | } |
| 9842 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9843 | adjResult = adjustWallpaperWindowsLocked(); |
| 9844 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9845 | wallpaperForceHidingChanged = false; |
| 9846 | if (DEBUG_WALLPAPER) Log.v(TAG, "****** OLD: " + oldWallpaper |
| 9847 | + " NEW: " + mWallpaperTarget |
| 9848 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9849 | if (mLowerWallpaperTarget == null) { |
| 9850 | // Whoops, we don't need a special wallpaper animation. |
| 9851 | // Clear them out. |
| 9852 | forceHiding = false; |
| 9853 | for (i=N-1; i>=0; i--) { |
| 9854 | WindowState w = (WindowState)mWindows.get(i); |
| 9855 | if (w.mSurface != null) { |
| 9856 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9857 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| 9858 | if (DEBUG_FOCUS) Log.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9859 | forceHiding = true; |
| 9860 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9861 | if (!w.mAnimating) { |
| 9862 | // We set the animation above so it |
| 9863 | // is not yet running. |
| 9864 | w.clearAnimation(); |
| 9865 | } |
| 9866 | } |
| 9867 | } |
| 9868 | } |
| 9869 | } |
| 9870 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9871 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9872 | if (wallpaperMayChange) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9873 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9874 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9875 | adjResult = adjustWallpaperWindowsLocked(); |
| 9876 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9877 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9878 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9879 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9880 | "Wallpaper layer changed: assigning layers + relayout"); |
| 9881 | restart = true; |
| 9882 | mLayoutNeeded = true; |
| 9883 | assignLayersLocked(); |
| 9884 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| 9885 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9886 | "Wallpaper visibility changed: relayout"); |
| 9887 | restart = true; |
| 9888 | mLayoutNeeded = true; |
| 9889 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9890 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9891 | if (focusMayChange) { |
| 9892 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9893 | restart = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9894 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9895 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9896 | } |
| 9897 | |
| 9898 | if (mLayoutNeeded) { |
| 9899 | restart = true; |
| 9900 | performLayoutLockedInner(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9901 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9902 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9903 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "*** ANIM STEP: restart=" |
| 9904 | + restart); |
| 9905 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9906 | } while (restart); |
| 9907 | |
| 9908 | // THIRD LOOP: Update the surfaces of all windows. |
| 9909 | |
| 9910 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9911 | |
| 9912 | boolean obscured = false; |
| 9913 | boolean blurring = false; |
| 9914 | boolean dimming = false; |
| 9915 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9916 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9917 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9918 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9919 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9920 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9921 | for (i=N-1; i>=0; i--) { |
| 9922 | WindowState w = (WindowState)mWindows.get(i); |
| 9923 | |
| 9924 | boolean displayed = false; |
| 9925 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9926 | final int attrFlags = attrs.flags; |
| 9927 | |
| 9928 | if (w.mSurface != null) { |
| 9929 | w.computeShownFrameLocked(); |
| 9930 | if (localLOGV) Log.v( |
| 9931 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9932 | + ": new=" + w.mShownFrame + ", old=" |
| 9933 | + w.mLastShownFrame); |
| 9934 | |
| 9935 | boolean resize; |
| 9936 | int width, height; |
| 9937 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9938 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9939 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9940 | // for a scaled surface, we just want to use |
| 9941 | // the requested size. |
| 9942 | width = w.mRequestedWidth; |
| 9943 | height = w.mRequestedHeight; |
| 9944 | w.mLastRequestedWidth = width; |
| 9945 | w.mLastRequestedHeight = height; |
| 9946 | w.mLastShownFrame.set(w.mShownFrame); |
| 9947 | try { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9948 | if (SHOW_TRANSACTIONS) Log.i( |
| 9949 | TAG, " SURFACE " + w.mSurface |
| 9950 | + ": POS " + w.mShownFrame.left |
| 9951 | + ", " + w.mShownFrame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9952 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9953 | } catch (RuntimeException e) { |
| 9954 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 9955 | if (!recoveringMemory) { |
| 9956 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9957 | } |
| 9958 | } |
| 9959 | } else { |
| 9960 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9961 | width = w.mShownFrame.width(); |
| 9962 | height = w.mShownFrame.height(); |
| 9963 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9964 | } |
| 9965 | |
| 9966 | if (resize) { |
| 9967 | if (width < 1) width = 1; |
| 9968 | if (height < 1) height = 1; |
| 9969 | if (w.mSurface != null) { |
| 9970 | try { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9971 | if (SHOW_TRANSACTIONS) Log.i( |
| 9972 | TAG, " SURFACE " + w.mSurface + ": POS " |
| 9973 | + w.mShownFrame.left + "," |
| 9974 | + w.mShownFrame.top + " SIZE " |
| 9975 | + w.mShownFrame.width() + "x" |
| 9976 | + w.mShownFrame.height()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9977 | w.mSurface.setSize(width, height); |
| 9978 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9979 | w.mShownFrame.top); |
| 9980 | } catch (RuntimeException e) { |
| 9981 | // If something goes wrong with the surface (such |
| 9982 | // as running out of memory), don't take down the |
| 9983 | // entire system. |
| 9984 | Log.e(TAG, "Failure updating surface of " + w |
| 9985 | + "size=(" + width + "x" + height |
| 9986 | + "), pos=(" + w.mShownFrame.left |
| 9987 | + "," + w.mShownFrame.top + ")", e); |
| 9988 | if (!recoveringMemory) { |
| 9989 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9990 | } |
| 9991 | } |
| 9992 | } |
| 9993 | } |
| 9994 | if (!w.mAppFreezing) { |
| 9995 | w.mContentInsetsChanged = |
| 9996 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9997 | w.mVisibleInsetsChanged = |
| 9998 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9999 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10000 | || w.mContentInsetsChanged |
| 10001 | || w.mVisibleInsetsChanged) { |
| 10002 | w.mLastFrame.set(w.mFrame); |
| 10003 | w.mLastContentInsets.set(w.mContentInsets); |
| 10004 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10005 | // If the screen is currently frozen, then keep |
| 10006 | // it frozen until this window draws at its new |
| 10007 | // orientation. |
| 10008 | if (mDisplayFrozen) { |
| 10009 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10010 | "Resizing while display frozen: " + w); |
| 10011 | w.mOrientationChanging = true; |
| 10012 | if (mWindowsFreezingScreen) { |
| 10013 | mWindowsFreezingScreen = true; |
| 10014 | // XXX should probably keep timeout from |
| 10015 | // when we first froze the display. |
| 10016 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10017 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10018 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10019 | } |
| 10020 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10021 | // If the orientation is changing, then we need to |
| 10022 | // hold off on unfreezing the display until this |
| 10023 | // window has been redrawn; to do that, we need |
| 10024 | // to go through the process of getting informed |
| 10025 | // by the application when it has finished drawing. |
| 10026 | if (w.mOrientationChanging) { |
| 10027 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10028 | "Orientation start waiting for draw in " |
| 10029 | + w + ", surface " + w.mSurface); |
| 10030 | w.mDrawPending = true; |
| 10031 | w.mCommitDrawPending = false; |
| 10032 | w.mReadyToShow = false; |
| 10033 | if (w.mAppToken != null) { |
| 10034 | w.mAppToken.allDrawn = false; |
| 10035 | } |
| 10036 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10037 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10038 | "Resizing window " + w + " to " + w.mFrame); |
| 10039 | mResizingWindows.add(w); |
| 10040 | } else if (w.mOrientationChanging) { |
| 10041 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 10042 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10043 | "Orientation not waiting for draw in " |
| 10044 | + w + ", surface " + w.mSurface); |
| 10045 | w.mOrientationChanging = false; |
| 10046 | } |
| 10047 | } |
| 10048 | } |
| 10049 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10050 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10051 | if (!w.mLastHidden) { |
| 10052 | //dump(); |
| 10053 | w.mLastHidden = true; |
| 10054 | if (SHOW_TRANSACTIONS) Log.i( |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10055 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout)"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10056 | if (w.mSurface != null) { |
| 10057 | try { |
| 10058 | w.mSurface.hide(); |
| 10059 | } catch (RuntimeException e) { |
| 10060 | Log.w(TAG, "Exception hiding surface in " + w); |
| 10061 | } |
| 10062 | } |
| 10063 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 10064 | } |
| 10065 | // If we are waiting for this window to handle an |
| 10066 | // orientation change, well, it is hidden, so |
| 10067 | // doesn't really matter. Note that this does |
| 10068 | // introduce a potential glitch if the window |
| 10069 | // becomes unhidden before it has drawn for the |
| 10070 | // new orientation. |
| 10071 | if (w.mOrientationChanging) { |
| 10072 | w.mOrientationChanging = false; |
| 10073 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10074 | "Orientation change skips hidden " + w); |
| 10075 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10076 | } else if (w.mLastLayer != w.mAnimLayer |
| 10077 | || w.mLastAlpha != w.mShownAlpha |
| 10078 | || w.mLastDsDx != w.mDsDx |
| 10079 | || w.mLastDtDx != w.mDtDx |
| 10080 | || w.mLastDsDy != w.mDsDy |
| 10081 | || w.mLastDtDy != w.mDtDy |
| 10082 | || w.mLastHScale != w.mHScale |
| 10083 | || w.mLastVScale != w.mVScale |
| 10084 | || w.mLastHidden) { |
| 10085 | displayed = true; |
| 10086 | w.mLastAlpha = w.mShownAlpha; |
| 10087 | w.mLastLayer = w.mAnimLayer; |
| 10088 | w.mLastDsDx = w.mDsDx; |
| 10089 | w.mLastDtDx = w.mDtDx; |
| 10090 | w.mLastDsDy = w.mDsDy; |
| 10091 | w.mLastDtDy = w.mDtDy; |
| 10092 | w.mLastHScale = w.mHScale; |
| 10093 | w.mLastVScale = w.mVScale; |
| 10094 | if (SHOW_TRANSACTIONS) Log.i( |
| 10095 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10096 | + w.mShownAlpha + " layer=" + w.mAnimLayer |
| 10097 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10098 | + "," + (w.mDtDx*w.mVScale) |
| 10099 | + "][" + (w.mDsDy*w.mHScale) |
| 10100 | + "," + (w.mDtDy*w.mVScale) + "]"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10101 | if (w.mSurface != null) { |
| 10102 | try { |
| 10103 | w.mSurface.setAlpha(w.mShownAlpha); |
| 10104 | w.mSurface.setLayer(w.mAnimLayer); |
| 10105 | w.mSurface.setMatrix( |
| 10106 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10107 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10108 | } catch (RuntimeException e) { |
| 10109 | Log.w(TAG, "Error updating surface in " + w, e); |
| 10110 | if (!recoveringMemory) { |
| 10111 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10112 | } |
| 10113 | } |
| 10114 | } |
| 10115 | |
| 10116 | if (w.mLastHidden && !w.mDrawPending |
| 10117 | && !w.mCommitDrawPending |
| 10118 | && !w.mReadyToShow) { |
| 10119 | if (SHOW_TRANSACTIONS) Log.i( |
| 10120 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 10121 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 10122 | + " during relayout"); |
| 10123 | if (showSurfaceRobustlyLocked(w)) { |
| 10124 | w.mHasDrawn = true; |
| 10125 | w.mLastHidden = false; |
| 10126 | } else { |
| 10127 | w.mOrientationChanging = false; |
| 10128 | } |
| 10129 | } |
| 10130 | if (w.mSurface != null) { |
| 10131 | w.mToken.hasVisible = true; |
| 10132 | } |
| 10133 | } else { |
| 10134 | displayed = true; |
| 10135 | } |
| 10136 | |
| 10137 | if (displayed) { |
| 10138 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10139 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10140 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10141 | covered = true; |
| 10142 | } |
| 10143 | } |
| 10144 | if (w.mOrientationChanging) { |
| 10145 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10146 | orientationChangeComplete = false; |
| 10147 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10148 | "Orientation continue waiting for draw in " + w); |
| 10149 | } else { |
| 10150 | w.mOrientationChanging = false; |
| 10151 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10152 | "Orientation change complete in " + w); |
| 10153 | } |
| 10154 | } |
| 10155 | w.mToken.hasVisible = true; |
| 10156 | } |
| 10157 | } else if (w.mOrientationChanging) { |
| 10158 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10159 | "Orientation change skips hidden " + w); |
| 10160 | w.mOrientationChanging = false; |
| 10161 | } |
| 10162 | |
| 10163 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10164 | |
| 10165 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10166 | focusDisplayed = true; |
| 10167 | } |
| 10168 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10169 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10171 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10172 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10173 | if (w.mSurface != null) { |
| 10174 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10175 | holdScreen = w.mSession; |
| 10176 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10177 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10178 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10179 | screenBrightness = w.mAttrs.screenBrightness; |
| 10180 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10181 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10182 | && buttonBrightness < 0) { |
| 10183 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10184 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10185 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10186 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10187 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 10188 | syswin = true; |
| 10189 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10190 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10191 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10192 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10193 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10194 | // This window completely covers everything behind it, |
| 10195 | // so we want to leave all of them as unblurred (for |
| 10196 | // performance reasons). |
| 10197 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10198 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| 10199 | if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10200 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10201 | obscured = true; |
| 10202 | if (mBackgroundFillerSurface == null) { |
| 10203 | try { |
| 10204 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 10205 | 0, dw, dh, |
| 10206 | PixelFormat.OPAQUE, |
| 10207 | Surface.FX_SURFACE_NORMAL); |
| 10208 | } catch (Exception e) { |
| 10209 | Log.e(TAG, "Exception creating filler surface", e); |
| 10210 | } |
| 10211 | } |
| 10212 | try { |
| 10213 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10214 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10215 | // Using the same layer as Dim because they will never be shown at the |
| 10216 | // same time. |
| 10217 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10218 | mBackgroundFillerSurface.show(); |
| 10219 | } catch (RuntimeException e) { |
| 10220 | Log.e(TAG, "Exception showing filler surface"); |
| 10221 | } |
| 10222 | backgroundFillerShown = true; |
| 10223 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10224 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10225 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 10226 | if (localLOGV) Log.v(TAG, "Win " + w |
| 10227 | + ": blurring=" + blurring |
| 10228 | + " obscured=" + obscured |
| 10229 | + " displayed=" + displayed); |
| 10230 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10231 | if (!dimming) { |
| 10232 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 10233 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10234 | if (mDimAnimator == null) { |
| 10235 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10236 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10237 | mDimAnimator.show(dw, dh); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10238 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10239 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10240 | } |
| 10241 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10242 | if (!blurring) { |
| 10243 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 10244 | blurring = true; |
| 10245 | mBlurShown = true; |
| 10246 | if (mBlurSurface == null) { |
| 10247 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 10248 | + mBlurSurface + ": CREATE"); |
| 10249 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10250 | mBlurSurface = new Surface(mFxSession, 0, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10251 | -1, 16, 16, |
| 10252 | PixelFormat.OPAQUE, |
| 10253 | Surface.FX_SURFACE_BLUR); |
| 10254 | } catch (Exception e) { |
| 10255 | Log.e(TAG, "Exception creating Blur surface", e); |
| 10256 | } |
| 10257 | } |
| 10258 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 10259 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 10260 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 10261 | if (mBlurSurface != null) { |
| 10262 | mBlurSurface.setPosition(0, 0); |
| 10263 | mBlurSurface.setSize(dw, dh); |
| 10264 | try { |
| 10265 | mBlurSurface.show(); |
| 10266 | } catch (RuntimeException e) { |
| 10267 | Log.w(TAG, "Failure showing blur surface", e); |
| 10268 | } |
| 10269 | } |
| 10270 | } |
| 10271 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10272 | } |
| 10273 | } |
| 10274 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10275 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10276 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10277 | // This is the wallpaper target and its obscured state |
| 10278 | // changed... make sure the current wallaper's visibility |
| 10279 | // has been updated accordingly. |
| 10280 | updateWallpaperVisibilityLocked(); |
| 10281 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10282 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10283 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10284 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10285 | mBackgroundFillerShown = false; |
| 10286 | if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler"); |
| 10287 | try { |
| 10288 | mBackgroundFillerSurface.hide(); |
| 10289 | } catch (RuntimeException e) { |
| 10290 | Log.e(TAG, "Exception hiding filler surface", e); |
| 10291 | } |
| 10292 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10293 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10294 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10295 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10296 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10297 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10299 | if (!blurring && mBlurShown) { |
| 10300 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 10301 | + ": HIDE"); |
| 10302 | try { |
| 10303 | mBlurSurface.hide(); |
| 10304 | } catch (IllegalArgumentException e) { |
| 10305 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 10306 | } |
| 10307 | mBlurShown = false; |
| 10308 | } |
| 10309 | |
| 10310 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 10311 | } catch (RuntimeException e) { |
| 10312 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 10313 | } |
| 10314 | |
| 10315 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10316 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10317 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 10318 | "With display frozen, orientationChangeComplete=" |
| 10319 | + orientationChangeComplete); |
| 10320 | if (orientationChangeComplete) { |
| 10321 | if (mWindowsFreezingScreen) { |
| 10322 | mWindowsFreezingScreen = false; |
| 10323 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10324 | } |
| 10325 | if (mAppsFreezingScreen == 0) { |
| 10326 | stopFreezingDisplayLocked(); |
| 10327 | } |
| 10328 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10329 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10330 | i = mResizingWindows.size(); |
| 10331 | if (i > 0) { |
| 10332 | do { |
| 10333 | i--; |
| 10334 | WindowState win = mResizingWindows.get(i); |
| 10335 | try { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10336 | if (DEBUG_ORIENTATION) Log.v(TAG, "Reporting new frame to " |
| 10337 | + win + ": " + win.mFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10338 | win.mClient.resized(win.mFrame.width(), |
| 10339 | win.mFrame.height(), win.mLastContentInsets, |
| 10340 | win.mLastVisibleInsets, win.mDrawPending); |
| 10341 | win.mContentInsetsChanged = false; |
| 10342 | win.mVisibleInsetsChanged = false; |
| 10343 | } catch (RemoteException e) { |
| 10344 | win.mOrientationChanging = false; |
| 10345 | } |
| 10346 | } while (i > 0); |
| 10347 | mResizingWindows.clear(); |
| 10348 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10350 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10351 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10352 | i = mDestroySurface.size(); |
| 10353 | if (i > 0) { |
| 10354 | do { |
| 10355 | i--; |
| 10356 | WindowState win = mDestroySurface.get(i); |
| 10357 | win.mDestroying = false; |
| 10358 | if (mInputMethodWindow == win) { |
| 10359 | mInputMethodWindow = null; |
| 10360 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10361 | if (win == mWallpaperTarget) { |
| 10362 | wallpaperDestroyed = true; |
| 10363 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10364 | win.destroySurfaceLocked(); |
| 10365 | } while (i > 0); |
| 10366 | mDestroySurface.clear(); |
| 10367 | } |
| 10368 | |
| 10369 | // Time to remove any exiting tokens? |
| 10370 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10371 | WindowToken token = mExitingTokens.get(i); |
| 10372 | if (!token.hasVisible) { |
| 10373 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10374 | if (token.windowType == TYPE_WALLPAPER) { |
| 10375 | mWallpaperTokens.remove(token); |
| 10376 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10377 | } |
| 10378 | } |
| 10379 | |
| 10380 | // Time to remove any exiting applications? |
| 10381 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10382 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10383 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10384 | // Make sure there is no animation running on this token, |
| 10385 | // so any windows associated with it will be removed as |
| 10386 | // soon as their animations are complete |
| 10387 | token.animation = null; |
| 10388 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10389 | mAppTokens.remove(token); |
| 10390 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10391 | if (mLastEnterAnimToken == token) { |
| 10392 | mLastEnterAnimToken = null; |
| 10393 | mLastEnterAnimParams = null; |
| 10394 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10395 | } |
| 10396 | } |
| 10397 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10398 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10399 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10400 | if (!animating && mAppTransitionRunning) { |
| 10401 | // We have finished the animation of an app transition. To do |
| 10402 | // this, we have delayed a lot of operations like showing and |
| 10403 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10404 | // reflects the correct Z-order, but the window list may now |
| 10405 | // be out of sync with it. So here we will just rebuild the |
| 10406 | // entire app window list. Fun! |
| 10407 | mAppTransitionRunning = false; |
| 10408 | needRelayout = true; |
| 10409 | rebuildAppWindowListLocked(); |
| 10410 | // Clear information about apps that were moving. |
| 10411 | mToBottomApps.clear(); |
| 10412 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10413 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10414 | if (focusDisplayed) { |
| 10415 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10416 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10417 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10418 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10419 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10420 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10421 | requestAnimationLocked(0); |
| 10422 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10423 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10424 | } |
| 10425 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 10426 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10427 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10428 | } else { |
| 10429 | mPowerManager.setScreenBrightnessOverride((int) |
| 10430 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10431 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10432 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10433 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10434 | } else { |
| 10435 | mPowerManager.setButtonBrightnessOverride((int) |
| 10436 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10437 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10438 | if (holdScreen != mHoldingScreenOn) { |
| 10439 | mHoldingScreenOn = holdScreen; |
| 10440 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10441 | mH.sendMessage(m); |
| 10442 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10443 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10444 | if (mTurnOnScreen) { |
| 10445 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10446 | LocalPowerManager.BUTTON_EVENT, true); |
| 10447 | mTurnOnScreen = false; |
| 10448 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10449 | |
| 10450 | // Check to see if we are now in a state where the screen should |
| 10451 | // be enabled, because the window obscured flags have changed. |
| 10452 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10453 | } |
| 10454 | |
| 10455 | void requestAnimationLocked(long delay) { |
| 10456 | if (!mAnimationPending) { |
| 10457 | mAnimationPending = true; |
| 10458 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10459 | } |
| 10460 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10462 | /** |
| 10463 | * Have the surface flinger show a surface, robustly dealing with |
| 10464 | * error conditions. In particular, if there is not enough memory |
| 10465 | * to show the surface, then we will try to get rid of other surfaces |
| 10466 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10467 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10468 | * @return Returns true if the surface was successfully shown. |
| 10469 | */ |
| 10470 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10471 | try { |
| 10472 | if (win.mSurface != null) { |
| 10473 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10474 | if (win.mTurnOnScreen) { |
| 10475 | win.mTurnOnScreen = false; |
| 10476 | mTurnOnScreen = true; |
| 10477 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10478 | } |
| 10479 | return true; |
| 10480 | } catch (RuntimeException e) { |
| 10481 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 10482 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10484 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10485 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10486 | return false; |
| 10487 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10488 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10489 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10490 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10491 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10492 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10493 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10495 | if (mForceRemoves == null) { |
| 10496 | mForceRemoves = new ArrayList<WindowState>(); |
| 10497 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10498 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10499 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10500 | try { |
| 10501 | // There was some problem... first, do a sanity check of the |
| 10502 | // window list to make sure we haven't left any dangling surfaces |
| 10503 | // around. |
| 10504 | int N = mWindows.size(); |
| 10505 | boolean leakedSurface = false; |
| 10506 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 10507 | for (int i=0; i<N; i++) { |
| 10508 | WindowState ws = (WindowState)mWindows.get(i); |
| 10509 | if (ws.mSurface != null) { |
| 10510 | if (!mSessions.contains(ws.mSession)) { |
| 10511 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 10512 | + ws + " surface=" + ws.mSurface |
| 10513 | + " token=" + win.mToken |
| 10514 | + " pid=" + ws.mSession.mPid |
| 10515 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10516 | ws.mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10517 | ws.mSurface = null; |
| 10518 | mForceRemoves.add(ws); |
| 10519 | i--; |
| 10520 | N--; |
| 10521 | leakedSurface = true; |
| 10522 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 10523 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 10524 | + ws + " surface=" + ws.mSurface |
| 10525 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10526 | ws.mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10527 | ws.mSurface = null; |
| 10528 | leakedSurface = true; |
| 10529 | } |
| 10530 | } |
| 10531 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10533 | boolean killedApps = false; |
| 10534 | if (!leakedSurface) { |
| 10535 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 10536 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10537 | for (int i=0; i<N; i++) { |
| 10538 | WindowState ws = (WindowState)mWindows.get(i); |
| 10539 | if (ws.mSurface != null) { |
| 10540 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10541 | } |
| 10542 | } |
| 10543 | if (pidCandidates.size() > 0) { |
| 10544 | int[] pids = new int[pidCandidates.size()]; |
| 10545 | for (int i=0; i<pids.length; i++) { |
| 10546 | pids[i] = pidCandidates.keyAt(i); |
| 10547 | } |
| 10548 | try { |
| 10549 | if (mActivityManager.killPidsForMemory(pids)) { |
| 10550 | killedApps = true; |
| 10551 | } |
| 10552 | } catch (RemoteException e) { |
| 10553 | } |
| 10554 | } |
| 10555 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10557 | if (leakedSurface || killedApps) { |
| 10558 | // We managed to reclaim some memory, so get rid of the trouble |
| 10559 | // surface and ask the app to request another one. |
| 10560 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 10561 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10562 | surface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10563 | win.mSurface = null; |
| 10564 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10565 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10566 | try { |
| 10567 | win.mClient.dispatchGetNewSurface(); |
| 10568 | } catch (RemoteException e) { |
| 10569 | } |
| 10570 | } |
| 10571 | } finally { |
| 10572 | Binder.restoreCallingIdentity(callingIdentity); |
| 10573 | } |
| 10574 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10575 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10576 | private boolean updateFocusedWindowLocked(int mode) { |
| 10577 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10578 | if (mCurrentFocus != newFocus) { |
| 10579 | // This check makes sure that we don't already have the focus |
| 10580 | // change message pending. |
| 10581 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10582 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 10583 | if (localLOGV) Log.v( |
| 10584 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10585 | final WindowState oldFocus = mCurrentFocus; |
| 10586 | mCurrentFocus = newFocus; |
| 10587 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10589 | final WindowState imWindow = mInputMethodWindow; |
| 10590 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10591 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10592 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10593 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10594 | mLayoutNeeded = true; |
| 10595 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10596 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10597 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10598 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10599 | // Client will do the layout, but we need to assign layers |
| 10600 | // for handleNewWindowLocked() below. |
| 10601 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10602 | } |
| 10603 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10604 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10605 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10606 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 10607 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10608 | return true; |
| 10609 | } |
| 10610 | return false; |
| 10611 | } |
| 10612 | |
| 10613 | private WindowState computeFocusedWindowLocked() { |
| 10614 | WindowState result = null; |
| 10615 | WindowState win; |
| 10616 | |
| 10617 | int i = mWindows.size() - 1; |
| 10618 | int nextAppIndex = mAppTokens.size()-1; |
| 10619 | WindowToken nextApp = nextAppIndex >= 0 |
| 10620 | ? mAppTokens.get(nextAppIndex) : null; |
| 10621 | |
| 10622 | while (i >= 0) { |
| 10623 | win = (WindowState)mWindows.get(i); |
| 10624 | |
| 10625 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10626 | TAG, "Looking for focus: " + i |
| 10627 | + " = " + win |
| 10628 | + ", flags=" + win.mAttrs.flags |
| 10629 | + ", canReceive=" + win.canReceiveKeys()); |
| 10630 | |
| 10631 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10633 | // If this window's application has been removed, just skip it. |
| 10634 | if (thisApp != null && thisApp.removed) { |
| 10635 | i--; |
| 10636 | continue; |
| 10637 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10638 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10639 | // If there is a focused app, don't allow focus to go to any |
| 10640 | // windows below it. If this is an application window, step |
| 10641 | // through the app tokens until we find its app. |
| 10642 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10643 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10644 | int origAppIndex = nextAppIndex; |
| 10645 | while (nextAppIndex > 0) { |
| 10646 | if (nextApp == mFocusedApp) { |
| 10647 | // Whoops, we are below the focused app... no focus |
| 10648 | // for you! |
| 10649 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10650 | TAG, "Reached focused app: " + mFocusedApp); |
| 10651 | return null; |
| 10652 | } |
| 10653 | nextAppIndex--; |
| 10654 | nextApp = mAppTokens.get(nextAppIndex); |
| 10655 | if (nextApp == thisApp) { |
| 10656 | break; |
| 10657 | } |
| 10658 | } |
| 10659 | if (thisApp != nextApp) { |
| 10660 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10661 | // happen, but if it does we can get totally hosed... |
| 10662 | // so restart at the original app. |
| 10663 | nextAppIndex = origAppIndex; |
| 10664 | nextApp = mAppTokens.get(nextAppIndex); |
| 10665 | } |
| 10666 | } |
| 10667 | |
| 10668 | // Dispatch to this window if it is wants key events. |
| 10669 | if (win.canReceiveKeys()) { |
| 10670 | if (DEBUG_FOCUS) Log.v( |
| 10671 | TAG, "Found focus @ " + i + " = " + win); |
| 10672 | result = win; |
| 10673 | break; |
| 10674 | } |
| 10675 | |
| 10676 | i--; |
| 10677 | } |
| 10678 | |
| 10679 | return result; |
| 10680 | } |
| 10681 | |
| 10682 | private void startFreezingDisplayLocked() { |
| 10683 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10684 | // Freezing the display also suspends key event delivery, to |
| 10685 | // keep events from going astray while the display is reconfigured. |
| 10686 | // If someone has changed orientation again while the screen is |
| 10687 | // still frozen, the events will continue to be blocked while the |
| 10688 | // successive orientation change is processed. To prevent spurious |
| 10689 | // ANRs, we reset the event dispatch timeout in this case. |
| 10690 | synchronized (mKeyWaiter) { |
| 10691 | mKeyWaiter.mWasFrozen = true; |
| 10692 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10693 | return; |
| 10694 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10695 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10696 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10697 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10698 | long now = SystemClock.uptimeMillis(); |
| 10699 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 10700 | if (mFreezeGcPending != 0) { |
| 10701 | if (now > (mFreezeGcPending+1000)) { |
| 10702 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 10703 | mH.removeMessages(H.FORCE_GC); |
| 10704 | Runtime.getRuntime().gc(); |
| 10705 | mFreezeGcPending = now; |
| 10706 | } |
| 10707 | } else { |
| 10708 | mFreezeGcPending = now; |
| 10709 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10710 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10711 | mDisplayFrozen = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10712 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10713 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10714 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10715 | mAppTransitionReady = true; |
| 10716 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10717 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10718 | if (PROFILE_ORIENTATION) { |
| 10719 | File file = new File("/data/system/frozen"); |
| 10720 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10721 | } |
| 10722 | Surface.freezeDisplay(0); |
| 10723 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10724 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10725 | private void stopFreezingDisplayLocked() { |
| 10726 | if (!mDisplayFrozen) { |
| 10727 | return; |
| 10728 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10729 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10730 | mDisplayFrozen = false; |
| 10731 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10732 | if (PROFILE_ORIENTATION) { |
| 10733 | Debug.stopMethodTracing(); |
| 10734 | } |
| 10735 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10736 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10737 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 10738 | // too because regular key delivery processing should resume immediately. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10739 | synchronized (mKeyWaiter) { |
| 10740 | mKeyWaiter.mWasFrozen = true; |
| 10741 | mKeyWaiter.notifyAll(); |
| 10742 | } |
| 10743 | |
| 10744 | // A little kludge: a lot could have happened while the |
| 10745 | // display was frozen, so now that we are coming back we |
| 10746 | // do a gc so that any remote references the system |
| 10747 | // processes holds on others can be released if they are |
| 10748 | // no longer needed. |
| 10749 | mH.removeMessages(H.FORCE_GC); |
| 10750 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10751 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10752 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10753 | mScreenFrozenLock.release(); |
| 10754 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10755 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10756 | @Override |
| 10757 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10758 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10759 | != PackageManager.PERMISSION_GRANTED) { |
| 10760 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10761 | + Binder.getCallingPid() |
| 10762 | + ", uid=" + Binder.getCallingUid()); |
| 10763 | return; |
| 10764 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10765 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10766 | synchronized(mWindowMap) { |
| 10767 | pw.println("Current Window Manager state:"); |
| 10768 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 10769 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10770 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10771 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10772 | w.dump(pw, " "); |
| 10773 | } |
| 10774 | if (mInputMethodDialogs.size() > 0) { |
| 10775 | pw.println(" "); |
| 10776 | pw.println(" Input method dialogs:"); |
| 10777 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10778 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10779 | 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] | 10780 | } |
| 10781 | } |
| 10782 | if (mPendingRemove.size() > 0) { |
| 10783 | pw.println(" "); |
| 10784 | pw.println(" Remove pending for:"); |
| 10785 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10786 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10787 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10788 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10789 | w.dump(pw, " "); |
| 10790 | } |
| 10791 | } |
| 10792 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10793 | pw.println(" "); |
| 10794 | pw.println(" Windows force removing:"); |
| 10795 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10796 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10797 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10798 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10799 | w.dump(pw, " "); |
| 10800 | } |
| 10801 | } |
| 10802 | if (mDestroySurface.size() > 0) { |
| 10803 | pw.println(" "); |
| 10804 | pw.println(" Windows waiting to destroy their surface:"); |
| 10805 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10806 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10807 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10808 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10809 | w.dump(pw, " "); |
| 10810 | } |
| 10811 | } |
| 10812 | if (mLosingFocus.size() > 0) { |
| 10813 | pw.println(" "); |
| 10814 | pw.println(" Windows losing focus:"); |
| 10815 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10816 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10817 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10818 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10819 | w.dump(pw, " "); |
| 10820 | } |
| 10821 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10822 | if (mResizingWindows.size() > 0) { |
| 10823 | pw.println(" "); |
| 10824 | pw.println(" Windows waiting to resize:"); |
| 10825 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10826 | WindowState w = mResizingWindows.get(i); |
| 10827 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10828 | pw.print(w); pw.println(":"); |
| 10829 | w.dump(pw, " "); |
| 10830 | } |
| 10831 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10832 | if (mSessions.size() > 0) { |
| 10833 | pw.println(" "); |
| 10834 | pw.println(" All active sessions:"); |
| 10835 | Iterator<Session> it = mSessions.iterator(); |
| 10836 | while (it.hasNext()) { |
| 10837 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10838 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10839 | s.dump(pw, " "); |
| 10840 | } |
| 10841 | } |
| 10842 | if (mTokenMap.size() > 0) { |
| 10843 | pw.println(" "); |
| 10844 | pw.println(" All tokens:"); |
| 10845 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10846 | while (it.hasNext()) { |
| 10847 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10848 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10849 | token.dump(pw, " "); |
| 10850 | } |
| 10851 | } |
| 10852 | if (mTokenList.size() > 0) { |
| 10853 | pw.println(" "); |
| 10854 | pw.println(" Window token list:"); |
| 10855 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10856 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10857 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10858 | } |
| 10859 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10860 | if (mWallpaperTokens.size() > 0) { |
| 10861 | pw.println(" "); |
| 10862 | pw.println(" Wallpaper tokens:"); |
| 10863 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10864 | WindowToken token = mWallpaperTokens.get(i); |
| 10865 | pw.print(" Wallpaper #"); pw.print(i); |
| 10866 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10867 | token.dump(pw, " "); |
| 10868 | } |
| 10869 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10870 | if (mAppTokens.size() > 0) { |
| 10871 | pw.println(" "); |
| 10872 | pw.println(" Application tokens in Z order:"); |
| 10873 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10874 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10875 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10876 | } |
| 10877 | } |
| 10878 | if (mFinishedStarting.size() > 0) { |
| 10879 | pw.println(" "); |
| 10880 | pw.println(" Finishing start of application tokens:"); |
| 10881 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10882 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10883 | pw.print(" Finished Starting #"); pw.print(i); |
| 10884 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10885 | token.dump(pw, " "); |
| 10886 | } |
| 10887 | } |
| 10888 | if (mExitingTokens.size() > 0) { |
| 10889 | pw.println(" "); |
| 10890 | pw.println(" Exiting tokens:"); |
| 10891 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10892 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10893 | pw.print(" Exiting #"); pw.print(i); |
| 10894 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10895 | token.dump(pw, " "); |
| 10896 | } |
| 10897 | } |
| 10898 | if (mExitingAppTokens.size() > 0) { |
| 10899 | pw.println(" "); |
| 10900 | pw.println(" Exiting application tokens:"); |
| 10901 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10902 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10903 | pw.print(" Exiting App #"); pw.print(i); |
| 10904 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10905 | token.dump(pw, " "); |
| 10906 | } |
| 10907 | } |
| 10908 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10909 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10910 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10911 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10912 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10913 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10914 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10915 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10916 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10917 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10918 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10919 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 10920 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10921 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10922 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10923 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10924 | if (mDimAnimator != null) { |
| 10925 | mDimAnimator.printTo(pw); |
| 10926 | } else { |
| 10927 | pw.print( " no DimAnimator "); |
| 10928 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10929 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10930 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10931 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10932 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10933 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10934 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10935 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10936 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 10937 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 10938 | pw.print(" mRotation="); pw.print(mRotation); |
| 10939 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10940 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10941 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10942 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10943 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10944 | pw.print(" mNextAppTransition=0x"); |
| 10945 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10946 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10947 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10948 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10949 | if (mNextAppTransitionPackage != null) { |
| 10950 | pw.print(" mNextAppTransitionPackage="); |
| 10951 | pw.print(mNextAppTransitionPackage); |
| 10952 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10953 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10954 | pw.print(", mNextAppTransitionExit=0x"); |
| 10955 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10956 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10957 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10958 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10959 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10960 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10961 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10962 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10963 | if (mOpeningApps.size() > 0) { |
| 10964 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10965 | } |
| 10966 | if (mClosingApps.size() > 0) { |
| 10967 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10968 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10969 | if (mToTopApps.size() > 0) { |
| 10970 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10971 | } |
| 10972 | if (mToBottomApps.size() > 0) { |
| 10973 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10974 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10975 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10976 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10977 | pw.println(" KeyWaiter state:"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10978 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 10979 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 10980 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 10981 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 10982 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 10983 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10984 | } |
| 10985 | } |
| 10986 | |
| 10987 | public void monitor() { |
| 10988 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10989 | synchronized (mKeyguardTokenWatcher) { } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10990 | synchronized (mKeyWaiter) { } |
| 10991 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10992 | |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10993 | public void virtualKeyFeedback(KeyEvent event) { |
| 10994 | mPolicy.keyFeedbackFromInput(event); |
| 10995 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10996 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10997 | /** |
| 10998 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10999 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11000 | */ |
| 11001 | private static class DimAnimator { |
| 11002 | Surface mDimSurface; |
| 11003 | boolean mDimShown = false; |
| 11004 | float mDimCurrentAlpha; |
| 11005 | float mDimTargetAlpha; |
| 11006 | float mDimDeltaPerMs; |
| 11007 | long mLastDimAnimTime; |
| 11008 | |
| 11009 | DimAnimator (SurfaceSession session) { |
| 11010 | if (mDimSurface == null) { |
| 11011 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 11012 | + mDimSurface + ": CREATE"); |
| 11013 | try { |
| 11014 | mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE, |
| 11015 | Surface.FX_SURFACE_DIM); |
| 11016 | } catch (Exception e) { |
| 11017 | Log.e(TAG, "Exception creating Dim surface", e); |
| 11018 | } |
| 11019 | } |
| 11020 | } |
| 11021 | |
| 11022 | /** |
| 11023 | * Show the dim surface. |
| 11024 | */ |
| 11025 | void show(int dw, int dh) { |
| 11026 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11027 | dw + "x" + dh + ")"); |
| 11028 | mDimShown = true; |
| 11029 | try { |
| 11030 | mDimSurface.setPosition(0, 0); |
| 11031 | mDimSurface.setSize(dw, dh); |
| 11032 | mDimSurface.show(); |
| 11033 | } catch (RuntimeException e) { |
| 11034 | Log.w(TAG, "Failure showing dim surface", e); |
| 11035 | } |
| 11036 | } |
| 11037 | |
| 11038 | /** |
| 11039 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11040 | * {@link updateSurface} after all windows are examined. |
| 11041 | */ |
| 11042 | void updateParameters(WindowState w, long currentTime) { |
| 11043 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11044 | |
| 11045 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11046 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 11047 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11048 | if (mDimTargetAlpha != target) { |
| 11049 | // If the desired dim level has changed, then |
| 11050 | // start an animation to it. |
| 11051 | mLastDimAnimTime = currentTime; |
| 11052 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11053 | ? w.mAnimation.computeDurationHint() |
| 11054 | : DEFAULT_DIM_DURATION; |
| 11055 | if (target > mDimTargetAlpha) { |
| 11056 | // This is happening behind the activity UI, |
| 11057 | // so we can make it run a little longer to |
| 11058 | // give a stronger impression without disrupting |
| 11059 | // the user. |
| 11060 | duration *= DIM_DURATION_MULTIPLIER; |
| 11061 | } |
| 11062 | if (duration < 1) { |
| 11063 | // Don't divide by zero |
| 11064 | duration = 1; |
| 11065 | } |
| 11066 | mDimTargetAlpha = target; |
| 11067 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11068 | } |
| 11069 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11070 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11071 | /** |
| 11072 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11073 | * false when the animation is finished and the dim surface is hidden. |
| 11074 | */ |
| 11075 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11076 | if (!dimming) { |
| 11077 | if (mDimTargetAlpha != 0) { |
| 11078 | mLastDimAnimTime = currentTime; |
| 11079 | mDimTargetAlpha = 0; |
| 11080 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11081 | } |
| 11082 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11083 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11084 | boolean animating = false; |
| 11085 | if (mLastDimAnimTime != 0) { |
| 11086 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11087 | * (currentTime-mLastDimAnimTime); |
| 11088 | boolean more = true; |
| 11089 | if (displayFrozen) { |
| 11090 | // If the display is frozen, there is no reason to animate. |
| 11091 | more = false; |
| 11092 | } else if (mDimDeltaPerMs > 0) { |
| 11093 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11094 | more = false; |
| 11095 | } |
| 11096 | } else if (mDimDeltaPerMs < 0) { |
| 11097 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11098 | more = false; |
| 11099 | } |
| 11100 | } else { |
| 11101 | more = false; |
| 11102 | } |
| 11103 | |
| 11104 | // Do we need to continue animating? |
| 11105 | if (more) { |
| 11106 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 11107 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11108 | mLastDimAnimTime = currentTime; |
| 11109 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11110 | animating = true; |
| 11111 | } else { |
| 11112 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11113 | mLastDimAnimTime = 0; |
| 11114 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 11115 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11116 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11117 | if (!dimming) { |
| 11118 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 11119 | + ": HIDE"); |
| 11120 | try { |
| 11121 | mDimSurface.hide(); |
| 11122 | } catch (RuntimeException e) { |
| 11123 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 11124 | } |
| 11125 | mDimShown = false; |
| 11126 | } |
| 11127 | } |
| 11128 | } |
| 11129 | return animating; |
| 11130 | } |
| 11131 | |
| 11132 | public void printTo(PrintWriter pw) { |
| 11133 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11134 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11135 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11136 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11137 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11138 | } |
| 11139 | } |
| 11140 | |
| 11141 | /** |
| 11142 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11143 | * This is used for opening/closing transition for apps in compatible mode. |
| 11144 | */ |
| 11145 | private static class FadeInOutAnimation extends Animation { |
| 11146 | int mWidth; |
| 11147 | boolean mFadeIn; |
| 11148 | |
| 11149 | public FadeInOutAnimation(boolean fadeIn) { |
| 11150 | setInterpolator(new AccelerateInterpolator()); |
| 11151 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11152 | mFadeIn = fadeIn; |
| 11153 | } |
| 11154 | |
| 11155 | @Override |
| 11156 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11157 | float x = interpolatedTime; |
| 11158 | if (!mFadeIn) { |
| 11159 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11160 | } |
| 11161 | if (x < 0.5) { |
| 11162 | // move the window out of the screen. |
| 11163 | t.getMatrix().setTranslate(mWidth, 0); |
| 11164 | } else { |
| 11165 | t.getMatrix().setTranslate(0, 0);// show |
| 11166 | t.setAlpha((x - 0.5f) * 2); |
| 11167 | } |
| 11168 | } |
| 11169 | |
| 11170 | @Override |
| 11171 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11172 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11173 | mWidth = width; |
| 11174 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11175 | |
| 11176 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11177 | public int getZAdjustment() { |
| 11178 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11179 | } |
| 11180 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11181 | } |