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 |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2388 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2389 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2390 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2391 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2392 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | } else { |
| 2394 | win.mEnterAnimationPending = false; |
| 2395 | if (win.mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2396 | if (DEBUG_VISIBILITY) Log.i(TAG, "Relayout invis " + win |
| 2397 | + ": mExiting=" + win.mExiting |
| 2398 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | // If we are not currently running the exit animation, we |
| 2400 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2401 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | // Try starting an animation; if there isn't one, we |
| 2403 | // can destroy the surface right away. |
| 2404 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2405 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2406 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2407 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2408 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2409 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2410 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | win.mExiting = true; |
| 2412 | mKeyWaiter.finishedKey(session, client, true, |
| 2413 | KeyWaiter.RETURN_NOTHING); |
| 2414 | } else if (win.isAnimating()) { |
| 2415 | // Currently in a hide animation... turn this into |
| 2416 | // an exit. |
| 2417 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2418 | } else if (win == mWallpaperTarget) { |
| 2419 | // If the wallpaper is currently behind this |
| 2420 | // window, we need to change both of them inside |
| 2421 | // of a transaction to avoid artifacts. |
| 2422 | win.mExiting = true; |
| 2423 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2424 | } else { |
| 2425 | if (mInputMethodWindow == win) { |
| 2426 | mInputMethodWindow = null; |
| 2427 | } |
| 2428 | win.destroySurfaceLocked(); |
| 2429 | } |
| 2430 | } |
| 2431 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2432 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2433 | if (win.mSurface == null || (win.getAttrs().flags |
| 2434 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2435 | || win.mSurfacePendingDestroy) { |
| 2436 | // We are being called from a local process, which |
| 2437 | // means outSurface holds its current surface. Ensure the |
| 2438 | // surface object is cleared, but we don't want it actually |
| 2439 | // destroyed at this point. |
| 2440 | win.mSurfacePendingDestroy = false; |
| 2441 | outSurface.release(); |
| 2442 | if (DEBUG_VISIBILITY) Log.i(TAG, "Releasing surface in: " + win); |
| 2443 | } else if (win.mSurface != null) { |
| 2444 | if (DEBUG_VISIBILITY) Log.i(TAG, |
| 2445 | "Keeping surface, will report destroy: " + win); |
| 2446 | win.mReportDestroySurface = true; |
| 2447 | outSurface.copyFrom(win.mSurface); |
| 2448 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | } |
| 2450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | if (focusMayChange) { |
| 2452 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2453 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2454 | imMayMove = false; |
| 2455 | } |
| 2456 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2457 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2458 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2459 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2460 | // reassign them at this point if the IM window state gets shuffled |
| 2461 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2464 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2465 | // Little hack here -- we -should- be able to rely on the |
| 2466 | // function to return true if the IME has moved and needs |
| 2467 | // its layer recomputed. However, if the IME was hidden |
| 2468 | // and isn't actually moved in the list, its layer may be |
| 2469 | // 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] | 2470 | assignLayers = true; |
| 2471 | } |
| 2472 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2473 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2474 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2475 | assignLayers = true; |
| 2476 | } |
| 2477 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2479 | mLayoutNeeded = true; |
| 2480 | win.mGivenInsetsPending = insetsPending; |
| 2481 | if (assignLayers) { |
| 2482 | assignLayersLocked(); |
| 2483 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2484 | newConfig = updateOrientationFromAppTokensLocked(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2486 | if (displayed && win.mIsWallpaper) { |
| 2487 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2488 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2489 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | if (win.mAppToken != null) { |
| 2491 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2492 | } |
| 2493 | outFrame.set(win.mFrame); |
| 2494 | outContentInsets.set(win.mContentInsets); |
| 2495 | outVisibleInsets.set(win.mVisibleInsets); |
| 2496 | if (localLOGV) Log.v( |
| 2497 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2498 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | + ", requestedHeight=" + requestedHeight |
| 2500 | + ", viewVisibility=" + viewVisibility |
| 2501 | + "\nRelayout returning frame=" + outFrame |
| 2502 | + ", surface=" + outSurface); |
| 2503 | |
| 2504 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 2505 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2506 | |
| 2507 | inTouchMode = mInTouchMode; |
| 2508 | } |
| 2509 | |
| 2510 | if (newConfig != null) { |
| 2511 | sendNewConfiguration(); |
| 2512 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2517 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2518 | } |
| 2519 | |
| 2520 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2521 | final long origId = Binder.clearCallingIdentity(); |
| 2522 | synchronized(mWindowMap) { |
| 2523 | WindowState win = windowForClientLocked(session, client); |
| 2524 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2525 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2526 | adjustWallpaperWindowsLocked(); |
| 2527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | mLayoutNeeded = true; |
| 2529 | performLayoutAndPlaceSurfacesLocked(); |
| 2530 | } |
| 2531 | } |
| 2532 | Binder.restoreCallingIdentity(origId); |
| 2533 | } |
| 2534 | |
| 2535 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| 2536 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2537 | + (lp != null ? lp.packageName : null) |
| 2538 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2539 | if (lp != null && lp.windowAnimations != 0) { |
| 2540 | // If this is a system resource, don't try to load it from the |
| 2541 | // application resources. It is nice to avoid loading application |
| 2542 | // resources if we can. |
| 2543 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2544 | int resId = lp.windowAnimations; |
| 2545 | if ((resId&0xFF000000) == 0x01000000) { |
| 2546 | packageName = "android"; |
| 2547 | } |
| 2548 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2549 | + packageName); |
| 2550 | return AttributeCache.instance().get(packageName, resId, |
| 2551 | com.android.internal.R.styleable.WindowAnimation); |
| 2552 | } |
| 2553 | return null; |
| 2554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2555 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2556 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| 2557 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: params package=" |
| 2558 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2559 | if (packageName != null) { |
| 2560 | if ((resId&0xFF000000) == 0x01000000) { |
| 2561 | packageName = "android"; |
| 2562 | } |
| 2563 | if (DEBUG_ANIM) Log.v(TAG, "Loading animations: picked package=" |
| 2564 | + packageName); |
| 2565 | return AttributeCache.instance().get(packageName, resId, |
| 2566 | com.android.internal.R.styleable.WindowAnimation); |
| 2567 | } |
| 2568 | return null; |
| 2569 | } |
| 2570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | private void applyEnterAnimationLocked(WindowState win) { |
| 2572 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2573 | if (win.mEnterAnimationPending) { |
| 2574 | win.mEnterAnimationPending = false; |
| 2575 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2576 | } |
| 2577 | |
| 2578 | applyAnimationLocked(win, transit, true); |
| 2579 | } |
| 2580 | |
| 2581 | private boolean applyAnimationLocked(WindowState win, |
| 2582 | int transit, boolean isEntrance) { |
| 2583 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2584 | // If we are trying to apply an animation, but already running |
| 2585 | // an animation of the same type, then just leave that one alone. |
| 2586 | return true; |
| 2587 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | // Only apply an animation if the display isn't frozen. If it is |
| 2590 | // frozen, there is no reason to animate and it can cause strange |
| 2591 | // artifacts when we unfreeze the display if some different animation |
| 2592 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2593 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2595 | int attr = -1; |
| 2596 | Animation a = null; |
| 2597 | if (anim != 0) { |
| 2598 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2599 | } else { |
| 2600 | switch (transit) { |
| 2601 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2602 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2603 | break; |
| 2604 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2605 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2606 | break; |
| 2607 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2608 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2609 | break; |
| 2610 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2611 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2612 | break; |
| 2613 | } |
| 2614 | if (attr >= 0) { |
| 2615 | a = loadAnimation(win.mAttrs, attr); |
| 2616 | } |
| 2617 | } |
| 2618 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: win=" + win |
| 2619 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2620 | + " mAnimation=" + win.mAnimation |
| 2621 | + " isEntrance=" + isEntrance); |
| 2622 | if (a != null) { |
| 2623 | if (DEBUG_ANIM) { |
| 2624 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2625 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2626 | Log.v(TAG, "Loaded animation " + a + " for " + win, e); |
| 2627 | } |
| 2628 | win.setAnimation(a); |
| 2629 | win.mAnimationIsEntrance = isEntrance; |
| 2630 | } |
| 2631 | } else { |
| 2632 | win.clearAnimation(); |
| 2633 | } |
| 2634 | |
| 2635 | return win.mAnimation != null; |
| 2636 | } |
| 2637 | |
| 2638 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2639 | int anim = 0; |
| 2640 | Context context = mContext; |
| 2641 | if (animAttr >= 0) { |
| 2642 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2643 | if (ent != null) { |
| 2644 | context = ent.context; |
| 2645 | anim = ent.array.getResourceId(animAttr, 0); |
| 2646 | } |
| 2647 | } |
| 2648 | if (anim != 0) { |
| 2649 | return AnimationUtils.loadAnimation(context, anim); |
| 2650 | } |
| 2651 | return null; |
| 2652 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2653 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2654 | private Animation loadAnimation(String packageName, int resId) { |
| 2655 | int anim = 0; |
| 2656 | Context context = mContext; |
| 2657 | if (resId >= 0) { |
| 2658 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2659 | if (ent != null) { |
| 2660 | context = ent.context; |
| 2661 | anim = resId; |
| 2662 | } |
| 2663 | } |
| 2664 | if (anim != 0) { |
| 2665 | return AnimationUtils.loadAnimation(context, anim); |
| 2666 | } |
| 2667 | return null; |
| 2668 | } |
| 2669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2671 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2672 | // Only apply an animation if the display isn't frozen. If it is |
| 2673 | // frozen, there is no reason to animate and it can cause strange |
| 2674 | // artifacts when we unfreeze the display if some different animation |
| 2675 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2676 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2677 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2678 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2679 | a = new FadeInOutAnimation(enter); |
| 2680 | if (DEBUG_ANIM) Log.v(TAG, |
| 2681 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2682 | } else if (mNextAppTransitionPackage != null) { |
| 2683 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2684 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2685 | } else { |
| 2686 | int animAttr = 0; |
| 2687 | switch (transit) { |
| 2688 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2689 | animAttr = enter |
| 2690 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2691 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2692 | break; |
| 2693 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2694 | animAttr = enter |
| 2695 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2696 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2697 | break; |
| 2698 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2699 | animAttr = enter |
| 2700 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2701 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2702 | break; |
| 2703 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2704 | animAttr = enter |
| 2705 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2706 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2707 | break; |
| 2708 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2709 | animAttr = enter |
| 2710 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2711 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2712 | break; |
| 2713 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2714 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2715 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2716 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2717 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2718 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2719 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2720 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2721 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2722 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2723 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2724 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2725 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2726 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2727 | break; |
| 2728 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2729 | animAttr = enter |
| 2730 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2731 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2732 | break; |
| 2733 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2734 | animAttr = enter |
| 2735 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2736 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2737 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2738 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2739 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2740 | if (DEBUG_ANIM) Log.v(TAG, "applyAnimation: wtoken=" + wtoken |
| 2741 | + " anim=" + a |
| 2742 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2743 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2745 | if (a != null) { |
| 2746 | if (DEBUG_ANIM) { |
| 2747 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2748 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | Log.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| 2750 | } |
| 2751 | wtoken.setAnimation(a); |
| 2752 | } |
| 2753 | } else { |
| 2754 | wtoken.clearAnimation(); |
| 2755 | } |
| 2756 | |
| 2757 | return wtoken.animation != null; |
| 2758 | } |
| 2759 | |
| 2760 | // ------------------------------------------------------------- |
| 2761 | // Application Window Tokens |
| 2762 | // ------------------------------------------------------------- |
| 2763 | |
| 2764 | public void validateAppTokens(List tokens) { |
| 2765 | int v = tokens.size()-1; |
| 2766 | int m = mAppTokens.size()-1; |
| 2767 | while (v >= 0 && m >= 0) { |
| 2768 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2769 | if (wtoken.removed) { |
| 2770 | m--; |
| 2771 | continue; |
| 2772 | } |
| 2773 | if (tokens.get(v) != wtoken.token) { |
| 2774 | Log.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| 2775 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2776 | } |
| 2777 | v--; |
| 2778 | m--; |
| 2779 | } |
| 2780 | while (v >= 0) { |
| 2781 | Log.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| 2782 | v--; |
| 2783 | } |
| 2784 | while (m >= 0) { |
| 2785 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2786 | if (!wtoken.removed) { |
| 2787 | Log.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| 2788 | } |
| 2789 | m--; |
| 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | boolean checkCallingPermission(String permission, String func) { |
| 2794 | // Quick check: if the calling permission is me, it's all okay. |
| 2795 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2796 | return true; |
| 2797 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2799 | if (mContext.checkCallingPermission(permission) |
| 2800 | == PackageManager.PERMISSION_GRANTED) { |
| 2801 | return true; |
| 2802 | } |
| 2803 | String msg = "Permission Denial: " + func + " from pid=" |
| 2804 | + Binder.getCallingPid() |
| 2805 | + ", uid=" + Binder.getCallingUid() |
| 2806 | + " requires " + permission; |
| 2807 | Log.w(TAG, msg); |
| 2808 | return false; |
| 2809 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2810 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2812 | WindowToken wtoken = mTokenMap.get(token); |
| 2813 | if (wtoken == null) { |
| 2814 | return null; |
| 2815 | } |
| 2816 | return wtoken.appWindowToken; |
| 2817 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | public void addWindowToken(IBinder token, int type) { |
| 2820 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2821 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2822 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2825 | synchronized(mWindowMap) { |
| 2826 | WindowToken wtoken = mTokenMap.get(token); |
| 2827 | if (wtoken != null) { |
| 2828 | Log.w(TAG, "Attempted to add existing input method token: " + token); |
| 2829 | return; |
| 2830 | } |
| 2831 | wtoken = new WindowToken(token, type, true); |
| 2832 | mTokenMap.put(token, wtoken); |
| 2833 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2834 | if (type == TYPE_WALLPAPER) { |
| 2835 | mWallpaperTokens.add(wtoken); |
| 2836 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | } |
| 2838 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | public void removeWindowToken(IBinder token) { |
| 2841 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2842 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2843 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | final long origId = Binder.clearCallingIdentity(); |
| 2847 | synchronized(mWindowMap) { |
| 2848 | WindowToken wtoken = mTokenMap.remove(token); |
| 2849 | mTokenList.remove(wtoken); |
| 2850 | if (wtoken != null) { |
| 2851 | boolean delayed = false; |
| 2852 | if (!wtoken.hidden) { |
| 2853 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | final int N = wtoken.windows.size(); |
| 2856 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | for (int i=0; i<N; i++) { |
| 2859 | WindowState win = wtoken.windows.get(i); |
| 2860 | |
| 2861 | if (win.isAnimating()) { |
| 2862 | delayed = true; |
| 2863 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | if (win.isVisibleNow()) { |
| 2866 | applyAnimationLocked(win, |
| 2867 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2868 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2869 | KeyWaiter.RETURN_NOTHING); |
| 2870 | changed = true; |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | if (changed) { |
| 2875 | mLayoutNeeded = true; |
| 2876 | performLayoutAndPlaceSurfacesLocked(); |
| 2877 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2878 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2880 | if (delayed) { |
| 2881 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2882 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2883 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | } |
| 2885 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | } else { |
| 2888 | Log.w(TAG, "Attempted to remove non-existing token: " + token); |
| 2889 | } |
| 2890 | } |
| 2891 | Binder.restoreCallingIdentity(origId); |
| 2892 | } |
| 2893 | |
| 2894 | public void addAppToken(int addPos, IApplicationToken token, |
| 2895 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2896 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2897 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2898 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | synchronized(mWindowMap) { |
| 2902 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2903 | if (wtoken != null) { |
| 2904 | Log.w(TAG, "Attempted to add existing app token: " + token); |
| 2905 | return; |
| 2906 | } |
| 2907 | wtoken = new AppWindowToken(token); |
| 2908 | wtoken.groupId = groupId; |
| 2909 | wtoken.appFullscreen = fullscreen; |
| 2910 | wtoken.requestedOrientation = requestedOrientation; |
| 2911 | mAppTokens.add(addPos, wtoken); |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 2912 | 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] | 2913 | mTokenMap.put(token.asBinder(), wtoken); |
| 2914 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | // Application tokens start out hidden. |
| 2917 | wtoken.hidden = true; |
| 2918 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | //dump(); |
| 2921 | } |
| 2922 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | public void setAppGroupId(IBinder token, int groupId) { |
| 2925 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2926 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2927 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | synchronized(mWindowMap) { |
| 2931 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2932 | if (wtoken == null) { |
| 2933 | Log.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| 2934 | return; |
| 2935 | } |
| 2936 | wtoken.groupId = groupId; |
| 2937 | } |
| 2938 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | public int getOrientationFromWindowsLocked() { |
| 2941 | int pos = mWindows.size() - 1; |
| 2942 | while (pos >= 0) { |
| 2943 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2944 | pos--; |
| 2945 | if (wtoken.mAppToken != null) { |
| 2946 | // We hit an application window. so the orientation will be determined by the |
| 2947 | // app window. No point in continuing further. |
| 2948 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2949 | } |
| 2950 | if (!wtoken.isVisibleLw()) { |
| 2951 | continue; |
| 2952 | } |
| 2953 | int req = wtoken.mAttrs.screenOrientation; |
| 2954 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2955 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2956 | continue; |
| 2957 | } else { |
| 2958 | return req; |
| 2959 | } |
| 2960 | } |
| 2961 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2962 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | public int getOrientationFromAppTokensLocked() { |
| 2965 | int pos = mAppTokens.size() - 1; |
| 2966 | int curGroup = 0; |
| 2967 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2968 | boolean findingBehind = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | boolean haveGroup = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2970 | boolean lastFullscreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | while (pos >= 0) { |
| 2972 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 2973 | pos--; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 2974 | // if we're about to tear down this window and not seek for |
| 2975 | // the behind activity, don't use it for orientation |
| 2976 | if (!findingBehind |
| 2977 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2978 | continue; |
| 2979 | } |
| 2980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | if (!haveGroup) { |
| 2982 | // We ignore any hidden applications on the top. |
| 2983 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| 2984 | continue; |
| 2985 | } |
| 2986 | haveGroup = true; |
| 2987 | curGroup = wtoken.groupId; |
| 2988 | lastOrientation = wtoken.requestedOrientation; |
| 2989 | } else if (curGroup != wtoken.groupId) { |
| 2990 | // If we have hit a new application group, and the bottom |
| 2991 | // 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] | 2992 | // the orientation behind it, and the last app was |
| 2993 | // full screen, then we'll stick with the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | // user's orientation. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2995 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 2996 | && lastFullscreen) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2997 | return lastOrientation; |
| 2998 | } |
| 2999 | } |
| 3000 | int or = wtoken.requestedOrientation; |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 3001 | // If this application is fullscreen, and didn't explicitly say |
| 3002 | // 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] | 3003 | // orientation it has and ignores whatever is under it. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3004 | lastFullscreen = wtoken.appFullscreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3005 | if (lastFullscreen |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 3006 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | return or; |
| 3008 | } |
| 3009 | // If this application has requested an explicit orientation, |
| 3010 | // then use it. |
| 3011 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3012 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3013 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3014 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3015 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3016 | return or; |
| 3017 | } |
Owen Lin | 3413b89 | 2009-05-01 17:12:32 -0700 | [diff] [blame] | 3018 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3019 | } |
| 3020 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3021 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3024 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3025 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3026 | "updateOrientationFromAppTokens()")) { |
| 3027 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3028 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | Configuration config; |
| 3031 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3032 | config = updateOrientationFromAppTokensUnchecked(currentConfig, |
| 3033 | freezeThisOneIfNeeded); |
| 3034 | Binder.restoreCallingIdentity(ident); |
| 3035 | return config; |
| 3036 | } |
| 3037 | |
| 3038 | Configuration updateOrientationFromAppTokensUnchecked( |
| 3039 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 3040 | Configuration config; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | synchronized(mWindowMap) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3042 | config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3043 | if (config != null) { |
| 3044 | mLayoutNeeded = true; |
| 3045 | performLayoutAndPlaceSurfacesLocked(); |
| 3046 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | return config; |
| 3049 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | /* |
| 3052 | * The orientation is computed from non-application windows first. If none of |
| 3053 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3054 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3055 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3056 | * android.os.IBinder) |
| 3057 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3058 | Configuration updateOrientationFromAppTokensLocked( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3059 | Configuration appConfig, IBinder freezeThisOneIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3061 | long ident = Binder.clearCallingIdentity(); |
| 3062 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3063 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3064 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | if (req != mForcedAppOrientation) { |
| 3066 | changed = true; |
| 3067 | mForcedAppOrientation = req; |
| 3068 | //send a message to Policy indicating orientation change to take |
| 3069 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3070 | mPolicy.setCurrentOrientationLw(req); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3071 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3073 | if (changed) { |
| 3074 | changed = setRotationUncheckedLocked( |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 3075 | WindowManagerPolicy.USE_LAST_ROTATION, |
| 3076 | mLastRotationFlags & (~Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3077 | if (changed) { |
| 3078 | if (freezeThisOneIfNeeded != null) { |
| 3079 | AppWindowToken wtoken = findAppWindowToken( |
| 3080 | freezeThisOneIfNeeded); |
| 3081 | if (wtoken != null) { |
| 3082 | startAppFreezingScreenLocked(wtoken, |
| 3083 | ActivityInfo.CONFIG_ORIENTATION); |
| 3084 | } |
| 3085 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3086 | return computeNewConfigurationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | } |
| 3088 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3089 | |
| 3090 | // No obvious action we need to take, but if our current |
| 3091 | // state mismatches the activity maanager's, update it |
| 3092 | if (appConfig != null) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3093 | mTempConfiguration.setToDefaults(); |
| 3094 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3095 | if (appConfig.diff(mTempConfiguration) != 0) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 3096 | return new Configuration(mTempConfiguration); |
| 3097 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3098 | } |
| 3099 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3100 | } finally { |
| 3101 | Binder.restoreCallingIdentity(ident); |
| 3102 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3104 | return null; |
| 3105 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3106 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3107 | int computeForcedAppOrientationLocked() { |
| 3108 | int req = getOrientationFromWindowsLocked(); |
| 3109 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3110 | req = getOrientationFromAppTokensLocked(); |
| 3111 | } |
| 3112 | return req; |
| 3113 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3116 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3117 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3118 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3119 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | synchronized(mWindowMap) { |
| 3122 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3123 | if (wtoken == null) { |
| 3124 | Log.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| 3125 | return; |
| 3126 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3128 | wtoken.requestedOrientation = requestedOrientation; |
| 3129 | } |
| 3130 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3132 | public int getAppOrientation(IApplicationToken token) { |
| 3133 | synchronized(mWindowMap) { |
| 3134 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3135 | if (wtoken == null) { |
| 3136 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3137 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3139 | return wtoken.requestedOrientation; |
| 3140 | } |
| 3141 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3144 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3145 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3146 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | synchronized(mWindowMap) { |
| 3150 | boolean changed = false; |
| 3151 | if (token == null) { |
| 3152 | if (DEBUG_FOCUS) Log.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| 3153 | changed = mFocusedApp != null; |
| 3154 | mFocusedApp = null; |
| 3155 | mKeyWaiter.tickle(); |
| 3156 | } else { |
| 3157 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3158 | if (newFocus == null) { |
| 3159 | Log.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| 3160 | return; |
| 3161 | } |
| 3162 | changed = mFocusedApp != newFocus; |
| 3163 | mFocusedApp = newFocus; |
| 3164 | if (DEBUG_FOCUS) Log.v(TAG, "Set focused app to: " + mFocusedApp); |
| 3165 | mKeyWaiter.tickle(); |
| 3166 | } |
| 3167 | |
| 3168 | if (moveFocusNow && changed) { |
| 3169 | final long origId = Binder.clearCallingIdentity(); |
| 3170 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3171 | Binder.restoreCallingIdentity(origId); |
| 3172 | } |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | public void prepareAppTransition(int transit) { |
| 3177 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3178 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3179 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3182 | synchronized(mWindowMap) { |
| 3183 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3184 | TAG, "Prepare app transition: transit=" + transit |
| 3185 | + " mNextAppTransition=" + mNextAppTransition); |
| 3186 | if (!mDisplayFrozen) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3187 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3188 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3189 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3190 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3191 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3192 | // Opening a new task always supersedes a close for the anim. |
| 3193 | mNextAppTransition = transit; |
| 3194 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3195 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3196 | // Opening a new activity always supersedes a close for the anim. |
| 3197 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3198 | } |
| 3199 | mAppTransitionReady = false; |
| 3200 | mAppTransitionTimeout = false; |
| 3201 | mStartingIconInTransition = false; |
| 3202 | mSkipAppTransitionAnimation = false; |
| 3203 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3204 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3205 | 5000); |
| 3206 | } |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | public int getPendingAppTransition() { |
| 3211 | return mNextAppTransition; |
| 3212 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3213 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3214 | public void overridePendingAppTransition(String packageName, |
| 3215 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3216 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3217 | mNextAppTransitionPackage = packageName; |
| 3218 | mNextAppTransitionEnter = enterAnim; |
| 3219 | mNextAppTransitionExit = exitAnim; |
| 3220 | } |
| 3221 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | public void executeAppTransition() { |
| 3224 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3225 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3226 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3227 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3230 | if (DEBUG_APP_TRANSITIONS) { |
| 3231 | RuntimeException e = new RuntimeException("here"); |
| 3232 | e.fillInStackTrace(); |
| 3233 | Log.w(TAG, "Execute app transition: mNextAppTransition=" |
| 3234 | + mNextAppTransition, e); |
| 3235 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3236 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | mAppTransitionReady = true; |
| 3238 | final long origId = Binder.clearCallingIdentity(); |
| 3239 | performLayoutAndPlaceSurfacesLocked(); |
| 3240 | Binder.restoreCallingIdentity(origId); |
| 3241 | } |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3246 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3247 | IBinder transferFrom, boolean createIfNeeded) { |
| 3248 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3249 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3250 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | synchronized(mWindowMap) { |
| 3254 | if (DEBUG_STARTING_WINDOW) Log.v( |
| 3255 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3256 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3259 | if (wtoken == null) { |
| 3260 | Log.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| 3261 | return; |
| 3262 | } |
| 3263 | |
| 3264 | // If the display is frozen, we won't do anything until the |
| 3265 | // actual window is displayed so there is no reason to put in |
| 3266 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3267 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | return; |
| 3269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3271 | if (wtoken.startingData != null) { |
| 3272 | return; |
| 3273 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3275 | if (transferFrom != null) { |
| 3276 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3277 | if (ttoken != null) { |
| 3278 | WindowState startingWindow = ttoken.startingWindow; |
| 3279 | if (startingWindow != null) { |
| 3280 | if (mStartingIconInTransition) { |
| 3281 | // In this case, the starting icon has already |
| 3282 | // been displayed, so start letting windows get |
| 3283 | // shown immediately without any more transitions. |
| 3284 | mSkipAppTransitionAnimation = true; |
| 3285 | } |
| 3286 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3287 | "Moving existing starting from " + ttoken |
| 3288 | + " to " + wtoken); |
| 3289 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3291 | // Transfer the starting window over to the new |
| 3292 | // token. |
| 3293 | wtoken.startingData = ttoken.startingData; |
| 3294 | wtoken.startingView = ttoken.startingView; |
| 3295 | wtoken.startingWindow = startingWindow; |
| 3296 | ttoken.startingData = null; |
| 3297 | ttoken.startingView = null; |
| 3298 | ttoken.startingWindow = null; |
| 3299 | ttoken.startingMoved = true; |
| 3300 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3301 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3302 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3303 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3304 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | mWindows.remove(startingWindow); |
| 3306 | ttoken.windows.remove(startingWindow); |
| 3307 | ttoken.allAppWindows.remove(startingWindow); |
| 3308 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | // Propagate other interesting state between the |
| 3311 | // tokens. If the old token is displayed, we should |
| 3312 | // immediately force the new one to be displayed. If |
| 3313 | // it is animating, we need to move that animation to |
| 3314 | // the new one. |
| 3315 | if (ttoken.allDrawn) { |
| 3316 | wtoken.allDrawn = true; |
| 3317 | } |
| 3318 | if (ttoken.firstWindowDrawn) { |
| 3319 | wtoken.firstWindowDrawn = true; |
| 3320 | } |
| 3321 | if (!ttoken.hidden) { |
| 3322 | wtoken.hidden = false; |
| 3323 | wtoken.hiddenRequested = false; |
| 3324 | wtoken.willBeHidden = false; |
| 3325 | } |
| 3326 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3327 | wtoken.clientHidden = ttoken.clientHidden; |
| 3328 | wtoken.sendAppVisibilityToClients(); |
| 3329 | } |
| 3330 | if (ttoken.animation != null) { |
| 3331 | wtoken.animation = ttoken.animation; |
| 3332 | wtoken.animating = ttoken.animating; |
| 3333 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3334 | ttoken.animation = null; |
| 3335 | ttoken.animLayerAdjustment = 0; |
| 3336 | wtoken.updateLayers(); |
| 3337 | ttoken.updateLayers(); |
| 3338 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3341 | mLayoutNeeded = true; |
| 3342 | performLayoutAndPlaceSurfacesLocked(); |
| 3343 | Binder.restoreCallingIdentity(origId); |
| 3344 | return; |
| 3345 | } else if (ttoken.startingData != null) { |
| 3346 | // The previous app was getting ready to show a |
| 3347 | // starting window, but hasn't yet done so. Steal it! |
| 3348 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 3349 | "Moving pending starting from " + ttoken |
| 3350 | + " to " + wtoken); |
| 3351 | wtoken.startingData = ttoken.startingData; |
| 3352 | ttoken.startingData = null; |
| 3353 | ttoken.startingMoved = true; |
| 3354 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3355 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3356 | // want to process the message ASAP, before any other queued |
| 3357 | // messages. |
| 3358 | mH.sendMessageAtFrontOfQueue(m); |
| 3359 | return; |
| 3360 | } |
| 3361 | } |
| 3362 | } |
| 3363 | |
| 3364 | // There is no existing starting window, and the caller doesn't |
| 3365 | // want us to create one, so that's it! |
| 3366 | if (!createIfNeeded) { |
| 3367 | return; |
| 3368 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3369 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3370 | // If this is a translucent or wallpaper window, then don't |
| 3371 | // show a starting window -- the current effect (a full-screen |
| 3372 | // opaque starting window that fades away to the real contents |
| 3373 | // when it is ready) does not work for this. |
| 3374 | if (theme != 0) { |
| 3375 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3376 | com.android.internal.R.styleable.Window); |
| 3377 | if (ent.array.getBoolean( |
| 3378 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3379 | return; |
| 3380 | } |
| 3381 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3382 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3383 | return; |
| 3384 | } |
| 3385 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3386 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3387 | return; |
| 3388 | } |
| 3389 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3391 | mStartingIconInTransition = true; |
| 3392 | wtoken.startingData = new StartingData( |
| 3393 | pkg, theme, nonLocalizedLabel, |
| 3394 | labelRes, icon); |
| 3395 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3396 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3397 | // want to process the message ASAP, before any other queued |
| 3398 | // messages. |
| 3399 | mH.sendMessageAtFrontOfQueue(m); |
| 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | public void setAppWillBeHidden(IBinder token) { |
| 3404 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3405 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3406 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | AppWindowToken wtoken; |
| 3410 | |
| 3411 | synchronized(mWindowMap) { |
| 3412 | wtoken = findAppWindowToken(token); |
| 3413 | if (wtoken == null) { |
| 3414 | Log.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| 3415 | return; |
| 3416 | } |
| 3417 | wtoken.willBeHidden = true; |
| 3418 | } |
| 3419 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3421 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3422 | boolean visible, int transit, boolean performLayout) { |
| 3423 | boolean delayed = false; |
| 3424 | |
| 3425 | if (wtoken.clientHidden == visible) { |
| 3426 | wtoken.clientHidden = !visible; |
| 3427 | wtoken.sendAppVisibilityToClients(); |
| 3428 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3430 | wtoken.willBeHidden = false; |
| 3431 | if (wtoken.hidden == visible) { |
| 3432 | final int N = wtoken.allAppWindows.size(); |
| 3433 | boolean changed = false; |
| 3434 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3435 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3436 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3438 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3439 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3440 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3441 | if (wtoken.animation == sDummyAnimation) { |
| 3442 | wtoken.animation = null; |
| 3443 | } |
| 3444 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3445 | changed = true; |
| 3446 | if (wtoken.animation != null) { |
| 3447 | delayed = runningAppAnimation = true; |
| 3448 | } |
| 3449 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3451 | for (int i=0; i<N; i++) { |
| 3452 | WindowState win = wtoken.allAppWindows.get(i); |
| 3453 | if (win == wtoken.startingWindow) { |
| 3454 | continue; |
| 3455 | } |
| 3456 | |
| 3457 | if (win.isAnimating()) { |
| 3458 | delayed = true; |
| 3459 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3461 | //Log.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| 3462 | //win.dump(" "); |
| 3463 | if (visible) { |
| 3464 | if (!win.isVisibleNow()) { |
| 3465 | if (!runningAppAnimation) { |
| 3466 | applyAnimationLocked(win, |
| 3467 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3468 | } |
| 3469 | changed = true; |
| 3470 | } |
| 3471 | } else if (win.isVisibleNow()) { |
| 3472 | if (!runningAppAnimation) { |
| 3473 | applyAnimationLocked(win, |
| 3474 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3475 | } |
| 3476 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3477 | KeyWaiter.RETURN_NOTHING); |
| 3478 | changed = true; |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3483 | if (!visible) { |
| 3484 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3485 | } else { |
| 3486 | // If we are being set visible, and the starting window is |
| 3487 | // not yet displayed, then make sure it doesn't get displayed. |
| 3488 | WindowState swin = wtoken.startingWindow; |
| 3489 | if (swin != null && (swin.mDrawPending |
| 3490 | || swin.mCommitDrawPending)) { |
| 3491 | swin.mPolicyVisibility = false; |
| 3492 | swin.mPolicyVisibilityAfterAnim = false; |
| 3493 | } |
| 3494 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| 3497 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3498 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3499 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3500 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | mLayoutNeeded = true; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3502 | if (performLayout) { |
| 3503 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3504 | performLayoutAndPlaceSurfacesLocked(); |
| 3505 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | } |
| 3507 | } |
| 3508 | |
| 3509 | if (wtoken.animation != null) { |
| 3510 | delayed = true; |
| 3511 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3513 | return delayed; |
| 3514 | } |
| 3515 | |
| 3516 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3517 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3518 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3519 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | AppWindowToken wtoken; |
| 3523 | |
| 3524 | synchronized(mWindowMap) { |
| 3525 | wtoken = findAppWindowToken(token); |
| 3526 | if (wtoken == null) { |
| 3527 | Log.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| 3528 | return; |
| 3529 | } |
| 3530 | |
| 3531 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| 3532 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3533 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3534 | Log.v(TAG, "setAppVisibility(" + token + ", " + visible |
| 3535 | + "): mNextAppTransition=" + mNextAppTransition |
| 3536 | + " hidden=" + wtoken.hidden |
| 3537 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3538 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | // If we are preparing an app transition, then delay changing |
| 3541 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3542 | if (!mDisplayFrozen && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | // Already in requested state, don't do anything more. |
| 3544 | if (wtoken.hiddenRequested != visible) { |
| 3545 | return; |
| 3546 | } |
| 3547 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3550 | TAG, "Setting dummy animation on: " + wtoken); |
| 3551 | wtoken.setDummyAnimation(); |
| 3552 | mOpeningApps.remove(wtoken); |
| 3553 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3554 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3555 | wtoken.inPendingTransaction = true; |
| 3556 | if (visible) { |
| 3557 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | wtoken.startingDisplayed = false; |
| 3559 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3560 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3561 | // If the token is currently hidden (should be the |
| 3562 | // common case), then we need to set up to wait for |
| 3563 | // its windows to be ready. |
| 3564 | if (wtoken.hidden) { |
| 3565 | wtoken.allDrawn = false; |
| 3566 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3567 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3568 | if (wtoken.clientHidden) { |
| 3569 | // In the case where we are making an app visible |
| 3570 | // but holding off for a transition, we still need |
| 3571 | // to tell the client to make its windows visible so |
| 3572 | // they get drawn. Otherwise, we will wait on |
| 3573 | // performing the transition until all windows have |
| 3574 | // been drawn, they never will be, and we are sad. |
| 3575 | wtoken.clientHidden = false; |
| 3576 | wtoken.sendAppVisibilityToClients(); |
| 3577 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3578 | } |
| 3579 | } else { |
| 3580 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3581 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3582 | // If the token is currently visible (should be the |
| 3583 | // common case), then set up to wait for it to be hidden. |
| 3584 | if (!wtoken.hidden) { |
| 3585 | wtoken.waitingToHide = true; |
| 3586 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | } |
| 3588 | return; |
| 3589 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3592 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3593 | wtoken.updateReportedVisibilityLocked(); |
| 3594 | Binder.restoreCallingIdentity(origId); |
| 3595 | } |
| 3596 | } |
| 3597 | |
| 3598 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3599 | boolean unfreezeSurfaceNow, boolean force) { |
| 3600 | if (wtoken.freezingScreen) { |
| 3601 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + wtoken |
| 3602 | + " force=" + force); |
| 3603 | final int N = wtoken.allAppWindows.size(); |
| 3604 | boolean unfrozeWindows = false; |
| 3605 | for (int i=0; i<N; i++) { |
| 3606 | WindowState w = wtoken.allAppWindows.get(i); |
| 3607 | if (w.mAppFreezing) { |
| 3608 | w.mAppFreezing = false; |
| 3609 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3610 | w.mOrientationChanging = true; |
| 3611 | } |
| 3612 | unfrozeWindows = true; |
| 3613 | } |
| 3614 | } |
| 3615 | if (force || unfrozeWindows) { |
| 3616 | if (DEBUG_ORIENTATION) Log.v(TAG, "No longer freezing: " + wtoken); |
| 3617 | wtoken.freezingScreen = false; |
| 3618 | mAppsFreezingScreen--; |
| 3619 | } |
| 3620 | if (unfreezeSurfaceNow) { |
| 3621 | if (unfrozeWindows) { |
| 3622 | mLayoutNeeded = true; |
| 3623 | performLayoutAndPlaceSurfacesLocked(); |
| 3624 | } |
| 3625 | if (mAppsFreezingScreen == 0 && !mWindowsFreezingScreen) { |
| 3626 | stopFreezingDisplayLocked(); |
| 3627 | } |
| 3628 | } |
| 3629 | } |
| 3630 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3633 | int configChanges) { |
| 3634 | if (DEBUG_ORIENTATION) { |
| 3635 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3636 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3637 | Log.i(TAG, "Set freezing of " + wtoken.appToken |
| 3638 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3639 | + wtoken.freezingScreen, e); |
| 3640 | } |
| 3641 | if (!wtoken.hiddenRequested) { |
| 3642 | if (!wtoken.freezingScreen) { |
| 3643 | wtoken.freezingScreen = true; |
| 3644 | mAppsFreezingScreen++; |
| 3645 | if (mAppsFreezingScreen == 1) { |
| 3646 | startFreezingDisplayLocked(); |
| 3647 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3648 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3649 | 5000); |
| 3650 | } |
| 3651 | } |
| 3652 | final int N = wtoken.allAppWindows.size(); |
| 3653 | for (int i=0; i<N; i++) { |
| 3654 | WindowState w = wtoken.allAppWindows.get(i); |
| 3655 | w.mAppFreezing = true; |
| 3656 | } |
| 3657 | } |
| 3658 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3661 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3662 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3663 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | synchronized(mWindowMap) { |
| 3667 | if (configChanges == 0 && !mDisplayFrozen) { |
| 3668 | if (DEBUG_ORIENTATION) Log.v(TAG, "Skipping set freeze of " + token); |
| 3669 | return; |
| 3670 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3673 | if (wtoken == null || wtoken.appToken == null) { |
| 3674 | Log.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| 3675 | return; |
| 3676 | } |
| 3677 | final long origId = Binder.clearCallingIdentity(); |
| 3678 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3679 | Binder.restoreCallingIdentity(origId); |
| 3680 | } |
| 3681 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3683 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3684 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3685 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3686 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | synchronized(mWindowMap) { |
| 3690 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3691 | if (wtoken == null || wtoken.appToken == null) { |
| 3692 | return; |
| 3693 | } |
| 3694 | final long origId = Binder.clearCallingIdentity(); |
| 3695 | if (DEBUG_ORIENTATION) Log.v(TAG, "Clear freezing of " + token |
| 3696 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3697 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3698 | Binder.restoreCallingIdentity(origId); |
| 3699 | } |
| 3700 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | public void removeAppToken(IBinder token) { |
| 3703 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3704 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3705 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | } |
| 3707 | |
| 3708 | AppWindowToken wtoken = null; |
| 3709 | AppWindowToken startingToken = null; |
| 3710 | boolean delayed = false; |
| 3711 | |
| 3712 | final long origId = Binder.clearCallingIdentity(); |
| 3713 | synchronized(mWindowMap) { |
| 3714 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3715 | mTokenList.remove(basewtoken); |
| 3716 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| 3717 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3718 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | wtoken.inPendingTransaction = false; |
| 3720 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3721 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | if (mClosingApps.contains(wtoken)) { |
| 3723 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3724 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3725 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3726 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3727 | delayed = true; |
| 3728 | } |
| 3729 | if (DEBUG_APP_TRANSITIONS) Log.v( |
| 3730 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3731 | + " animation=" + wtoken.animation |
| 3732 | + " animating=" + wtoken.animating); |
| 3733 | if (delayed) { |
| 3734 | // set the token aside because it has an active animation to be finished |
| 3735 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3736 | } else { |
| 3737 | // Make sure there is no animation running on this token, |
| 3738 | // so any windows associated with it will be removed as |
| 3739 | // soon as their animations are complete |
| 3740 | wtoken.animation = null; |
| 3741 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | } |
| 3743 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3744 | if (mLastEnterAnimToken == wtoken) { |
| 3745 | mLastEnterAnimToken = null; |
| 3746 | mLastEnterAnimParams = null; |
| 3747 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | wtoken.removed = true; |
| 3749 | if (wtoken.startingData != null) { |
| 3750 | startingToken = wtoken; |
| 3751 | } |
| 3752 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3753 | if (mFocusedApp == wtoken) { |
| 3754 | if (DEBUG_FOCUS) Log.v(TAG, "Removing focused app token:" + wtoken); |
| 3755 | mFocusedApp = null; |
| 3756 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3757 | mKeyWaiter.tickle(); |
| 3758 | } |
| 3759 | } else { |
| 3760 | Log.w(TAG, "Attempted to remove non-existing app token: " + token); |
| 3761 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3763 | if (!delayed && wtoken != null) { |
| 3764 | wtoken.updateReportedVisibilityLocked(); |
| 3765 | } |
| 3766 | } |
| 3767 | Binder.restoreCallingIdentity(origId); |
| 3768 | |
| 3769 | if (startingToken != null) { |
| 3770 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Schedule remove starting " |
| 3771 | + startingToken + ": app token removed"); |
| 3772 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3773 | mH.sendMessage(m); |
| 3774 | } |
| 3775 | } |
| 3776 | |
| 3777 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3778 | final int NW = token.windows.size(); |
| 3779 | for (int i=0; i<NW; i++) { |
| 3780 | WindowState win = token.windows.get(i); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3781 | 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] | 3782 | mWindows.remove(win); |
| 3783 | int j = win.mChildWindows.size(); |
| 3784 | while (j > 0) { |
| 3785 | j--; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3786 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3787 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 3788 | "Tmp removing child window " + cwin); |
| 3789 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | } |
| 3791 | } |
| 3792 | return NW > 0; |
| 3793 | } |
| 3794 | |
| 3795 | void dumpAppTokensLocked() { |
| 3796 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| 3797 | Log.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| 3798 | } |
| 3799 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | void dumpWindowsLocked() { |
| 3802 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 3803 | Log.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| 3804 | } |
| 3805 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | private int findWindowOffsetLocked(int tokenPos) { |
| 3808 | final int NW = mWindows.size(); |
| 3809 | |
| 3810 | if (tokenPos >= mAppTokens.size()) { |
| 3811 | int i = NW; |
| 3812 | while (i > 0) { |
| 3813 | i--; |
| 3814 | WindowState win = (WindowState)mWindows.get(i); |
| 3815 | if (win.getAppToken() != null) { |
| 3816 | return i+1; |
| 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | |
| 3821 | while (tokenPos > 0) { |
| 3822 | // Find the first app token below the new position that has |
| 3823 | // a window displayed. |
| 3824 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| 3825 | if (DEBUG_REORDER) Log.v(TAG, "Looking for lower windows @ " |
| 3826 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3827 | if (wtoken.sendingToBottom) { |
| 3828 | if (DEBUG_REORDER) Log.v(TAG, |
| 3829 | "Skipping token -- currently sending to bottom"); |
| 3830 | tokenPos--; |
| 3831 | continue; |
| 3832 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | int i = wtoken.windows.size(); |
| 3834 | while (i > 0) { |
| 3835 | i--; |
| 3836 | WindowState win = wtoken.windows.get(i); |
| 3837 | int j = win.mChildWindows.size(); |
| 3838 | while (j > 0) { |
| 3839 | j--; |
| 3840 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3841 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | for (int pos=NW-1; pos>=0; pos--) { |
| 3843 | if (mWindows.get(pos) == cwin) { |
| 3844 | if (DEBUG_REORDER) Log.v(TAG, |
| 3845 | "Found child win @" + (pos+1)); |
| 3846 | return pos+1; |
| 3847 | } |
| 3848 | } |
| 3849 | } |
| 3850 | } |
| 3851 | for (int pos=NW-1; pos>=0; pos--) { |
| 3852 | if (mWindows.get(pos) == win) { |
| 3853 | if (DEBUG_REORDER) Log.v(TAG, "Found win @" + (pos+1)); |
| 3854 | return pos+1; |
| 3855 | } |
| 3856 | } |
| 3857 | } |
| 3858 | tokenPos--; |
| 3859 | } |
| 3860 | |
| 3861 | return 0; |
| 3862 | } |
| 3863 | |
| 3864 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3865 | final int NCW = win.mChildWindows.size(); |
| 3866 | boolean added = false; |
| 3867 | for (int j=0; j<NCW; j++) { |
| 3868 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3869 | if (!added && cwin.mSubLayer >= 0) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3870 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding child window at " |
| 3871 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | mWindows.add(index, win); |
| 3873 | index++; |
| 3874 | added = true; |
| 3875 | } |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3876 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3877 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | mWindows.add(index, cwin); |
| 3879 | index++; |
| 3880 | } |
| 3881 | if (!added) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3882 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, "Re-adding window at " |
| 3883 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | mWindows.add(index, win); |
| 3885 | index++; |
| 3886 | } |
| 3887 | return index; |
| 3888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3891 | final int NW = token.windows.size(); |
| 3892 | for (int i=0; i<NW; i++) { |
| 3893 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3894 | } |
| 3895 | return index; |
| 3896 | } |
| 3897 | |
| 3898 | public void moveAppToken(int index, IBinder token) { |
| 3899 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3900 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3901 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | synchronized(mWindowMap) { |
| 3905 | if (DEBUG_REORDER) Log.v(TAG, "Initial app tokens:"); |
| 3906 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3907 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3908 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| 3909 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3910 | + token + " (" + wtoken + ")"); |
| 3911 | return; |
| 3912 | } |
| 3913 | mAppTokens.add(index, wtoken); |
| 3914 | if (DEBUG_REORDER) Log.v(TAG, "Moved " + token + " to " + index + ":"); |
| 3915 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3917 | final long origId = Binder.clearCallingIdentity(); |
| 3918 | if (DEBUG_REORDER) Log.v(TAG, "Removing windows in " + token + ":"); |
| 3919 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3920 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 3921 | if (DEBUG_REORDER) Log.v(TAG, "Adding windows back in:"); |
| 3922 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3923 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| 3924 | if (DEBUG_REORDER) Log.v(TAG, "Final window list:"); |
| 3925 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3926 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | mLayoutNeeded = true; |
| 3928 | performLayoutAndPlaceSurfacesLocked(); |
| 3929 | } |
| 3930 | Binder.restoreCallingIdentity(origId); |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3935 | // XXX This should be done more efficiently! |
| 3936 | // (take advantage of the fact that both lists should be |
| 3937 | // ordered in the same way.) |
| 3938 | int N = tokens.size(); |
| 3939 | for (int i=0; i<N; i++) { |
| 3940 | IBinder token = tokens.get(i); |
| 3941 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3942 | if (!mAppTokens.remove(wtoken)) { |
| 3943 | Log.w(TAG, "Attempting to reorder token that doesn't exist: " |
| 3944 | + token + " (" + wtoken + ")"); |
| 3945 | i--; |
| 3946 | N--; |
| 3947 | } |
| 3948 | } |
| 3949 | } |
| 3950 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3951 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 3952 | boolean updateFocusAndLayout) { |
| 3953 | // First remove all of the windows from the list. |
| 3954 | tmpRemoveAppWindowsLocked(wtoken); |
| 3955 | |
| 3956 | // Where to start adding? |
| 3957 | int pos = findWindowOffsetLocked(tokenPos); |
| 3958 | |
| 3959 | // And now add them back at the correct place. |
| 3960 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 3961 | |
| 3962 | if (updateFocusAndLayout) { |
| 3963 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3964 | assignLayersLocked(); |
| 3965 | } |
| 3966 | mLayoutNeeded = true; |
| 3967 | performLayoutAndPlaceSurfacesLocked(); |
| 3968 | } |
| 3969 | } |
| 3970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 3972 | // First remove all of the windows from the list. |
| 3973 | final int N = tokens.size(); |
| 3974 | int i; |
| 3975 | for (i=0; i<N; i++) { |
| 3976 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3977 | if (token != null) { |
| 3978 | tmpRemoveAppWindowsLocked(token); |
| 3979 | } |
| 3980 | } |
| 3981 | |
| 3982 | // Where to start adding? |
| 3983 | int pos = findWindowOffsetLocked(tokenPos); |
| 3984 | |
| 3985 | // And now add them back at the correct place. |
| 3986 | for (i=0; i<N; i++) { |
| 3987 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 3988 | if (token != null) { |
| 3989 | pos = reAddAppWindowsLocked(pos, token); |
| 3990 | } |
| 3991 | } |
| 3992 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3993 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 3994 | assignLayersLocked(); |
| 3995 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | mLayoutNeeded = true; |
| 3997 | performLayoutAndPlaceSurfacesLocked(); |
| 3998 | |
| 3999 | //dump(); |
| 4000 | } |
| 4001 | |
| 4002 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4003 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4004 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4005 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | final long origId = Binder.clearCallingIdentity(); |
| 4009 | synchronized(mWindowMap) { |
| 4010 | removeAppTokensLocked(tokens); |
| 4011 | final int N = tokens.size(); |
| 4012 | for (int i=0; i<N; i++) { |
| 4013 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4014 | if (wt != null) { |
| 4015 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4016 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4017 | mToTopApps.remove(wt); |
| 4018 | mToBottomApps.remove(wt); |
| 4019 | mToTopApps.add(wt); |
| 4020 | wt.sendingToBottom = false; |
| 4021 | wt.sendingToTop = true; |
| 4022 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | } |
| 4024 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4025 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4026 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4027 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4028 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4029 | } |
| 4030 | Binder.restoreCallingIdentity(origId); |
| 4031 | } |
| 4032 | |
| 4033 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4034 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4035 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4036 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | final long origId = Binder.clearCallingIdentity(); |
| 4040 | synchronized(mWindowMap) { |
| 4041 | removeAppTokensLocked(tokens); |
| 4042 | final int N = tokens.size(); |
| 4043 | int pos = 0; |
| 4044 | for (int i=0; i<N; i++) { |
| 4045 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4046 | if (wt != null) { |
| 4047 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4048 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4049 | mToTopApps.remove(wt); |
| 4050 | mToBottomApps.remove(wt); |
| 4051 | mToBottomApps.add(i, wt); |
| 4052 | wt.sendingToTop = false; |
| 4053 | wt.sendingToBottom = true; |
| 4054 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | pos++; |
| 4056 | } |
| 4057 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4058 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4059 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4060 | moveAppWindowsLocked(tokens, 0); |
| 4061 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4062 | } |
| 4063 | Binder.restoreCallingIdentity(origId); |
| 4064 | } |
| 4065 | |
| 4066 | // ------------------------------------------------------------- |
| 4067 | // Misc IWindowSession methods |
| 4068 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4070 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4071 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | != PackageManager.PERMISSION_GRANTED) { |
| 4073 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4074 | } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4075 | synchronized (mKeyguardTokenWatcher) { |
| 4076 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4077 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4081 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4082 | != PackageManager.PERMISSION_GRANTED) { |
| 4083 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4084 | } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4085 | synchronized (mKeyguardTokenWatcher) { |
| 4086 | mKeyguardTokenWatcher.release(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4087 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4088 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4089 | // If we are the last one to reenable the keyguard wait until |
| 4090 | // we have actaully finished reenabling until returning. |
| 4091 | // It is possible that reenableKeyguard() can be called before |
| 4092 | // the previous disableKeyguard() is handled, in which case |
| 4093 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4094 | // be called. In that case mKeyguardDisabled will be false here |
| 4095 | // and we have nothing to wait for. |
| 4096 | while (mKeyguardDisabled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | try { |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4098 | mKeyguardTokenWatcher.wait(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | } catch (InterruptedException e) { |
| 4100 | Thread.currentThread().interrupt(); |
| 4101 | } |
| 4102 | } |
| 4103 | } |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | /** |
| 4108 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4109 | */ |
| 4110 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4111 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4112 | != PackageManager.PERMISSION_GRANTED) { |
| 4113 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4114 | } |
| 4115 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4116 | public void onKeyguardExitResult(boolean success) { |
| 4117 | try { |
| 4118 | callback.onKeyguardExitResult(success); |
| 4119 | } catch (RemoteException e) { |
| 4120 | // Client has died, we don't care. |
| 4121 | } |
| 4122 | } |
| 4123 | }); |
| 4124 | } |
| 4125 | |
| 4126 | public boolean inKeyguardRestrictedInputMode() { |
| 4127 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4128 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4129 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4130 | public void closeSystemDialogs(String reason) { |
| 4131 | synchronized(mWindowMap) { |
| 4132 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4133 | WindowState w = (WindowState)mWindows.get(i); |
| 4134 | if (w.mSurface != null) { |
| 4135 | try { |
| 4136 | w.mClient.closeSystemDialogs(reason); |
| 4137 | } catch (RemoteException e) { |
| 4138 | } |
| 4139 | } |
| 4140 | } |
| 4141 | } |
| 4142 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | static float fixScale(float scale) { |
| 4145 | if (scale < 0) scale = 0; |
| 4146 | else if (scale > 20) scale = 20; |
| 4147 | return Math.abs(scale); |
| 4148 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | public void setAnimationScale(int which, float scale) { |
| 4151 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4152 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4153 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4154 | } |
| 4155 | |
| 4156 | if (scale < 0) scale = 0; |
| 4157 | else if (scale > 20) scale = 20; |
| 4158 | scale = Math.abs(scale); |
| 4159 | switch (which) { |
| 4160 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4161 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4162 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | // Persist setting |
| 4165 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4166 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | public void setAnimationScales(float[] scales) { |
| 4169 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4170 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4171 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | if (scales != null) { |
| 4175 | if (scales.length >= 1) { |
| 4176 | mWindowAnimationScale = fixScale(scales[0]); |
| 4177 | } |
| 4178 | if (scales.length >= 2) { |
| 4179 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4180 | } |
| 4181 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4183 | // Persist setting |
| 4184 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4185 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4187 | public float getAnimationScale(int which) { |
| 4188 | switch (which) { |
| 4189 | case 0: return mWindowAnimationScale; |
| 4190 | case 1: return mTransitionAnimationScale; |
| 4191 | } |
| 4192 | return 0; |
| 4193 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4195 | public float[] getAnimationScales() { |
| 4196 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4197 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4199 | public int getSwitchState(int sw) { |
| 4200 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4201 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4202 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4203 | } |
| 4204 | return KeyInputQueue.getSwitchState(sw); |
| 4205 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4208 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4209 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4210 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | } |
| 4212 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4213 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4215 | public int getScancodeState(int sw) { |
| 4216 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4217 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4218 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4219 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4220 | return mQueue.getScancodeState(sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4223 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4224 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4225 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4226 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4227 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4228 | return mQueue.getScancodeState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4230 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4231 | public int getTrackballScancodeState(int sw) { |
| 4232 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4233 | "getTrackballScancodeState()")) { |
| 4234 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4235 | } |
| 4236 | return mQueue.getTrackballScancodeState(sw); |
| 4237 | } |
| 4238 | |
| 4239 | public int getDPadScancodeState(int sw) { |
| 4240 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4241 | "getDPadScancodeState()")) { |
| 4242 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4243 | } |
| 4244 | return mQueue.getDPadScancodeState(sw); |
| 4245 | } |
| 4246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | public int getKeycodeState(int sw) { |
| 4248 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4249 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4250 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4251 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4252 | return mQueue.getKeycodeState(sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4253 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4255 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4256 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4257 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4258 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | } |
Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4260 | return mQueue.getKeycodeState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4261 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4262 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4263 | public int getTrackballKeycodeState(int sw) { |
| 4264 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4265 | "getTrackballKeycodeState()")) { |
| 4266 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4267 | } |
| 4268 | return mQueue.getTrackballKeycodeState(sw); |
| 4269 | } |
| 4270 | |
| 4271 | public int getDPadKeycodeState(int sw) { |
| 4272 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4273 | "getDPadKeycodeState()")) { |
| 4274 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4275 | } |
| 4276 | return mQueue.getDPadKeycodeState(sw); |
| 4277 | } |
| 4278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4279 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 4280 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4281 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4283 | public void enableScreenAfterBoot() { |
| 4284 | synchronized(mWindowMap) { |
| 4285 | if (mSystemBooted) { |
| 4286 | return; |
| 4287 | } |
| 4288 | mSystemBooted = true; |
| 4289 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | performEnableScreen(); |
| 4292 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4294 | public void enableScreenIfNeededLocked() { |
| 4295 | if (mDisplayEnabled) { |
| 4296 | return; |
| 4297 | } |
| 4298 | if (!mSystemBooted) { |
| 4299 | return; |
| 4300 | } |
| 4301 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4302 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | public void performEnableScreen() { |
| 4305 | synchronized(mWindowMap) { |
| 4306 | if (mDisplayEnabled) { |
| 4307 | return; |
| 4308 | } |
| 4309 | if (!mSystemBooted) { |
| 4310 | return; |
| 4311 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4313 | // Don't enable the screen until all existing windows |
| 4314 | // have been drawn. |
| 4315 | final int N = mWindows.size(); |
| 4316 | for (int i=0; i<N; i++) { |
| 4317 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4318 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | return; |
| 4320 | } |
| 4321 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | mDisplayEnabled = true; |
| 4324 | if (false) { |
| 4325 | Log.i(TAG, "ENABLING SCREEN!"); |
| 4326 | StringWriter sw = new StringWriter(); |
| 4327 | PrintWriter pw = new PrintWriter(sw); |
| 4328 | this.dump(null, pw, null); |
| 4329 | Log.i(TAG, sw.toString()); |
| 4330 | } |
| 4331 | try { |
| 4332 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4333 | if (surfaceFlinger != null) { |
| 4334 | //Log.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| 4335 | Parcel data = Parcel.obtain(); |
| 4336 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4337 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4338 | data, null, 0); |
| 4339 | data.recycle(); |
| 4340 | } |
| 4341 | } catch (RemoteException ex) { |
| 4342 | Log.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| 4343 | } |
| 4344 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4349 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4350 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4351 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4353 | public void setInTouchMode(boolean mode) { |
| 4354 | synchronized(mWindowMap) { |
| 4355 | mInTouchMode = mode; |
| 4356 | } |
| 4357 | } |
| 4358 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4359 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4360 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4361 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4362 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4363 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4364 | } |
| 4365 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4366 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4368 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4369 | public void setRotationUnchecked(int rotation, |
| 4370 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | if(DEBUG_ORIENTATION) Log.v(TAG, |
| 4372 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4374 | long origId = Binder.clearCallingIdentity(); |
| 4375 | boolean changed; |
| 4376 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4377 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4380 | if (changed) { |
| 4381 | sendNewConfiguration(); |
| 4382 | synchronized(mWindowMap) { |
| 4383 | mLayoutNeeded = true; |
| 4384 | performLayoutAndPlaceSurfacesLocked(); |
| 4385 | } |
| 4386 | } else if (alwaysSendConfiguration) { |
| 4387 | //update configuration ignoring orientation change |
| 4388 | sendNewConfiguration(); |
| 4389 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4391 | Binder.restoreCallingIdentity(origId); |
| 4392 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4393 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4394 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | boolean changed; |
| 4396 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4397 | rotation = mRequestedRotation; |
| 4398 | } else { |
| 4399 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4400 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | } |
| 4402 | 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] | 4403 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4404 | mRotation, mDisplayEnabled); |
| 4405 | if (DEBUG_ORIENTATION) Log.v(TAG, "new rotation is set to " + rotation); |
| 4406 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4408 | if (changed) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4409 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | "Rotation changed to " + rotation |
| 4411 | + " from " + mRotation |
| 4412 | + " (forceApp=" + mForcedAppOrientation |
| 4413 | + ", req=" + mRequestedRotation + ")"); |
| 4414 | mRotation = rotation; |
| 4415 | mWindowsFreezingScreen = true; |
| 4416 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4417 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4418 | 2000); |
| 4419 | startFreezingDisplayLocked(); |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4420 | Log.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4421 | mQueue.setOrientation(rotation); |
| 4422 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4423 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4424 | } |
| 4425 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4426 | WindowState w = (WindowState)mWindows.get(i); |
| 4427 | if (w.mSurface != null) { |
| 4428 | w.mOrientationChanging = true; |
| 4429 | } |
| 4430 | } |
| 4431 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4432 | try { |
| 4433 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4434 | } catch (RemoteException e) { |
| 4435 | } |
| 4436 | } |
| 4437 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | return changed; |
| 4440 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4442 | public int getRotation() { |
| 4443 | return mRotation; |
| 4444 | } |
| 4445 | |
| 4446 | public int watchRotation(IRotationWatcher watcher) { |
| 4447 | final IBinder watcherBinder = watcher.asBinder(); |
| 4448 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4449 | public void binderDied() { |
| 4450 | synchronized (mWindowMap) { |
| 4451 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4452 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4453 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4454 | if (removed != null) { |
| 4455 | removed.asBinder().unlinkToDeath(this, 0); |
| 4456 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4457 | i--; |
| 4458 | } |
| 4459 | } |
| 4460 | } |
| 4461 | } |
| 4462 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | synchronized (mWindowMap) { |
| 4465 | try { |
| 4466 | watcher.asBinder().linkToDeath(dr, 0); |
| 4467 | mRotationWatchers.add(watcher); |
| 4468 | } catch (RemoteException e) { |
| 4469 | // Client died, no cleanup needed. |
| 4470 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4472 | return mRotation; |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | /** |
| 4477 | * Starts the view server on the specified port. |
| 4478 | * |
| 4479 | * @param port The port to listener to. |
| 4480 | * |
| 4481 | * @return True if the server was successfully started, false otherwise. |
| 4482 | * |
| 4483 | * @see com.android.server.ViewServer |
| 4484 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4485 | */ |
| 4486 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4487 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | return false; |
| 4489 | } |
| 4490 | |
| 4491 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4492 | return false; |
| 4493 | } |
| 4494 | |
| 4495 | if (port < 1024) { |
| 4496 | return false; |
| 4497 | } |
| 4498 | |
| 4499 | if (mViewServer != null) { |
| 4500 | if (!mViewServer.isRunning()) { |
| 4501 | try { |
| 4502 | return mViewServer.start(); |
| 4503 | } catch (IOException e) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4504 | Log.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | } |
| 4506 | } |
| 4507 | return false; |
| 4508 | } |
| 4509 | |
| 4510 | try { |
| 4511 | mViewServer = new ViewServer(this, port); |
| 4512 | return mViewServer.start(); |
| 4513 | } catch (IOException e) { |
| 4514 | Log.w(TAG, "View server did not start"); |
| 4515 | } |
| 4516 | return false; |
| 4517 | } |
| 4518 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4519 | private boolean isSystemSecure() { |
| 4520 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4521 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4522 | } |
| 4523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | /** |
| 4525 | * Stops the view server if it exists. |
| 4526 | * |
| 4527 | * @return True if the server stopped, false if it wasn't started or |
| 4528 | * couldn't be stopped. |
| 4529 | * |
| 4530 | * @see com.android.server.ViewServer |
| 4531 | */ |
| 4532 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4533 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4534 | return false; |
| 4535 | } |
| 4536 | |
| 4537 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4538 | return false; |
| 4539 | } |
| 4540 | |
| 4541 | if (mViewServer != null) { |
| 4542 | return mViewServer.stop(); |
| 4543 | } |
| 4544 | return false; |
| 4545 | } |
| 4546 | |
| 4547 | /** |
| 4548 | * Indicates whether the view server is running. |
| 4549 | * |
| 4550 | * @return True if the server is running, false otherwise. |
| 4551 | * |
| 4552 | * @see com.android.server.ViewServer |
| 4553 | */ |
| 4554 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4555 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4556 | return false; |
| 4557 | } |
| 4558 | |
| 4559 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4560 | return false; |
| 4561 | } |
| 4562 | |
| 4563 | return mViewServer != null && mViewServer.isRunning(); |
| 4564 | } |
| 4565 | |
| 4566 | /** |
| 4567 | * Lists all availble windows in the system. The listing is written in the |
| 4568 | * specified Socket's output stream with the following syntax: |
| 4569 | * windowHashCodeInHexadecimal windowName |
| 4570 | * Each line of the ouput represents a different window. |
| 4571 | * |
| 4572 | * @param client The remote client to send the listing to. |
| 4573 | * @return False if an error occured, true otherwise. |
| 4574 | */ |
| 4575 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4576 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4577 | return false; |
| 4578 | } |
| 4579 | |
| 4580 | boolean result = true; |
| 4581 | |
| 4582 | Object[] windows; |
| 4583 | synchronized (mWindowMap) { |
| 4584 | windows = new Object[mWindows.size()]; |
| 4585 | //noinspection unchecked |
| 4586 | windows = mWindows.toArray(windows); |
| 4587 | } |
| 4588 | |
| 4589 | BufferedWriter out = null; |
| 4590 | |
| 4591 | // Any uncaught exception will crash the system process |
| 4592 | try { |
| 4593 | OutputStream clientStream = client.getOutputStream(); |
| 4594 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4595 | |
| 4596 | final int count = windows.length; |
| 4597 | for (int i = 0; i < count; i++) { |
| 4598 | final WindowState w = (WindowState) windows[i]; |
| 4599 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4600 | out.write(' '); |
| 4601 | out.append(w.mAttrs.getTitle()); |
| 4602 | out.write('\n'); |
| 4603 | } |
| 4604 | |
| 4605 | out.write("DONE.\n"); |
| 4606 | out.flush(); |
| 4607 | } catch (Exception e) { |
| 4608 | result = false; |
| 4609 | } finally { |
| 4610 | if (out != null) { |
| 4611 | try { |
| 4612 | out.close(); |
| 4613 | } catch (IOException e) { |
| 4614 | result = false; |
| 4615 | } |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | return result; |
| 4620 | } |
| 4621 | |
| 4622 | /** |
| 4623 | * Sends a command to a target window. The result of the command, if any, will be |
| 4624 | * written in the output stream of the specified socket. |
| 4625 | * |
| 4626 | * The parameters must follow this syntax: |
| 4627 | * windowHashcode extra |
| 4628 | * |
| 4629 | * Where XX is the length in characeters of the windowTitle. |
| 4630 | * |
| 4631 | * The first parameter is the target window. The window with the specified hashcode |
| 4632 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4633 | * will be delivered to the target window and as parameters to the command itself. |
| 4634 | * |
| 4635 | * @param client The remote client to sent the result, if any, to. |
| 4636 | * @param command The command to execute. |
| 4637 | * @param parameters The command parameters. |
| 4638 | * |
| 4639 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4640 | * not indicate whether the command itself was successful. |
| 4641 | */ |
| 4642 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4643 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | return false; |
| 4645 | } |
| 4646 | |
| 4647 | boolean success = true; |
| 4648 | Parcel data = null; |
| 4649 | Parcel reply = null; |
| 4650 | |
| 4651 | // Any uncaught exception will crash the system process |
| 4652 | try { |
| 4653 | // Find the hashcode of the window |
| 4654 | int index = parameters.indexOf(' '); |
| 4655 | if (index == -1) { |
| 4656 | index = parameters.length(); |
| 4657 | } |
| 4658 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4659 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | |
| 4661 | // Extract the command's parameter after the window description |
| 4662 | if (index < parameters.length()) { |
| 4663 | parameters = parameters.substring(index + 1); |
| 4664 | } else { |
| 4665 | parameters = ""; |
| 4666 | } |
| 4667 | |
| 4668 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4669 | if (window == null) { |
| 4670 | return false; |
| 4671 | } |
| 4672 | |
| 4673 | data = Parcel.obtain(); |
| 4674 | data.writeInterfaceToken("android.view.IWindow"); |
| 4675 | data.writeString(command); |
| 4676 | data.writeString(parameters); |
| 4677 | data.writeInt(1); |
| 4678 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4679 | |
| 4680 | reply = Parcel.obtain(); |
| 4681 | |
| 4682 | final IBinder binder = window.mClient.asBinder(); |
| 4683 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4684 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4685 | |
| 4686 | reply.readException(); |
| 4687 | |
| 4688 | } catch (Exception e) { |
| 4689 | Log.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| 4690 | success = false; |
| 4691 | } finally { |
| 4692 | if (data != null) { |
| 4693 | data.recycle(); |
| 4694 | } |
| 4695 | if (reply != null) { |
| 4696 | reply.recycle(); |
| 4697 | } |
| 4698 | } |
| 4699 | |
| 4700 | return success; |
| 4701 | } |
| 4702 | |
| 4703 | private WindowState findWindow(int hashCode) { |
| 4704 | if (hashCode == -1) { |
| 4705 | return getFocusedWindow(); |
| 4706 | } |
| 4707 | |
| 4708 | synchronized (mWindowMap) { |
| 4709 | final ArrayList windows = mWindows; |
| 4710 | final int count = windows.size(); |
| 4711 | |
| 4712 | for (int i = 0; i < count; i++) { |
| 4713 | WindowState w = (WindowState) windows.get(i); |
| 4714 | if (System.identityHashCode(w) == hashCode) { |
| 4715 | return w; |
| 4716 | } |
| 4717 | } |
| 4718 | } |
| 4719 | |
| 4720 | return null; |
| 4721 | } |
| 4722 | |
| 4723 | /* |
| 4724 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4725 | * that to config-changed listeners if appropriate. |
| 4726 | */ |
| 4727 | void sendNewConfiguration() { |
| 4728 | try { |
| 4729 | mActivityManager.updateConfiguration(null); |
| 4730 | } catch (RemoteException e) { |
| 4731 | } |
| 4732 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4734 | public Configuration computeNewConfiguration() { |
| 4735 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4736 | return computeNewConfigurationLocked(); |
| 4737 | } |
| 4738 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4739 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4740 | Configuration computeNewConfigurationLocked() { |
| 4741 | Configuration config = new Configuration(); |
| 4742 | if (!computeNewConfigurationLocked(config)) { |
| 4743 | return null; |
| 4744 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4745 | return config; |
| 4746 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4747 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4748 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4749 | if (mDisplay == null) { |
| 4750 | return false; |
| 4751 | } |
| 4752 | mQueue.getInputConfiguration(config); |
| 4753 | final int dw = mDisplay.getWidth(); |
| 4754 | final int dh = mDisplay.getHeight(); |
| 4755 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4756 | if (dw < dh) { |
| 4757 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4758 | } else if (dw > dh) { |
| 4759 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4760 | } |
| 4761 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4762 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4763 | DisplayMetrics dm = new DisplayMetrics(); |
| 4764 | mDisplay.getMetrics(dm); |
| 4765 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4766 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4767 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4768 | // Note we only do this once because at this point we don't |
| 4769 | // expect the screen to change in this way at runtime, and want |
| 4770 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4771 | int longSize = dw; |
| 4772 | int shortSize = dh; |
| 4773 | if (longSize < shortSize) { |
| 4774 | int tmp = longSize; |
| 4775 | longSize = shortSize; |
| 4776 | shortSize = tmp; |
| 4777 | } |
| 4778 | longSize = (int)(longSize/dm.density); |
| 4779 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4780 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4781 | // These semi-magic numbers define our compatibility modes for |
| 4782 | // applications with different screens. Don't change unless you |
| 4783 | // make sure to test lots and lots of apps! |
| 4784 | if (longSize < 470) { |
| 4785 | // This is shorter than an HVGA normal density screen (which |
| 4786 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4787 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4788 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4789 | } else { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4790 | // Is this a large screen? |
| 4791 | if (longSize > 640 && shortSize >= 480) { |
| 4792 | // VGA or larger screens at medium density are the point |
| 4793 | // at which we consider it to be a large screen. |
| 4794 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4795 | } else { |
| 4796 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4797 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4798 | // If this screen is wider than normal HVGA, or taller |
| 4799 | // than FWVGA, then for old apps we want to run in size |
| 4800 | // compatibility mode. |
| 4801 | if (shortSize > 321 || longSize > 570) { |
| 4802 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4803 | } |
| 4804 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4805 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4806 | // Is this a long screen? |
| 4807 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4808 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4809 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4810 | } else { |
| 4811 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4812 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4813 | } |
| 4814 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4815 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4816 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4817 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4818 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4819 | mPolicy.adjustConfigurationLw(config); |
| 4820 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4821 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4823 | // ------------------------------------------------------------- |
| 4824 | // Input Events and Focus Management |
| 4825 | // ------------------------------------------------------------- |
| 4826 | |
| 4827 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4828 | long curTime = SystemClock.uptimeMillis(); |
| 4829 | |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4830 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4831 | if (mLastTouchEventType == eventType && |
| 4832 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4833 | return; |
| 4834 | } |
| 4835 | mLastUserActivityCallTime = curTime; |
| 4836 | mLastTouchEventType = eventType; |
| 4837 | } |
| 4838 | |
| 4839 | if (targetWin == null |
| 4840 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4841 | mPowerManager.userActivity(curTime, false, eventType, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | // tells if it's a cheek event or not -- this function is stateful |
| 4846 | private static final int EVENT_NONE = 0; |
| 4847 | private static final int EVENT_UNKNOWN = 0; |
| 4848 | private static final int EVENT_CHEEK = 0; |
| 4849 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4850 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4851 | private int mEventState = EVENT_NONE; |
| 4852 | private float mEventSize; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4854 | private int eventType(MotionEvent ev) { |
| 4855 | float size = ev.getSize(); |
| 4856 | switch (ev.getAction()) { |
| 4857 | case MotionEvent.ACTION_DOWN: |
| 4858 | mEventSize = size; |
| 4859 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4860 | case MotionEvent.ACTION_UP: |
| 4861 | if (size > mEventSize) mEventSize = size; |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4862 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4863 | case MotionEvent.ACTION_MOVE: |
| 4864 | final int N = ev.getHistorySize(); |
| 4865 | if (size > mEventSize) mEventSize = size; |
| 4866 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4867 | for (int i=0; i<N; i++) { |
| 4868 | size = ev.getHistoricalSize(i); |
| 4869 | if (size > mEventSize) mEventSize = size; |
| 4870 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4871 | } |
| 4872 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4873 | return TOUCH_EVENT; |
| 4874 | } else { |
Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4875 | return LONG_TOUCH_EVENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4876 | } |
| 4877 | default: |
| 4878 | // not good |
| 4879 | return OTHER_EVENT; |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | /** |
| 4884 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4885 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4886 | 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] | 4887 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, |
| 4888 | "dispatchPointer " + ev); |
| 4889 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4890 | if (MEASURE_LATENCY) { |
| 4891 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 4892 | } |
| 4893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4894 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4895 | ev, true, false, pid, uid); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4896 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4897 | if (MEASURE_LATENCY) { |
| 4898 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 4899 | } |
| 4900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4901 | int action = ev.getAction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4903 | if (action == MotionEvent.ACTION_UP) { |
| 4904 | // let go of our target |
| 4905 | mKeyWaiter.mMotionTarget = null; |
| 4906 | mPowerManager.logPointerUpEvent(); |
| 4907 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 4908 | mPowerManager.logPointerDownEvent(); |
| 4909 | } |
| 4910 | |
| 4911 | if (targetObj == null) { |
| 4912 | // In this case we are either dropping the event, or have received |
| 4913 | // a move or up without a down. It is common to receive move |
| 4914 | // events in such a way, since this means the user is moving the |
| 4915 | // pointer without actually pressing down. All other cases should |
| 4916 | // be atypical, so let's log them. |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4917 | if (action != MotionEvent.ACTION_MOVE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4918 | Log.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| 4919 | } |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 4920 | synchronized (mWindowMap) { |
| 4921 | if (mSendingPointersToWallpaper) { |
| 4922 | Log.i(TAG, "Sending skipped pointer to wallpaper!"); |
| 4923 | sendPointerToWallpaperLocked(null, ev, ev.getEventTime()); |
| 4924 | } |
| 4925 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4926 | if (qev != null) { |
| 4927 | mQueue.recycleEvent(qev); |
| 4928 | } |
| 4929 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4930 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4931 | } |
| 4932 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 4933 | synchronized (mWindowMap) { |
| 4934 | if (mSendingPointersToWallpaper) { |
| 4935 | Log.i(TAG, "Sending skipped pointer to wallpaper!"); |
| 4936 | sendPointerToWallpaperLocked(null, ev, ev.getEventTime()); |
| 4937 | } |
| 4938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4939 | if (qev != null) { |
| 4940 | mQueue.recycleEvent(qev); |
| 4941 | } |
| 4942 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4943 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4944 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4946 | WindowState target = (WindowState)targetObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4948 | final long eventTime = ev.getEventTime(); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4949 | final long eventTimeNano = ev.getEventTimeNano(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4951 | //Log.i(TAG, "Sending " + ev + " to " + target); |
| 4952 | |
| 4953 | if (uid != 0 && uid != target.mSession.mUid) { |
| 4954 | if (mContext.checkPermission( |
| 4955 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 4956 | != PackageManager.PERMISSION_GRANTED) { |
| 4957 | Log.w(TAG, "Permission denied: injecting pointer event from pid " |
| 4958 | + pid + " uid " + uid + " to window " + target |
| 4959 | + " owned by uid " + target.mSession.mUid); |
| 4960 | if (qev != null) { |
| 4961 | mQueue.recycleEvent(qev); |
| 4962 | } |
| 4963 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4964 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4965 | } |
| 4966 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4967 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4968 | if (MEASURE_LATENCY) { |
| 4969 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 4970 | } |
| 4971 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4972 | if ((target.mAttrs.flags & |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4973 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 4974 | //target wants to ignore fat touch events |
| 4975 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 4976 | //explicit flag to return without processing event further |
| 4977 | boolean returnFlag = false; |
| 4978 | if((action == MotionEvent.ACTION_DOWN)) { |
| 4979 | mFatTouch = false; |
| 4980 | if(cheekPress) { |
| 4981 | mFatTouch = true; |
| 4982 | returnFlag = true; |
| 4983 | } |
| 4984 | } else { |
| 4985 | if(action == MotionEvent.ACTION_UP) { |
| 4986 | if(mFatTouch) { |
| 4987 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 4988 | mFatTouch = false; |
| 4989 | returnFlag = true; |
| 4990 | } else if(cheekPress) { |
| 4991 | //cancel the earlier event |
| 4992 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 4993 | action = MotionEvent.ACTION_CANCEL; |
| 4994 | } |
| 4995 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 4996 | if(mFatTouch) { |
| 4997 | //two cases here |
| 4998 | //an invalid down followed by 0 or moves(valid or invalid) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4999 | //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] | 5000 | returnFlag = true; |
| 5001 | } else if(cheekPress) { |
| 5002 | //valid down followed by invalid moves |
| 5003 | //an invalid move have to cancel earlier action |
| 5004 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5005 | action = MotionEvent.ACTION_CANCEL; |
| 5006 | if (DEBUG_INPUT) Log.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| 5007 | //note that the subsequent invalid moves will not get here |
| 5008 | mFatTouch = true; |
| 5009 | } |
| 5010 | } |
| 5011 | } //else if action |
| 5012 | if(returnFlag) { |
| 5013 | //recycle que, ev |
| 5014 | if (qev != null) { |
| 5015 | mQueue.recycleEvent(qev); |
| 5016 | } |
| 5017 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5018 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5019 | } |
| 5020 | } //end if target |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5021 | |
Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 5022 | // Enable this for testing the "right" value |
| 5023 | if (false && action == MotionEvent.ACTION_DOWN) { |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5024 | int max_events_per_sec = 35; |
| 5025 | try { |
| 5026 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 5027 | .get("windowsmgr.max_events_per_sec")); |
| 5028 | if (max_events_per_sec < 1) { |
| 5029 | max_events_per_sec = 35; |
| 5030 | } |
| 5031 | } catch (NumberFormatException e) { |
| 5032 | } |
| 5033 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 5034 | } |
| 5035 | |
| 5036 | /* |
| 5037 | * Throttle events to minimize CPU usage when there's a flood of events |
| 5038 | * e.g. constant contact with the screen |
| 5039 | */ |
| 5040 | if (action == MotionEvent.ACTION_MOVE) { |
| 5041 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 5042 | long now = SystemClock.uptimeMillis(); |
| 5043 | if (now < nextEventTime) { |
| 5044 | try { |
| 5045 | Thread.sleep(nextEventTime - now); |
| 5046 | } catch (InterruptedException e) { |
| 5047 | } |
| 5048 | mLastTouchEventTime = nextEventTime; |
| 5049 | } else { |
| 5050 | mLastTouchEventTime = now; |
| 5051 | } |
| 5052 | } |
| 5053 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5054 | if (MEASURE_LATENCY) { |
| 5055 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5056 | } |
| 5057 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5058 | synchronized(mWindowMap) { |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5059 | if (!target.isVisibleLw()) { |
| 5060 | // During this motion dispatch, the target window has become |
| 5061 | // invisible. |
| 5062 | if (mSendingPointersToWallpaper) { |
| 5063 | sendPointerToWallpaperLocked(null, ev, eventTime); |
| 5064 | } |
| 5065 | if (qev != null) { |
| 5066 | mQueue.recycleEvent(qev); |
| 5067 | } |
| 5068 | ev.recycle(); |
| 5069 | return INJECT_SUCCEEDED; |
| 5070 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5072 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 5073 | mKeyWaiter.bindTargetWindowLocked(target, |
| 5074 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 5075 | ev = null; |
| 5076 | } else { |
| 5077 | if (action == MotionEvent.ACTION_DOWN) { |
| 5078 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 5079 | if (out != null) { |
| 5080 | MotionEvent oev = MotionEvent.obtain(ev); |
| 5081 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 5082 | do { |
| 5083 | final Rect frame = out.mFrame; |
| 5084 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5085 | try { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5086 | out.mClient.dispatchPointer(oev, eventTime, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5087 | } catch (android.os.RemoteException e) { |
| 5088 | Log.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| 5089 | } |
| 5090 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 5091 | out = out.mNextOutsideTouch; |
| 5092 | } while (out != null); |
| 5093 | mKeyWaiter.mOutsideTouchTargets = null; |
| 5094 | } |
| 5095 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5096 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5097 | // If we are on top of the wallpaper, then the wallpaper also |
| 5098 | // gets to see this movement. |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 5099 | if ((mWallpaperTarget == target && |
| 5100 | target.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) |
| 5101 | || mSendingPointersToWallpaper) { |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5102 | sendPointerToWallpaperLocked(null, ev, eventTime); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5103 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5104 | |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5105 | final Rect frame = target.mFrame; |
| 5106 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5107 | mKeyWaiter.bindTargetWindowLocked(target); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5108 | } |
| 5109 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5111 | // finally offset the event to the target's coordinate system and |
| 5112 | // dispatch the event. |
| 5113 | try { |
| 5114 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| 5115 | Log.v(TAG, "Delivering pointer " + qev + " to " + target); |
| 5116 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5117 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5118 | if (MEASURE_LATENCY) { |
| 5119 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5120 | } |
| 5121 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5122 | target.mClient.dispatchPointer(ev, eventTime, true); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5123 | |
| 5124 | if (MEASURE_LATENCY) { |
| 5125 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5126 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5127 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5128 | } catch (android.os.RemoteException e) { |
| 5129 | Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| 5130 | mKeyWaiter.mMotionTarget = null; |
| 5131 | try { |
| 5132 | removeWindow(target.mSession, target.mClient); |
| 5133 | } catch (java.util.NoSuchElementException ex) { |
| 5134 | // This will happen if the window has already been |
| 5135 | // removed. |
| 5136 | } |
| 5137 | } |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5138 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5141 | /** |
| 5142 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5143 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5144 | 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] | 5145 | if (DEBUG_INPUT) Log.v( |
| 5146 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5148 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5149 | ev, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5150 | if (focusObj == null) { |
| 5151 | Log.w(TAG, "No focus window, dropping trackball: " + ev); |
| 5152 | if (qev != null) { |
| 5153 | mQueue.recycleEvent(qev); |
| 5154 | } |
| 5155 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5156 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5157 | } |
| 5158 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 5159 | if (qev != null) { |
| 5160 | mQueue.recycleEvent(qev); |
| 5161 | } |
| 5162 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5163 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5164 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5166 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5168 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5169 | if (mContext.checkPermission( |
| 5170 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5171 | != PackageManager.PERMISSION_GRANTED) { |
| 5172 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5173 | + pid + " uid " + uid + " to window " + focus |
| 5174 | + " owned by uid " + focus.mSession.mUid); |
| 5175 | if (qev != null) { |
| 5176 | mQueue.recycleEvent(qev); |
| 5177 | } |
| 5178 | ev.recycle(); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5179 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5180 | } |
| 5181 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | final long eventTime = ev.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | synchronized(mWindowMap) { |
| 5186 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5187 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5188 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5189 | // We don't deliver movement events to the client, we hold |
| 5190 | // them and wait for them to call back. |
| 5191 | ev = null; |
| 5192 | } else { |
| 5193 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5194 | } |
| 5195 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5197 | try { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5198 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5199 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5200 | } catch (android.os.RemoteException e) { |
| 5201 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5202 | try { |
| 5203 | removeWindow(focus.mSession, focus.mClient); |
| 5204 | } catch (java.util.NoSuchElementException ex) { |
| 5205 | // This will happen if the window has already been |
| 5206 | // removed. |
| 5207 | } |
| 5208 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5209 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5210 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5213 | /** |
| 5214 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5215 | */ |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5216 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5217 | if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event); |
| 5218 | |
| 5219 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5220 | null, false, false, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5221 | if (focusObj == null) { |
| 5222 | Log.w(TAG, "No focus window, dropping: " + event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5223 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5224 | } |
| 5225 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5226 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5227 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5228 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5229 | // Okay we have finished waiting for the last event to be processed. |
| 5230 | // First off, if this is a repeat event, check to see if there is |
| 5231 | // a corresponding up event in the queue. If there is, we will |
| 5232 | // just drop the repeat, because it makes no sense to repeat after |
| 5233 | // the user has released a key. (This is especially important for |
| 5234 | // long presses.) |
| 5235 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5236 | return INJECT_SUCCEEDED; |
| 5237 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5239 | WindowState focus = (WindowState)focusObj; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5241 | if (DEBUG_INPUT) Log.v( |
| 5242 | TAG, "Dispatching to " + focus + ": " + event); |
| 5243 | |
| 5244 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5245 | if (mContext.checkPermission( |
| 5246 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5247 | != PackageManager.PERMISSION_GRANTED) { |
| 5248 | Log.w(TAG, "Permission denied: injecting key event from pid " |
| 5249 | + pid + " uid " + uid + " to window " + focus |
| 5250 | + " owned by uid " + focus.mSession.mUid); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5251 | return INJECT_NO_PERMISSION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5252 | } |
| 5253 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5255 | synchronized(mWindowMap) { |
| 5256 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5257 | } |
| 5258 | |
| 5259 | // NOSHIP extra state logging |
| 5260 | mKeyWaiter.recordDispatchState(event, focus); |
| 5261 | // END NOSHIP |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5263 | try { |
| 5264 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| 5265 | Log.v(TAG, "Delivering key " + event.getKeyCode() |
| 5266 | + " to " + focus); |
| 5267 | } |
| 5268 | focus.mClient.dispatchKey(event); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5269 | return INJECT_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5270 | } catch (android.os.RemoteException e) { |
| 5271 | Log.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| 5272 | try { |
| 5273 | removeWindow(focus.mSession, focus.mClient); |
| 5274 | } catch (java.util.NoSuchElementException ex) { |
| 5275 | // This will happen if the window has already been |
| 5276 | // removed. |
| 5277 | } |
| 5278 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5279 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5280 | return INJECT_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5283 | public void pauseKeyDispatching(IBinder _token) { |
| 5284 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5285 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5286 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | synchronized (mWindowMap) { |
| 5290 | WindowToken token = mTokenMap.get(_token); |
| 5291 | if (token != null) { |
| 5292 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5293 | } |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | public void resumeKeyDispatching(IBinder _token) { |
| 5298 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5299 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5300 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | synchronized (mWindowMap) { |
| 5304 | WindowToken token = mTokenMap.get(_token); |
| 5305 | if (token != null) { |
| 5306 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5307 | } |
| 5308 | } |
| 5309 | } |
| 5310 | |
| 5311 | public void setEventDispatching(boolean enabled) { |
| 5312 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5313 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5314 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | synchronized (mWindowMap) { |
| 5318 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5319 | } |
| 5320 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5322 | /** |
| 5323 | * Injects a keystroke event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5324 | * |
| 5325 | * @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] | 5326 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5327 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5328 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5329 | */ |
| 5330 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5331 | long downTime = ev.getDownTime(); |
| 5332 | long eventTime = ev.getEventTime(); |
| 5333 | |
| 5334 | int action = ev.getAction(); |
| 5335 | int code = ev.getKeyCode(); |
| 5336 | int repeatCount = ev.getRepeatCount(); |
| 5337 | int metaState = ev.getMetaState(); |
| 5338 | int deviceId = ev.getDeviceId(); |
| 5339 | int scancode = ev.getScanCode(); |
| 5340 | |
| 5341 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5342 | if (downTime == 0) downTime = eventTime; |
| 5343 | |
| 5344 | 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] | 5345 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5346 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5347 | final int pid = Binder.getCallingPid(); |
| 5348 | final int uid = Binder.getCallingUid(); |
| 5349 | final long ident = Binder.clearCallingIdentity(); |
| 5350 | final int result = dispatchKey(newEvent, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5352 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5353 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5354 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5355 | switch (result) { |
| 5356 | case INJECT_NO_PERMISSION: |
| 5357 | throw new SecurityException( |
| 5358 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5359 | case INJECT_SUCCEEDED: |
| 5360 | return true; |
| 5361 | } |
| 5362 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | /** |
| 5366 | * Inject a pointer (touch) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5367 | * |
| 5368 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5369 | * {@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] | 5370 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5371 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5372 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5373 | */ |
| 5374 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5375 | final int pid = Binder.getCallingPid(); |
| 5376 | final int uid = Binder.getCallingUid(); |
| 5377 | final long ident = Binder.clearCallingIdentity(); |
| 5378 | final int result = dispatchPointer(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5379 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5380 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5382 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5383 | switch (result) { |
| 5384 | case INJECT_NO_PERMISSION: |
| 5385 | throw new SecurityException( |
| 5386 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5387 | case INJECT_SUCCEEDED: |
| 5388 | return true; |
| 5389 | } |
| 5390 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5391 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | /** |
| 5394 | * Inject a trackball (navigation device) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5395 | * |
| 5396 | * @param ev A motion event describing the trackball action. (As noted in |
| 5397 | * {@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] | 5398 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5399 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5400 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5401 | */ |
| 5402 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5403 | final int pid = Binder.getCallingPid(); |
| 5404 | final int uid = Binder.getCallingUid(); |
| 5405 | final long ident = Binder.clearCallingIdentity(); |
| 5406 | final int result = dispatchTrackball(null, ev, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5407 | if (sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5408 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5409 | } |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5410 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5411 | switch (result) { |
| 5412 | case INJECT_NO_PERMISSION: |
| 5413 | throw new SecurityException( |
| 5414 | "Injecting to another application requires INJECT_EVENT permission"); |
| 5415 | case INJECT_SUCCEEDED: |
| 5416 | return true; |
| 5417 | } |
| 5418 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5419 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5421 | private WindowState getFocusedWindow() { |
| 5422 | synchronized (mWindowMap) { |
| 5423 | return getFocusedWindowLocked(); |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | private WindowState getFocusedWindowLocked() { |
| 5428 | return mCurrentFocus; |
| 5429 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5431 | /** |
| 5432 | * This class holds the state for dispatching key events. This state |
| 5433 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 5434 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 5435 | * but not the other way around. |
| 5436 | */ |
| 5437 | final class KeyWaiter { |
| 5438 | // NOSHIP debugging |
| 5439 | public class DispatchState { |
| 5440 | private KeyEvent event; |
| 5441 | private WindowState focus; |
| 5442 | private long time; |
| 5443 | private WindowState lastWin; |
| 5444 | private IBinder lastBinder; |
| 5445 | private boolean finished; |
| 5446 | private boolean gotFirstWindow; |
| 5447 | private boolean eventDispatching; |
| 5448 | private long timeToSwitch; |
| 5449 | private boolean wasFrozen; |
| 5450 | private boolean focusPaused; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5451 | private WindowState curFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5453 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5454 | focus = theFocus; |
| 5455 | event = theEvent; |
| 5456 | time = System.currentTimeMillis(); |
| 5457 | // snapshot KeyWaiter state |
| 5458 | lastWin = mLastWin; |
| 5459 | lastBinder = mLastBinder; |
| 5460 | finished = mFinished; |
| 5461 | gotFirstWindow = mGotFirstWindow; |
| 5462 | eventDispatching = mEventDispatching; |
| 5463 | timeToSwitch = mTimeToSwitch; |
| 5464 | wasFrozen = mWasFrozen; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5465 | curFocus = mCurrentFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5466 | // cache the paused state at ctor time as well |
| 5467 | if (theFocus == null || theFocus.mToken == null) { |
| 5468 | Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!"); |
| 5469 | focusPaused = false; |
| 5470 | } else { |
| 5471 | focusPaused = theFocus.mToken.paused; |
| 5472 | } |
| 5473 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | public String toString() { |
| 5476 | return "{{" + event + " to " + focus + " @ " + time |
| 5477 | + " lw=" + lastWin + " lb=" + lastBinder |
| 5478 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 5479 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5480 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| 5481 | + " mcf=" + mCurrentFocus + "}}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5482 | } |
| 5483 | }; |
| 5484 | private DispatchState mDispatchState = null; |
| 5485 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5486 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 5487 | } |
| 5488 | // END NOSHIP |
| 5489 | |
| 5490 | public static final int RETURN_NOTHING = 0; |
| 5491 | public static final int RETURN_PENDING_POINTER = 1; |
| 5492 | public static final int RETURN_PENDING_TRACKBALL = 2; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5494 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 5495 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5497 | private WindowState mLastWin = null; |
| 5498 | private IBinder mLastBinder = null; |
| 5499 | private boolean mFinished = true; |
| 5500 | private boolean mGotFirstWindow = false; |
| 5501 | private boolean mEventDispatching = true; |
| 5502 | private long mTimeToSwitch = 0; |
| 5503 | /* package */ boolean mWasFrozen = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | // Target of Motion events |
| 5506 | WindowState mMotionTarget; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5508 | // Windows above the target who would like to receive an "outside" |
| 5509 | // touch event for any down events outside of them. |
| 5510 | WindowState mOutsideTouchTargets; |
| 5511 | |
| 5512 | /** |
| 5513 | * Wait for the last event dispatch to complete, then find the next |
| 5514 | * target that should receive the given event and wait for that one |
| 5515 | * to be ready to receive it. |
| 5516 | */ |
| 5517 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5518 | MotionEvent nextMotion, boolean isPointerEvent, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5519 | boolean failIfTimeout, int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5520 | long startTime = SystemClock.uptimeMillis(); |
| 5521 | long keyDispatchingTimeout = 5 * 1000; |
| 5522 | long waitedFor = 0; |
| 5523 | |
| 5524 | while (true) { |
| 5525 | // Figure out which window we care about. It is either the |
| 5526 | // last window we are waiting to have process the event or, |
| 5527 | // if none, then the next window we think the event should go |
| 5528 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5529 | // it may change before we lock. Thus we must check it again. |
| 5530 | WindowState targetWin = mLastWin; |
| 5531 | boolean targetIsNew = targetWin == null; |
| 5532 | if (DEBUG_INPUT) Log.v( |
| 5533 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5534 | ", mLastWin=" + mLastWin); |
| 5535 | if (targetIsNew) { |
| 5536 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5537 | isPointerEvent, callingPid, callingUid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5538 | if (target == SKIP_TARGET_TOKEN) { |
| 5539 | // The user has pressed a special key, and we are |
| 5540 | // dropping all pending events before it. |
| 5541 | if (DEBUG_INPUT) Log.v(TAG, "Skipping: " + nextKey |
| 5542 | + " " + nextMotion); |
| 5543 | return null; |
| 5544 | } |
| 5545 | if (target == CONSUMED_EVENT_TOKEN) { |
| 5546 | if (DEBUG_INPUT) Log.v(TAG, "Consumed: " + nextKey |
| 5547 | + " " + nextMotion); |
| 5548 | return target; |
| 5549 | } |
| 5550 | targetWin = (WindowState)target; |
| 5551 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5553 | AppWindowToken targetApp = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5555 | // Now: is it okay to send the next event to this window? |
| 5556 | synchronized (this) { |
| 5557 | // First: did we come here based on the last window not |
| 5558 | // being null, but it changed by the time we got here? |
| 5559 | // If so, try again. |
| 5560 | if (!targetIsNew && mLastWin == null) { |
| 5561 | continue; |
| 5562 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5564 | // We never dispatch events if not finished with the |
| 5565 | // last one, or the display is frozen. |
| 5566 | if (mFinished && !mDisplayFrozen) { |
| 5567 | // If event dispatching is disabled, then we |
| 5568 | // just consume the events. |
| 5569 | if (!mEventDispatching) { |
| 5570 | if (DEBUG_INPUT) Log.v(TAG, |
| 5571 | "Skipping event; dispatching disabled: " |
| 5572 | + nextKey + " " + nextMotion); |
| 5573 | return null; |
| 5574 | } |
| 5575 | if (targetWin != null) { |
| 5576 | // If this is a new target, and that target is not |
| 5577 | // paused or unresponsive, then all looks good to |
| 5578 | // handle the event. |
| 5579 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5580 | return targetWin; |
| 5581 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5583 | // If we didn't find a target window, and there is no |
| 5584 | // focused app window, then just eat the events. |
| 5585 | } else if (mFocusedApp == null) { |
| 5586 | if (DEBUG_INPUT) Log.v(TAG, |
| 5587 | "Skipping event; no focused app: " |
| 5588 | + nextKey + " " + nextMotion); |
| 5589 | return null; |
| 5590 | } |
| 5591 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5593 | if (DEBUG_INPUT) Log.v( |
| 5594 | TAG, "Waiting for last key in " + mLastBinder |
| 5595 | + " target=" + targetWin |
| 5596 | + " mFinished=" + mFinished |
| 5597 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5598 | + " targetIsNew=" + targetIsNew |
| 5599 | + " paused=" |
| 5600 | + (targetWin != null ? targetWin.mToken.paused : false) |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5601 | + " mFocusedApp=" + mFocusedApp |
| 5602 | + " mCurrentFocus=" + mCurrentFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5604 | targetApp = targetWin != null |
| 5605 | ? targetWin.mAppToken : mFocusedApp; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5607 | long curTimeout = keyDispatchingTimeout; |
| 5608 | if (mTimeToSwitch != 0) { |
| 5609 | long now = SystemClock.uptimeMillis(); |
| 5610 | if (mTimeToSwitch <= now) { |
| 5611 | // If an app switch key has been pressed, and we have |
| 5612 | // waited too long for the current app to finish |
| 5613 | // processing keys, then wait no more! |
| 5614 | doFinishedKeyLocked(true); |
| 5615 | continue; |
| 5616 | } |
| 5617 | long switchTimeout = mTimeToSwitch - now; |
| 5618 | if (curTimeout > switchTimeout) { |
| 5619 | curTimeout = switchTimeout; |
| 5620 | } |
| 5621 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5623 | try { |
| 5624 | // after that continue |
| 5625 | // processing keys, so we don't get stuck. |
| 5626 | if (DEBUG_INPUT) Log.v( |
| 5627 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5628 | wait(curTimeout); |
| 5629 | if (DEBUG_INPUT) Log.v(TAG, "Finished waiting @" |
| 5630 | + SystemClock.uptimeMillis() + " startTime=" |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5631 | + startTime + " switchTime=" + mTimeToSwitch |
| 5632 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5633 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5634 | + " mCurrentFocus=" + mCurrentFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5635 | } catch (InterruptedException e) { |
| 5636 | } |
| 5637 | } |
| 5638 | |
| 5639 | // If we were frozen during configuration change, restart the |
| 5640 | // timeout checks from now; otherwise look at whether we timed |
| 5641 | // out before awakening. |
| 5642 | if (mWasFrozen) { |
| 5643 | waitedFor = 0; |
| 5644 | mWasFrozen = false; |
| 5645 | } else { |
| 5646 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5647 | } |
| 5648 | |
| 5649 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5650 | IApplicationToken at = null; |
| 5651 | synchronized (this) { |
| 5652 | Log.w(TAG, "Key dispatching timed out sending to " + |
| 5653 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| 5654 | : "<null>")); |
| 5655 | // NOSHIP debugging |
| 5656 | Log.w(TAG, "Dispatch state: " + mDispatchState); |
| 5657 | Log.w(TAG, "Current state: " + new DispatchState(nextKey, targetWin)); |
| 5658 | // END NOSHIP |
| 5659 | //dump(); |
| 5660 | if (targetWin != null) { |
| 5661 | at = targetWin.getAppToken(); |
| 5662 | } else if (targetApp != null) { |
| 5663 | at = targetApp.appToken; |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | boolean abort = true; |
| 5668 | if (at != null) { |
| 5669 | try { |
| 5670 | long timeout = at.getKeyDispatchingTimeout(); |
| 5671 | if (timeout > waitedFor) { |
| 5672 | // we did not wait the proper amount of time for this application. |
| 5673 | // set the timeout to be the real timeout and wait again. |
| 5674 | keyDispatchingTimeout = timeout - waitedFor; |
| 5675 | continue; |
| 5676 | } else { |
| 5677 | abort = at.keyDispatchingTimedOut(); |
| 5678 | } |
| 5679 | } catch (RemoteException ex) { |
| 5680 | } |
| 5681 | } |
| 5682 | |
| 5683 | synchronized (this) { |
| 5684 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5685 | mFinished = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5686 | if (mLastWin != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5687 | if (DEBUG_INPUT) Log.v(TAG, |
| 5688 | "Window " + mLastWin + |
| 5689 | " timed out on key input"); |
| 5690 | if (mLastWin.mToken.paused) { |
| 5691 | Log.w(TAG, "Un-pausing dispatching to this window"); |
| 5692 | mLastWin.mToken.paused = false; |
| 5693 | } |
| 5694 | } |
| 5695 | if (mMotionTarget == targetWin) { |
| 5696 | mMotionTarget = null; |
| 5697 | } |
| 5698 | mLastWin = null; |
| 5699 | mLastBinder = null; |
| 5700 | if (failIfTimeout || targetWin == null) { |
| 5701 | return null; |
| 5702 | } |
| 5703 | } else { |
| 5704 | Log.w(TAG, "Continuing to wait for key to be dispatched"); |
| 5705 | startTime = SystemClock.uptimeMillis(); |
| 5706 | } |
| 5707 | } |
| 5708 | } |
| 5709 | } |
| 5710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5712 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5713 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5714 | int callingPid, int callingUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | mOutsideTouchTargets = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5717 | if (nextKey != null) { |
| 5718 | // Find the target window for a normal key event. |
| 5719 | final int keycode = nextKey.getKeyCode(); |
| 5720 | final int repeatCount = nextKey.getRepeatCount(); |
| 5721 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5722 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5724 | if (!dispatch) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5725 | if (callingUid == 0 || |
| 5726 | mContext.checkPermission( |
| 5727 | android.Manifest.permission.INJECT_EVENTS, |
| 5728 | callingPid, callingUid) |
| 5729 | == PackageManager.PERMISSION_GRANTED) { |
| 5730 | mPolicy.interceptKeyTi(null, keycode, |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5731 | nextKey.getMetaState(), down, repeatCount, |
| 5732 | nextKey.getFlags()); |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5733 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5734 | Log.w(TAG, "Event timeout during app switch: dropping " |
| 5735 | + nextKey); |
| 5736 | return SKIP_TARGET_TOKEN; |
| 5737 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5739 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5741 | WindowState focus = null; |
| 5742 | synchronized(mWindowMap) { |
| 5743 | focus = getFocusedWindowLocked(); |
| 5744 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5746 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5747 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5748 | if (callingUid == 0 || |
| 5749 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5750 | mContext.checkPermission( |
| 5751 | android.Manifest.permission.INJECT_EVENTS, |
| 5752 | callingPid, callingUid) |
| 5753 | == PackageManager.PERMISSION_GRANTED) { |
| 5754 | if (mPolicy.interceptKeyTi(focus, |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5755 | keycode, nextKey.getMetaState(), down, repeatCount, |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5756 | nextKey.getFlags())) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5757 | return CONSUMED_EVENT_TOKEN; |
| 5758 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5759 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5760 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5761 | return focus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5763 | } else if (!isPointerEvent) { |
| 5764 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5765 | if (!dispatch) { |
| 5766 | Log.w(TAG, "Event timeout during app switch: dropping trackball " |
| 5767 | + nextMotion); |
| 5768 | return SKIP_TARGET_TOKEN; |
| 5769 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | WindowState focus = null; |
| 5772 | synchronized(mWindowMap) { |
| 5773 | focus = getFocusedWindowLocked(); |
| 5774 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5776 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5777 | return focus; |
| 5778 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5780 | if (nextMotion == null) { |
| 5781 | return SKIP_TARGET_TOKEN; |
| 5782 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5784 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5785 | KeyEvent.KEYCODE_UNKNOWN); |
| 5786 | if (!dispatch) { |
| 5787 | Log.w(TAG, "Event timeout during app switch: dropping pointer " |
| 5788 | + nextMotion); |
| 5789 | return SKIP_TARGET_TOKEN; |
| 5790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5792 | // Find the target window for a pointer event. |
| 5793 | int action = nextMotion.getAction(); |
| 5794 | final float xf = nextMotion.getX(); |
| 5795 | final float yf = nextMotion.getY(); |
| 5796 | final long eventTime = nextMotion.getEventTime(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5798 | final boolean screenWasOff = qev != null |
| 5799 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | WindowState target = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | synchronized(mWindowMap) { |
| 5804 | synchronized (this) { |
| 5805 | if (action == MotionEvent.ACTION_DOWN) { |
| 5806 | if (mMotionTarget != null) { |
| 5807 | // this is weird, we got a pen down, but we thought it was |
| 5808 | // already down! |
| 5809 | // XXX: We should probably send an ACTION_UP to the current |
| 5810 | // target. |
| 5811 | Log.w(TAG, "Pointer down received while already down in: " |
| 5812 | + mMotionTarget); |
| 5813 | mMotionTarget = null; |
| 5814 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5815 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5816 | // ACTION_DOWN is special, because we need to lock next events to |
| 5817 | // the window we'll land onto. |
| 5818 | final int x = (int)xf; |
| 5819 | final int y = (int)yf; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5820 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5821 | final ArrayList windows = mWindows; |
| 5822 | final int N = windows.size(); |
| 5823 | WindowState topErrWindow = null; |
| 5824 | final Rect tmpRect = mTempRect; |
| 5825 | for (int i=N-1; i>=0; i--) { |
| 5826 | WindowState child = (WindowState)windows.get(i); |
| 5827 | //Log.i(TAG, "Checking dispatch to: " + child); |
| 5828 | final int flags = child.mAttrs.flags; |
| 5829 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5830 | if (topErrWindow == null) { |
| 5831 | topErrWindow = child; |
| 5832 | } |
| 5833 | } |
| 5834 | if (!child.isVisibleLw()) { |
| 5835 | //Log.i(TAG, "Not visible!"); |
| 5836 | continue; |
| 5837 | } |
| 5838 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 5839 | //Log.i(TAG, "Not touchable!"); |
| 5840 | if ((flags & WindowManager.LayoutParams |
| 5841 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5842 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5843 | mOutsideTouchTargets = child; |
| 5844 | } |
| 5845 | continue; |
| 5846 | } |
| 5847 | tmpRect.set(child.mFrame); |
| 5848 | if (child.mTouchableInsets == ViewTreeObserver |
| 5849 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5850 | // The touch is inside of the window if it is |
| 5851 | // inside the frame, AND the content part of that |
| 5852 | // frame that was given by the application. |
| 5853 | tmpRect.left += child.mGivenContentInsets.left; |
| 5854 | tmpRect.top += child.mGivenContentInsets.top; |
| 5855 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5856 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5857 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5858 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5859 | // The touch is inside of the window if it is |
| 5860 | // inside the frame, AND the visible part of that |
| 5861 | // frame that was given by the application. |
| 5862 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5863 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5864 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5865 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5866 | } |
| 5867 | final int touchFlags = flags & |
| 5868 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5869 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5870 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 5871 | //Log.i(TAG, "Using this target!"); |
| 5872 | if (!screenWasOff || (flags & |
| 5873 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5874 | mMotionTarget = child; |
| 5875 | } else { |
| 5876 | //Log.i(TAG, "Waking, skip!"); |
| 5877 | mMotionTarget = null; |
| 5878 | } |
| 5879 | break; |
| 5880 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5882 | if ((flags & WindowManager.LayoutParams |
| 5883 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5884 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5885 | mOutsideTouchTargets = child; |
| 5886 | //Log.i(TAG, "Adding to outside target list: " + child); |
| 5887 | } |
| 5888 | } |
| 5889 | |
| 5890 | // if there's an error window but it's not accepting |
| 5891 | // focus (typically because it is not yet visible) just |
| 5892 | // wait for it -- any other focused window may in fact |
| 5893 | // be in ANR state. |
| 5894 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5895 | mMotionTarget = null; |
| 5896 | } |
| 5897 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | target = mMotionTarget; |
| 5900 | } |
| 5901 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5903 | wakeupIfNeeded(target, eventType(nextMotion)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5905 | // Pointer events are a little different -- if there isn't a |
| 5906 | // target found for any event, then just drop it. |
| 5907 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 5908 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5910 | boolean checkShouldDispatchKey(int keycode) { |
| 5911 | synchronized (this) { |
| 5912 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 5913 | mTimeToSwitch = 0; |
| 5914 | return true; |
| 5915 | } |
| 5916 | if (mTimeToSwitch != 0 |
| 5917 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 5918 | return false; |
| 5919 | } |
| 5920 | return true; |
| 5921 | } |
| 5922 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5924 | void bindTargetWindowLocked(WindowState win, |
| 5925 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5926 | synchronized (this) { |
| 5927 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 5928 | } |
| 5929 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | void bindTargetWindowLocked(WindowState win) { |
| 5932 | synchronized (this) { |
| 5933 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | void bindTargetWindowLockedLocked(WindowState win, |
| 5938 | int pendingWhat, QueuedEvent pendingMotion) { |
| 5939 | mLastWin = win; |
| 5940 | mLastBinder = win.mClient.asBinder(); |
| 5941 | mFinished = false; |
| 5942 | if (pendingMotion != null) { |
| 5943 | final Session s = win.mSession; |
| 5944 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 5945 | releasePendingPointerLocked(s); |
| 5946 | s.mPendingPointerMove = pendingMotion; |
| 5947 | s.mPendingPointerWindow = win; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5948 | if (DEBUG_INPUT) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5949 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 5950 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 5951 | releasePendingTrackballLocked(s); |
| 5952 | s.mPendingTrackballMove = pendingMotion; |
| 5953 | s.mPendingTrackballWindow = win; |
| 5954 | } |
| 5955 | } |
| 5956 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5958 | void releasePendingPointerLocked(Session s) { |
| 5959 | if (DEBUG_INPUT) Log.v(TAG, |
| 5960 | "releasePendingPointer " + s.mPendingPointerMove); |
| 5961 | if (s.mPendingPointerMove != null) { |
| 5962 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 5963 | s.mPendingPointerMove = null; |
| 5964 | } |
| 5965 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5967 | void releasePendingTrackballLocked(Session s) { |
| 5968 | if (s.mPendingTrackballMove != null) { |
| 5969 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 5970 | s.mPendingTrackballMove = null; |
| 5971 | } |
| 5972 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5973 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5974 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 5975 | int returnWhat) { |
| 5976 | if (DEBUG_INPUT) Log.v( |
| 5977 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 5978 | |
| 5979 | if (client == null) { |
| 5980 | return null; |
| 5981 | } |
| 5982 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5983 | MotionEvent res = null; |
| 5984 | QueuedEvent qev = null; |
| 5985 | WindowState win = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5987 | synchronized (this) { |
| 5988 | if (DEBUG_INPUT) Log.v( |
| 5989 | TAG, "finishedKey: client=" + client.asBinder() |
| 5990 | + ", force=" + force + ", last=" + mLastBinder |
| 5991 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 5992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5993 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 5994 | qev = session.mPendingPointerMove; |
| 5995 | win = session.mPendingPointerWindow; |
| 5996 | session.mPendingPointerMove = null; |
| 5997 | session.mPendingPointerWindow = null; |
| 5998 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 5999 | qev = session.mPendingTrackballMove; |
| 6000 | win = session.mPendingTrackballWindow; |
| 6001 | session.mPendingTrackballMove = null; |
| 6002 | session.mPendingTrackballWindow = null; |
| 6003 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6005 | if (mLastBinder == client.asBinder()) { |
| 6006 | if (DEBUG_INPUT) Log.v( |
| 6007 | TAG, "finishedKey: last paused=" |
| 6008 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 6009 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 6010 | || !mEventDispatching)) { |
| 6011 | doFinishedKeyLocked(false); |
| 6012 | } else { |
| 6013 | // Make sure to wake up anyone currently waiting to |
| 6014 | // dispatch a key, so they can re-evaluate their |
| 6015 | // current situation. |
| 6016 | mFinished = true; |
| 6017 | notifyAll(); |
| 6018 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6019 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6021 | if (qev != null) { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6022 | res = (MotionEvent)qev.event; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6023 | if (DEBUG_INPUT) Log.v(TAG, |
| 6024 | "Returning pending motion: " + res); |
| 6025 | mQueue.recycleEvent(qev); |
| 6026 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6027 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 6028 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6029 | } |
Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6030 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6031 | |
Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6032 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6033 | synchronized (mWindowMap) { |
| 6034 | if ((mWallpaperTarget == win && |
| 6035 | win.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) |
| 6036 | || mSendingPointersToWallpaper) { |
| 6037 | sendPointerToWallpaperLocked(win, res, res.getEventTime()); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6038 | } |
| 6039 | } |
| 6040 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6041 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6042 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | void tickle() { |
| 6046 | synchronized (this) { |
| 6047 | notifyAll(); |
| 6048 | } |
| 6049 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6051 | void handleNewWindowLocked(WindowState newWindow) { |
| 6052 | if (!newWindow.canReceiveKeys()) { |
| 6053 | return; |
| 6054 | } |
| 6055 | synchronized (this) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6056 | if (DEBUG_INPUT) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6057 | TAG, "New key dispatch window: win=" |
| 6058 | + newWindow.mClient.asBinder() |
| 6059 | + ", last=" + mLastBinder |
| 6060 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6061 | + "), finished=" + mFinished + ", paused=" |
| 6062 | + newWindow.mToken.paused); |
| 6063 | |
| 6064 | // Displaying a window implicitly causes dispatching to |
| 6065 | // be unpaused. (This is to protect against bugs if someone |
| 6066 | // pauses dispatching but forgets to resume.) |
| 6067 | newWindow.mToken.paused = false; |
| 6068 | |
| 6069 | mGotFirstWindow = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6070 | |
| 6071 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 6072 | if (DEBUG_INPUT) Log.v(TAG, |
| 6073 | "New SYSTEM_ERROR window; resetting state"); |
| 6074 | mLastWin = null; |
| 6075 | mLastBinder = null; |
| 6076 | mMotionTarget = null; |
| 6077 | mFinished = true; |
| 6078 | } else if (mLastWin != null) { |
| 6079 | // If the new window is above the window we are |
| 6080 | // waiting on, then stop waiting and let key dispatching |
| 6081 | // start on the new guy. |
| 6082 | if (DEBUG_INPUT) Log.v( |
| 6083 | TAG, "Last win layer=" + mLastWin.mLayer |
| 6084 | + ", new win layer=" + newWindow.mLayer); |
| 6085 | if (newWindow.mLayer >= mLastWin.mLayer) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6086 | // The new window is above the old; finish pending input to the last |
| 6087 | // window and start directing it to the new one. |
| 6088 | mLastWin.mToken.paused = false; |
| 6089 | doFinishedKeyLocked(true); // does a notifyAll() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6090 | } |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6091 | // Either the new window is lower, so there is no need to wake key waiters, |
| 6092 | // or we just finished key input to the previous window, which implicitly |
| 6093 | // notified the key waiters. In both cases, we don't need to issue the |
| 6094 | // notification here. |
| 6095 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6096 | } |
| 6097 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6098 | // Now that we've put a new window state in place, make the event waiter |
| 6099 | // take notice and retarget its attentions. |
| 6100 | notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | } |
| 6102 | } |
| 6103 | |
| 6104 | void pauseDispatchingLocked(WindowToken token) { |
| 6105 | synchronized (this) |
| 6106 | { |
| 6107 | if (DEBUG_INPUT) Log.v(TAG, "Pausing WindowToken " + token); |
| 6108 | token.paused = true; |
| 6109 | |
| 6110 | /* |
| 6111 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 6112 | mPaused = true; |
| 6113 | } else { |
| 6114 | if (mLastWin == null) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6115 | 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] | 6116 | } else if (mFinished) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6117 | 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] | 6118 | } else { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6119 | 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] | 6120 | } |
| 6121 | } |
| 6122 | */ |
| 6123 | } |
| 6124 | } |
| 6125 | |
| 6126 | void resumeDispatchingLocked(WindowToken token) { |
| 6127 | synchronized (this) { |
| 6128 | if (token.paused) { |
| 6129 | if (DEBUG_INPUT) Log.v( |
| 6130 | TAG, "Resuming WindowToken " + token |
| 6131 | + ", last=" + mLastBinder |
| 6132 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6133 | + "), finished=" + mFinished + ", paused=" |
| 6134 | + token.paused); |
| 6135 | token.paused = false; |
| 6136 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| 6137 | doFinishedKeyLocked(true); |
| 6138 | } else { |
| 6139 | notifyAll(); |
| 6140 | } |
| 6141 | } |
| 6142 | } |
| 6143 | } |
| 6144 | |
| 6145 | void setEventDispatchingLocked(boolean enabled) { |
| 6146 | synchronized (this) { |
| 6147 | mEventDispatching = enabled; |
| 6148 | notifyAll(); |
| 6149 | } |
| 6150 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6152 | void appSwitchComing() { |
| 6153 | synchronized (this) { |
| 6154 | // Don't wait for more than .5 seconds for app to finish |
| 6155 | // processing the pending events. |
| 6156 | long now = SystemClock.uptimeMillis() + 500; |
| 6157 | if (DEBUG_INPUT) Log.v(TAG, "appSwitchComing: " + now); |
| 6158 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 6159 | mTimeToSwitch = now; |
| 6160 | } |
| 6161 | notifyAll(); |
| 6162 | } |
| 6163 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6165 | private final void doFinishedKeyLocked(boolean doRecycle) { |
| 6166 | if (mLastWin != null) { |
| 6167 | releasePendingPointerLocked(mLastWin.mSession); |
| 6168 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6169 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6171 | if (mLastWin == null || !mLastWin.mToken.paused |
| 6172 | || !mLastWin.isVisibleLw()) { |
| 6173 | // If the current window has been paused, we aren't -really- |
| 6174 | // finished... so let the waiters still wait. |
| 6175 | mLastWin = null; |
| 6176 | mLastBinder = null; |
| 6177 | } |
| 6178 | mFinished = true; |
| 6179 | notifyAll(); |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | private class KeyQ extends KeyInputQueue |
| 6184 | implements KeyInputQueue.FilterCallback { |
| 6185 | PowerManager.WakeLock mHoldingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6187 | KeyQ() { |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6188 | super(mContext, WindowManagerService.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6189 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 6190 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 6191 | "KEEP_SCREEN_ON_FLAG"); |
| 6192 | mHoldingScreen.setReferenceCounted(false); |
| 6193 | } |
| 6194 | |
| 6195 | @Override |
| 6196 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6197 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6198 | return true; |
| 6199 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6201 | switch (event.type) { |
| 6202 | case RawInputEvent.EV_KEY: { |
| 6203 | // XXX begin hack |
| 6204 | if (DEBUG) { |
| 6205 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6206 | if (event.value != 0) { |
| 6207 | // G down |
| 6208 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6209 | } |
| 6210 | return false; |
| 6211 | } |
| 6212 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6213 | if (event.value != 0) { |
| 6214 | //dump(); |
| 6215 | } |
| 6216 | return false; |
| 6217 | } |
| 6218 | } |
| 6219 | // XXX end hack |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6220 | |
Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6221 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6222 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6223 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6225 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6226 | mPowerManager.goToSleep(event.when); |
| 6227 | } |
| 6228 | |
| 6229 | if (screenIsOff) { |
| 6230 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6231 | } |
| 6232 | if (screenIsDim) { |
| 6233 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6234 | } |
| 6235 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6236 | mPowerManager.userActivity(event.when, false, |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6237 | LocalPowerManager.BUTTON_EVENT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6238 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6240 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6241 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6242 | filterQueue(this); |
| 6243 | mKeyWaiter.appSwitchComing(); |
| 6244 | } |
| 6245 | return true; |
| 6246 | } else { |
| 6247 | return false; |
| 6248 | } |
| 6249 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | case RawInputEvent.EV_REL: { |
Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6252 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6253 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | if (screenIsOff) { |
| 6255 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6256 | device.classes, event)) { |
| 6257 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6258 | return false; |
| 6259 | } |
| 6260 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6261 | } |
| 6262 | if (screenIsDim) { |
| 6263 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6264 | } |
| 6265 | return true; |
| 6266 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | case RawInputEvent.EV_ABS: { |
Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6269 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6270 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6271 | if (screenIsOff) { |
| 6272 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6273 | device.classes, event)) { |
| 6274 | //Log.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| 6275 | return false; |
| 6276 | } |
| 6277 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6278 | } |
| 6279 | if (screenIsDim) { |
| 6280 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6281 | } |
| 6282 | return true; |
| 6283 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | default: |
| 6286 | return true; |
| 6287 | } |
| 6288 | } |
| 6289 | |
| 6290 | public int filterEvent(QueuedEvent ev) { |
| 6291 | switch (ev.classType) { |
| 6292 | case RawInputEvent.CLASS_KEYBOARD: |
| 6293 | KeyEvent ke = (KeyEvent)ev.event; |
| 6294 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| 6295 | Log.w(TAG, "Dropping movement key during app switch: " |
| 6296 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6297 | return FILTER_REMOVE; |
| 6298 | } |
| 6299 | return FILTER_ABORT; |
| 6300 | default: |
| 6301 | return FILTER_KEEP; |
| 6302 | } |
| 6303 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6305 | /** |
| 6306 | * Must be called with the main window manager lock held. |
| 6307 | */ |
| 6308 | void setHoldScreenLocked(boolean holding) { |
| 6309 | boolean state = mHoldingScreen.isHeld(); |
| 6310 | if (holding != state) { |
| 6311 | if (holding) { |
| 6312 | mHoldingScreen.acquire(); |
| 6313 | } else { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6314 | mPolicy.screenOnStoppedLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | mHoldingScreen.release(); |
| 6316 | } |
| 6317 | } |
| 6318 | } |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6319 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6320 | |
| 6321 | public boolean detectSafeMode() { |
| 6322 | mSafeMode = mPolicy.detectSafeMode(); |
| 6323 | return mSafeMode; |
| 6324 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6326 | public void systemReady() { |
| 6327 | mPolicy.systemReady(); |
| 6328 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6330 | private final class InputDispatcherThread extends Thread { |
| 6331 | // Time to wait when there is nothing to do: 9999 seconds. |
| 6332 | static final int LONG_WAIT=9999*1000; |
| 6333 | |
| 6334 | public InputDispatcherThread() { |
| 6335 | super("InputDispatcher"); |
| 6336 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6338 | @Override |
| 6339 | public void run() { |
| 6340 | while (true) { |
| 6341 | try { |
| 6342 | process(); |
| 6343 | } catch (Exception e) { |
| 6344 | Log.e(TAG, "Exception in input dispatcher", e); |
| 6345 | } |
| 6346 | } |
| 6347 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6349 | private void process() { |
| 6350 | android.os.Process.setThreadPriority( |
| 6351 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6353 | // The last key event we saw |
| 6354 | KeyEvent lastKey = null; |
| 6355 | |
| 6356 | // Last keydown time for auto-repeating keys |
| 6357 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 6358 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6359 | long downTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6361 | // How many successive repeats we generated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6362 | int keyRepeatCount = 0; |
| 6363 | |
| 6364 | // Need to report that configuration has changed? |
| 6365 | boolean configChanged = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | while (true) { |
| 6368 | long curTime = SystemClock.uptimeMillis(); |
| 6369 | |
| 6370 | if (DEBUG_INPUT) Log.v( |
| 6371 | TAG, "Waiting for next key: now=" + curTime |
| 6372 | + ", repeat @ " + nextKeyTime); |
| 6373 | |
| 6374 | // Retrieve next event, waiting only as long as the next |
| 6375 | // repeat timeout. If the configuration has changed, then |
| 6376 | // don't wait at all -- we'll report the change as soon as |
| 6377 | // we have processed all events. |
| 6378 | QueuedEvent ev = mQueue.getEvent( |
| 6379 | (int)((!configChanged && curTime < nextKeyTime) |
| 6380 | ? (nextKeyTime-curTime) : 0)); |
| 6381 | |
| 6382 | if (DEBUG_INPUT && ev != null) Log.v( |
| 6383 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 6384 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6385 | if (MEASURE_LATENCY) { |
| 6386 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 6387 | } |
| 6388 | |
Mike Lockwood | 3d0ea72 | 2009-10-21 22:58:29 -0400 | [diff] [blame] | 6389 | if (lastKey != null && !mPolicy.allowKeyRepeat()) { |
| 6390 | // cancel key repeat at the request of the policy. |
| 6391 | lastKey = null; |
| 6392 | downTime = 0; |
| 6393 | lastKeyTime = curTime; |
| 6394 | nextKeyTime = curTime + LONG_WAIT; |
| 6395 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6396 | try { |
| 6397 | if (ev != null) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6398 | curTime = SystemClock.uptimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6399 | int eventType; |
| 6400 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 6401 | eventType = eventType((MotionEvent)ev.event); |
| 6402 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 6403 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 6404 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 6405 | } else { |
| 6406 | eventType = LocalPowerManager.OTHER_EVENT; |
| 6407 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6408 | try { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6409 | if ((curTime - mLastBatteryStatsCallTime) |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6410 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6411 | mLastBatteryStatsCallTime = curTime; |
Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6412 | mBatteryStats.noteInputEvent(); |
| 6413 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6414 | } catch (RemoteException e) { |
| 6415 | // Ignore |
| 6416 | } |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6417 | |
Mike Lockwood | 5db4240 | 2009-11-30 14:51:51 -0500 | [diff] [blame] | 6418 | if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) { |
| 6419 | // do not wake screen in this case |
| 6420 | } else if (eventType != TOUCH_EVENT |
Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6421 | && eventType != LONG_TOUCH_EVENT |
| 6422 | && eventType != CHEEK_EVENT) { |
| 6423 | mPowerManager.userActivity(curTime, false, |
| 6424 | eventType, false); |
| 6425 | } else if (mLastTouchEventType != eventType |
| 6426 | || (curTime - mLastUserActivityCallTime) |
| 6427 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 6428 | mLastUserActivityCallTime = curTime; |
| 6429 | mLastTouchEventType = eventType; |
| 6430 | mPowerManager.userActivity(curTime, false, |
| 6431 | eventType, false); |
| 6432 | } |
| 6433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | switch (ev.classType) { |
| 6435 | case RawInputEvent.CLASS_KEYBOARD: |
| 6436 | KeyEvent ke = (KeyEvent)ev.event; |
| 6437 | if (ke.isDown()) { |
| 6438 | lastKey = ke; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6439 | downTime = curTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6440 | keyRepeatCount = 0; |
| 6441 | lastKeyTime = curTime; |
| 6442 | nextKeyTime = lastKeyTime |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6443 | + ViewConfiguration.getLongPressTimeout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6444 | if (DEBUG_INPUT) Log.v( |
| 6445 | TAG, "Received key down: first repeat @ " |
| 6446 | + nextKeyTime); |
| 6447 | } else { |
| 6448 | lastKey = null; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6449 | downTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6450 | // Arbitrary long timeout. |
| 6451 | lastKeyTime = curTime; |
| 6452 | nextKeyTime = curTime + LONG_WAIT; |
| 6453 | if (DEBUG_INPUT) Log.v( |
| 6454 | TAG, "Received key up: ignore repeat @ " |
| 6455 | + nextKeyTime); |
| 6456 | } |
| 6457 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 6458 | mQueue.recycleEvent(ev); |
| 6459 | break; |
| 6460 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| 6461 | //Log.i(TAG, "Read next event " + ev); |
| 6462 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 6463 | break; |
| 6464 | case RawInputEvent.CLASS_TRACKBALL: |
| 6465 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 6466 | break; |
| 6467 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 6468 | configChanged = true; |
| 6469 | break; |
| 6470 | default: |
| 6471 | mQueue.recycleEvent(ev); |
| 6472 | break; |
| 6473 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6475 | } else if (configChanged) { |
| 6476 | configChanged = false; |
| 6477 | sendNewConfiguration(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6479 | } else if (lastKey != null) { |
| 6480 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | // Timeout occurred while key was down. If it is at or |
| 6483 | // past the key repeat time, dispatch the repeat. |
| 6484 | if (DEBUG_INPUT) Log.v( |
| 6485 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 6486 | + ", now=" + curTime); |
| 6487 | if (curTime < nextKeyTime) { |
| 6488 | continue; |
| 6489 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6491 | lastKeyTime = nextKeyTime; |
| 6492 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 6493 | keyRepeatCount++; |
| 6494 | if (DEBUG_INPUT) Log.v( |
| 6495 | TAG, "Key repeat: count=" + keyRepeatCount |
| 6496 | + ", next @ " + nextKeyTime); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6497 | KeyEvent newEvent; |
| 6498 | if (downTime != 0 && (downTime |
| 6499 | + ViewConfiguration.getLongPressTimeout()) |
| 6500 | <= curTime) { |
| 6501 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6502 | curTime, keyRepeatCount, |
| 6503 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6504 | downTime = 0; |
| 6505 | } else { |
| 6506 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6507 | curTime, keyRepeatCount); |
| 6508 | } |
| 6509 | dispatchKey(newEvent, 0, 0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6511 | } else { |
| 6512 | curTime = SystemClock.uptimeMillis(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6514 | lastKeyTime = curTime; |
| 6515 | nextKeyTime = curTime + LONG_WAIT; |
| 6516 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6518 | } catch (Exception e) { |
| 6519 | Log.e(TAG, |
| 6520 | "Input thread received uncaught exception: " + e, e); |
| 6521 | } |
| 6522 | } |
| 6523 | } |
| 6524 | } |
| 6525 | |
| 6526 | // ------------------------------------------------------------- |
| 6527 | // Client Session State |
| 6528 | // ------------------------------------------------------------- |
| 6529 | |
| 6530 | private final class Session extends IWindowSession.Stub |
| 6531 | implements IBinder.DeathRecipient { |
| 6532 | final IInputMethodClient mClient; |
| 6533 | final IInputContext mInputContext; |
| 6534 | final int mUid; |
| 6535 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6536 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6537 | SurfaceSession mSurfaceSession; |
| 6538 | int mNumWindow = 0; |
| 6539 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6541 | /** |
| 6542 | * Current pointer move event being dispatched to client window... must |
| 6543 | * hold key lock to access. |
| 6544 | */ |
| 6545 | QueuedEvent mPendingPointerMove; |
| 6546 | WindowState mPendingPointerWindow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6548 | /** |
| 6549 | * Current trackball move event being dispatched to client window... must |
| 6550 | * hold key lock to access. |
| 6551 | */ |
| 6552 | QueuedEvent mPendingTrackballMove; |
| 6553 | WindowState mPendingTrackballWindow; |
| 6554 | |
| 6555 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6556 | mClient = client; |
| 6557 | mInputContext = inputContext; |
| 6558 | mUid = Binder.getCallingUid(); |
| 6559 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6560 | StringBuilder sb = new StringBuilder(); |
| 6561 | sb.append("Session{"); |
| 6562 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6563 | sb.append(" uid "); |
| 6564 | sb.append(mUid); |
| 6565 | sb.append("}"); |
| 6566 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6568 | synchronized (mWindowMap) { |
| 6569 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6570 | IBinder b = ServiceManager.getService( |
| 6571 | Context.INPUT_METHOD_SERVICE); |
| 6572 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6573 | } |
| 6574 | } |
| 6575 | long ident = Binder.clearCallingIdentity(); |
| 6576 | try { |
| 6577 | // Note: it is safe to call in to the input method manager |
| 6578 | // here because we are not holding our lock. |
| 6579 | if (mInputMethodManager != null) { |
| 6580 | mInputMethodManager.addClient(client, inputContext, |
| 6581 | mUid, mPid); |
| 6582 | } else { |
| 6583 | client.setUsingInputMethod(false); |
| 6584 | } |
| 6585 | client.asBinder().linkToDeath(this, 0); |
| 6586 | } catch (RemoteException e) { |
| 6587 | // The caller has died, so we can just forget about this. |
| 6588 | try { |
| 6589 | if (mInputMethodManager != null) { |
| 6590 | mInputMethodManager.removeClient(client); |
| 6591 | } |
| 6592 | } catch (RemoteException ee) { |
| 6593 | } |
| 6594 | } finally { |
| 6595 | Binder.restoreCallingIdentity(ident); |
| 6596 | } |
| 6597 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6599 | @Override |
| 6600 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6601 | throws RemoteException { |
| 6602 | try { |
| 6603 | return super.onTransact(code, data, reply, flags); |
| 6604 | } catch (RuntimeException e) { |
| 6605 | // Log all 'real' exceptions thrown to the caller |
| 6606 | if (!(e instanceof SecurityException)) { |
| 6607 | Log.e(TAG, "Window Session Crash", e); |
| 6608 | } |
| 6609 | throw e; |
| 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | public void binderDied() { |
| 6614 | // Note: it is safe to call in to the input method manager |
| 6615 | // here because we are not holding our lock. |
| 6616 | try { |
| 6617 | if (mInputMethodManager != null) { |
| 6618 | mInputMethodManager.removeClient(mClient); |
| 6619 | } |
| 6620 | } catch (RemoteException e) { |
| 6621 | } |
| 6622 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6623 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | mClientDead = true; |
| 6625 | killSessionLocked(); |
| 6626 | } |
| 6627 | } |
| 6628 | |
| 6629 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6630 | int viewVisibility, Rect outContentInsets) { |
| 6631 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6632 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6634 | public void remove(IWindow window) { |
| 6635 | removeWindow(this, window); |
| 6636 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6638 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6639 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6640 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| 6641 | Rect outVisibleInsets, Surface outSurface) { |
| 6642 | return relayoutWindow(this, window, attrs, |
| 6643 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| 6644 | outFrame, outContentInsets, outVisibleInsets, outSurface); |
| 6645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | public void setTransparentRegion(IWindow window, Region region) { |
| 6648 | setTransparentRegionWindow(this, window, region); |
| 6649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6651 | public void setInsets(IWindow window, int touchableInsets, |
| 6652 | Rect contentInsets, Rect visibleInsets) { |
| 6653 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6654 | visibleInsets); |
| 6655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6658 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6659 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6661 | public void finishDrawing(IWindow window) { |
| 6662 | if (localLOGV) Log.v( |
| 6663 | TAG, "IWindow finishDrawing called for " + window); |
| 6664 | finishDrawingWindow(this, window); |
| 6665 | } |
| 6666 | |
| 6667 | public void finishKey(IWindow window) { |
| 6668 | if (localLOGV) Log.v( |
| 6669 | TAG, "IWindow finishKey called for " + window); |
| 6670 | mKeyWaiter.finishedKey(this, window, false, |
| 6671 | KeyWaiter.RETURN_NOTHING); |
| 6672 | } |
| 6673 | |
| 6674 | public MotionEvent getPendingPointerMove(IWindow window) { |
| 6675 | if (localLOGV) Log.v( |
| 6676 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6677 | return mKeyWaiter.finishedKey(this, window, false, |
| 6678 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6679 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6681 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| 6682 | if (localLOGV) Log.v( |
| 6683 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6684 | return mKeyWaiter.finishedKey(this, window, false, |
| 6685 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6686 | } |
| 6687 | |
| 6688 | public void setInTouchMode(boolean mode) { |
| 6689 | synchronized(mWindowMap) { |
| 6690 | mInTouchMode = mode; |
| 6691 | } |
| 6692 | } |
| 6693 | |
| 6694 | public boolean getInTouchMode() { |
| 6695 | synchronized(mWindowMap) { |
| 6696 | return mInTouchMode; |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6701 | boolean always) { |
| 6702 | synchronized(mWindowMap) { |
| 6703 | long ident = Binder.clearCallingIdentity(); |
| 6704 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6705 | return mPolicy.performHapticFeedbackLw( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6706 | windowForClientLocked(this, window), effectId, always); |
| 6707 | } finally { |
| 6708 | Binder.restoreCallingIdentity(ident); |
| 6709 | } |
| 6710 | } |
| 6711 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6712 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6713 | 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] | 6714 | synchronized(mWindowMap) { |
| 6715 | long ident = Binder.clearCallingIdentity(); |
| 6716 | try { |
| 6717 | setWindowWallpaperPositionLocked(windowForClientLocked(this, window), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6718 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6719 | } finally { |
| 6720 | Binder.restoreCallingIdentity(ident); |
| 6721 | } |
| 6722 | } |
| 6723 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6724 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6725 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6726 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6727 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6728 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6729 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6730 | int z, Bundle extras, boolean sync) { |
| 6731 | synchronized(mWindowMap) { |
| 6732 | long ident = Binder.clearCallingIdentity(); |
| 6733 | try { |
| 6734 | return sendWindowWallpaperCommandLocked( |
| 6735 | windowForClientLocked(this, window), |
| 6736 | action, x, y, z, extras, sync); |
| 6737 | } finally { |
| 6738 | Binder.restoreCallingIdentity(ident); |
| 6739 | } |
| 6740 | } |
| 6741 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6742 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6743 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6744 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6745 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | void windowAddedLocked() { |
| 6748 | if (mSurfaceSession == null) { |
| 6749 | if (localLOGV) Log.v( |
| 6750 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6751 | mSurfaceSession = new SurfaceSession(); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6752 | if (SHOW_TRANSACTIONS) Log.i( |
| 6753 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6754 | mSessions.add(this); |
| 6755 | } |
| 6756 | mNumWindow++; |
| 6757 | } |
| 6758 | |
| 6759 | void windowRemovedLocked() { |
| 6760 | mNumWindow--; |
| 6761 | killSessionLocked(); |
| 6762 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6764 | void killSessionLocked() { |
| 6765 | if (mNumWindow <= 0 && mClientDead) { |
| 6766 | mSessions.remove(this); |
| 6767 | if (mSurfaceSession != null) { |
| 6768 | if (localLOGV) Log.v( |
| 6769 | TAG, "Last window removed from " + this |
| 6770 | + ", destroying " + mSurfaceSession); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6771 | if (SHOW_TRANSACTIONS) Log.i( |
| 6772 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | try { |
| 6774 | mSurfaceSession.kill(); |
| 6775 | } catch (Exception e) { |
| 6776 | Log.w(TAG, "Exception thrown when killing surface session " |
| 6777 | + mSurfaceSession + " in session " + this |
| 6778 | + ": " + e.toString()); |
| 6779 | } |
| 6780 | mSurfaceSession = null; |
| 6781 | } |
| 6782 | } |
| 6783 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6785 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6786 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6787 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6788 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6789 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6790 | pw.print(prefix); |
| 6791 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6792 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6793 | } |
| 6794 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6795 | pw.print(prefix); |
| 6796 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6797 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6798 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6799 | } |
| 6800 | |
| 6801 | @Override |
| 6802 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6803 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | } |
| 6805 | } |
| 6806 | |
| 6807 | // ------------------------------------------------------------- |
| 6808 | // Client Window State |
| 6809 | // ------------------------------------------------------------- |
| 6810 | |
| 6811 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6812 | final Session mSession; |
| 6813 | final IWindow mClient; |
| 6814 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6815 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6816 | AppWindowToken mAppToken; |
| 6817 | AppWindowToken mTargetAppToken; |
| 6818 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6819 | final DeathRecipient mDeathRecipient; |
| 6820 | final WindowState mAttachedWindow; |
| 6821 | final ArrayList mChildWindows = new ArrayList(); |
| 6822 | final int mBaseLayer; |
| 6823 | final int mSubLayer; |
| 6824 | final boolean mLayoutAttached; |
| 6825 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6826 | final boolean mIsWallpaper; |
| 6827 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6828 | int mViewVisibility; |
| 6829 | boolean mPolicyVisibility = true; |
| 6830 | boolean mPolicyVisibilityAfterAnim = true; |
| 6831 | boolean mAppFreezing; |
| 6832 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6833 | boolean mReportDestroySurface; |
| 6834 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6835 | boolean mAttachedHidden; // is our parent window hidden? |
| 6836 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6837 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6838 | int mRequestedWidth; |
| 6839 | int mRequestedHeight; |
| 6840 | int mLastRequestedWidth; |
| 6841 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6842 | int mLayer; |
| 6843 | int mAnimLayer; |
| 6844 | int mLastLayer; |
| 6845 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6846 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6847 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | |
| 6849 | WindowState mNextOutsideTouch; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6851 | // Actual frame shown on-screen (may be modified by animation) |
| 6852 | final Rect mShownFrame = new Rect(); |
| 6853 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6855 | /** |
| 6856 | * Insets that determine the actually visible area |
| 6857 | */ |
| 6858 | final Rect mVisibleInsets = new Rect(); |
| 6859 | final Rect mLastVisibleInsets = new Rect(); |
| 6860 | boolean mVisibleInsetsChanged; |
| 6861 | |
| 6862 | /** |
| 6863 | * Insets that are covered by system windows |
| 6864 | */ |
| 6865 | final Rect mContentInsets = new Rect(); |
| 6866 | final Rect mLastContentInsets = new Rect(); |
| 6867 | boolean mContentInsetsChanged; |
| 6868 | |
| 6869 | /** |
| 6870 | * Set to true if we are waiting for this window to receive its |
| 6871 | * given internal insets before laying out other windows based on it. |
| 6872 | */ |
| 6873 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | /** |
| 6876 | * These are the content insets that were given during layout for |
| 6877 | * this window, to be applied to windows behind it. |
| 6878 | */ |
| 6879 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6881 | /** |
| 6882 | * These are the visible insets that were given during layout for |
| 6883 | * this window, to be applied to windows behind it. |
| 6884 | */ |
| 6885 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6887 | /** |
| 6888 | * Flag indicating whether the touchable region should be adjusted by |
| 6889 | * the visible insets; if false the area outside the visible insets is |
| 6890 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6891 | * tests. |
| 6892 | */ |
| 6893 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6894 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6895 | // Current transformation being applied. |
| 6896 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6897 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6898 | float mHScale=1, mVScale=1; |
| 6899 | float mLastHScale=1, mLastVScale=1; |
| 6900 | final Matrix mTmpMatrix = new Matrix(); |
| 6901 | |
| 6902 | // "Real" frame that the application sees. |
| 6903 | final Rect mFrame = new Rect(); |
| 6904 | final Rect mLastFrame = new Rect(); |
| 6905 | |
| 6906 | final Rect mContainingFrame = new Rect(); |
| 6907 | final Rect mDisplayFrame = new Rect(); |
| 6908 | final Rect mContentFrame = new Rect(); |
| 6909 | final Rect mVisibleFrame = new Rect(); |
| 6910 | |
| 6911 | float mShownAlpha = 1; |
| 6912 | float mAlpha = 1; |
| 6913 | float mLastAlpha = 1; |
| 6914 | |
| 6915 | // Set to true if, when the window gets displayed, it should perform |
| 6916 | // an enter animation. |
| 6917 | boolean mEnterAnimationPending; |
| 6918 | |
| 6919 | // Currently running animation. |
| 6920 | boolean mAnimating; |
| 6921 | boolean mLocalAnimating; |
| 6922 | Animation mAnimation; |
| 6923 | boolean mAnimationIsEntrance; |
| 6924 | boolean mHasTransformation; |
| 6925 | boolean mHasLocalTransformation; |
| 6926 | final Transformation mTransformation = new Transformation(); |
| 6927 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6928 | // If a window showing a wallpaper: the requested offset for the |
| 6929 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6930 | float mWallpaperX = -1; |
| 6931 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6932 | |
| 6933 | // If a window showing a wallpaper: what fraction of the offset |
| 6934 | // range corresponds to a full virtual screen. |
| 6935 | float mWallpaperXStep = -1; |
| 6936 | float mWallpaperYStep = -1; |
| 6937 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6938 | // Wallpaper windows: pixels offset based on above variables. |
| 6939 | int mXOffset; |
| 6940 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6942 | // This is set after IWindowSession.relayout() has been called at |
| 6943 | // least once for the window. It allows us to detect the situation |
| 6944 | // where we don't yet have a surface, but should have one soon, so |
| 6945 | // we can give the window focus before waiting for the relayout. |
| 6946 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | // This is set after the Surface has been created but before the |
| 6949 | // window has been drawn. During this time the surface is hidden. |
| 6950 | boolean mDrawPending; |
| 6951 | |
| 6952 | // This is set after the window has finished drawing for the first |
| 6953 | // time but before its surface is shown. The surface will be |
| 6954 | // displayed when the next layout is run. |
| 6955 | boolean mCommitDrawPending; |
| 6956 | |
| 6957 | // This is set during the time after the window's drawing has been |
| 6958 | // committed, and before its surface is actually shown. It is used |
| 6959 | // to delay showing the surface until all windows in a token are ready |
| 6960 | // to be shown. |
| 6961 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6963 | // Set when the window has been shown in the screen the first time. |
| 6964 | boolean mHasDrawn; |
| 6965 | |
| 6966 | // Currently running an exit animation? |
| 6967 | boolean mExiting; |
| 6968 | |
| 6969 | // Currently on the mDestroySurface list? |
| 6970 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6972 | // Completely remove from window manager after exit animation? |
| 6973 | boolean mRemoveOnExit; |
| 6974 | |
| 6975 | // Set when the orientation is changing and this window has not yet |
| 6976 | // been updated for the new orientation. |
| 6977 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6979 | // Is this window now (or just being) removed? |
| 6980 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6982 | WindowState(Session s, IWindow c, WindowToken token, |
| 6983 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6984 | int viewVisibility) { |
| 6985 | mSession = s; |
| 6986 | mClient = c; |
| 6987 | mToken = token; |
| 6988 | mAttrs.copyFrom(a); |
| 6989 | mViewVisibility = viewVisibility; |
| 6990 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6991 | mAlpha = a.alpha; |
| 6992 | if (localLOGV) Log.v( |
| 6993 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6994 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6995 | try { |
| 6996 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6997 | } catch (RemoteException e) { |
| 6998 | mDeathRecipient = null; |
| 6999 | mAttachedWindow = null; |
| 7000 | mLayoutAttached = false; |
| 7001 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7002 | mIsWallpaper = false; |
| 7003 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7004 | mBaseLayer = 0; |
| 7005 | mSubLayer = 0; |
| 7006 | return; |
| 7007 | } |
| 7008 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7009 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7010 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7011 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7012 | // The multiplier here is to reserve space for multiple |
| 7013 | // windows in the same type layer. |
| 7014 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7015 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7016 | + TYPE_LAYER_OFFSET; |
| 7017 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7018 | mAttachedWindow = attachedWindow; |
| 7019 | mAttachedWindow.mChildWindows.add(this); |
| 7020 | mLayoutAttached = mAttrs.type != |
| 7021 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7022 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7023 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7024 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7025 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7026 | } else { |
| 7027 | // The multiplier here is to reserve space for multiple |
| 7028 | // windows in the same type layer. |
| 7029 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7030 | * TYPE_LAYER_MULTIPLIER |
| 7031 | + TYPE_LAYER_OFFSET; |
| 7032 | mSubLayer = 0; |
| 7033 | mAttachedWindow = null; |
| 7034 | mLayoutAttached = false; |
| 7035 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7036 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7037 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7038 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | WindowState appWin = this; |
| 7042 | while (appWin.mAttachedWindow != null) { |
| 7043 | appWin = mAttachedWindow; |
| 7044 | } |
| 7045 | WindowToken appToken = appWin.mToken; |
| 7046 | while (appToken.appWindowToken == null) { |
| 7047 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7048 | if (parent == null || appToken == parent) { |
| 7049 | break; |
| 7050 | } |
| 7051 | appToken = parent; |
| 7052 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7053 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7054 | mAppToken = appToken.appWindowToken; |
| 7055 | |
| 7056 | mSurface = null; |
| 7057 | mRequestedWidth = 0; |
| 7058 | mRequestedHeight = 0; |
| 7059 | mLastRequestedWidth = 0; |
| 7060 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7061 | mXOffset = 0; |
| 7062 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | mLayer = 0; |
| 7064 | mAnimLayer = 0; |
| 7065 | mLastLayer = 0; |
| 7066 | } |
| 7067 | |
| 7068 | void attach() { |
| 7069 | if (localLOGV) Log.v( |
| 7070 | TAG, "Attaching " + this + " token=" + mToken |
| 7071 | + ", list=" + mToken.windows); |
| 7072 | mSession.windowAddedLocked(); |
| 7073 | } |
| 7074 | |
| 7075 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7076 | mHaveFrame = true; |
| 7077 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7078 | final Rect container = mContainingFrame; |
| 7079 | container.set(pf); |
| 7080 | |
| 7081 | final Rect display = mDisplayFrame; |
| 7082 | display.set(df); |
| 7083 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7084 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7085 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7086 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7087 | display.intersect(mCompatibleScreenFrame); |
| 7088 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7089 | } |
| 7090 | |
| 7091 | final int pw = container.right - container.left; |
| 7092 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7093 | |
| 7094 | int w,h; |
| 7095 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7096 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7097 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7098 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7099 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7100 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7101 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | final Rect content = mContentFrame; |
| 7104 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7106 | final Rect visible = mVisibleFrame; |
| 7107 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7109 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7110 | final int fw = frame.width(); |
| 7111 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7113 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7114 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7115 | |
| 7116 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7117 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7118 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7119 | |
| 7120 | //System.out.println("Out: " + mFrame); |
| 7121 | |
| 7122 | // Now make sure the window fits in the overall display. |
| 7123 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | // Make sure the content and visible frames are inside of the |
| 7126 | // final window frame. |
| 7127 | if (content.left < frame.left) content.left = frame.left; |
| 7128 | if (content.top < frame.top) content.top = frame.top; |
| 7129 | if (content.right > frame.right) content.right = frame.right; |
| 7130 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7131 | if (visible.left < frame.left) visible.left = frame.left; |
| 7132 | if (visible.top < frame.top) visible.top = frame.top; |
| 7133 | if (visible.right > frame.right) visible.right = frame.right; |
| 7134 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7136 | final Rect contentInsets = mContentInsets; |
| 7137 | contentInsets.left = content.left-frame.left; |
| 7138 | contentInsets.top = content.top-frame.top; |
| 7139 | contentInsets.right = frame.right-content.right; |
| 7140 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7142 | final Rect visibleInsets = mVisibleInsets; |
| 7143 | visibleInsets.left = visible.left-frame.left; |
| 7144 | visibleInsets.top = visible.top-frame.top; |
| 7145 | visibleInsets.right = frame.right-visible.right; |
| 7146 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7147 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7148 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7149 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7150 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7151 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7153 | if (localLOGV) { |
| 7154 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7155 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 7156 | Log.v(TAG, "Resolving (mRequestedWidth=" |
| 7157 | + mRequestedWidth + ", mRequestedheight=" |
| 7158 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7159 | + "): frame=" + mFrame.toShortString() |
| 7160 | + " ci=" + contentInsets.toShortString() |
| 7161 | + " vi=" + visibleInsets.toShortString()); |
| 7162 | //} |
| 7163 | } |
| 7164 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7166 | public Rect getFrameLw() { |
| 7167 | return mFrame; |
| 7168 | } |
| 7169 | |
| 7170 | public Rect getShownFrameLw() { |
| 7171 | return mShownFrame; |
| 7172 | } |
| 7173 | |
| 7174 | public Rect getDisplayFrameLw() { |
| 7175 | return mDisplayFrame; |
| 7176 | } |
| 7177 | |
| 7178 | public Rect getContentFrameLw() { |
| 7179 | return mContentFrame; |
| 7180 | } |
| 7181 | |
| 7182 | public Rect getVisibleFrameLw() { |
| 7183 | return mVisibleFrame; |
| 7184 | } |
| 7185 | |
| 7186 | public boolean getGivenInsetsPendingLw() { |
| 7187 | return mGivenInsetsPending; |
| 7188 | } |
| 7189 | |
| 7190 | public Rect getGivenContentInsetsLw() { |
| 7191 | return mGivenContentInsets; |
| 7192 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7194 | public Rect getGivenVisibleInsetsLw() { |
| 7195 | return mGivenVisibleInsets; |
| 7196 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7198 | public WindowManager.LayoutParams getAttrs() { |
| 7199 | return mAttrs; |
| 7200 | } |
| 7201 | |
| 7202 | public int getSurfaceLayer() { |
| 7203 | return mLayer; |
| 7204 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7206 | public IApplicationToken getAppToken() { |
| 7207 | return mAppToken != null ? mAppToken.appToken : null; |
| 7208 | } |
| 7209 | |
| 7210 | public boolean hasAppShownWindows() { |
| 7211 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7212 | } |
| 7213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | public void setAnimation(Animation anim) { |
| 7215 | if (localLOGV) Log.v( |
| 7216 | TAG, "Setting animation in " + this + ": " + anim); |
| 7217 | mAnimating = false; |
| 7218 | mLocalAnimating = false; |
| 7219 | mAnimation = anim; |
| 7220 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7221 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7222 | } |
| 7223 | |
| 7224 | public void clearAnimation() { |
| 7225 | if (mAnimation != null) { |
| 7226 | mAnimating = true; |
| 7227 | mLocalAnimating = false; |
| 7228 | mAnimation = null; |
| 7229 | } |
| 7230 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7232 | Surface createSurfaceLocked() { |
| 7233 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7234 | mReportDestroySurface = false; |
| 7235 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7236 | mDrawPending = true; |
| 7237 | mCommitDrawPending = false; |
| 7238 | mReadyToShow = false; |
| 7239 | if (mAppToken != null) { |
| 7240 | mAppToken.allDrawn = false; |
| 7241 | } |
| 7242 | |
| 7243 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7244 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | flags |= Surface.PUSH_BUFFERS; |
| 7246 | } |
| 7247 | |
| 7248 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7249 | flags |= Surface.SECURE; |
| 7250 | } |
| 7251 | if (DEBUG_VISIBILITY) Log.v( |
| 7252 | TAG, "Creating surface in session " |
| 7253 | + mSession.mSurfaceSession + " window " + this |
| 7254 | + " w=" + mFrame.width() |
| 7255 | + " h=" + mFrame.height() + " format=" |
| 7256 | + mAttrs.format + " flags=" + flags); |
| 7257 | |
| 7258 | int w = mFrame.width(); |
| 7259 | int h = mFrame.height(); |
| 7260 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7261 | // for a scaled surface, we always want the requested |
| 7262 | // size. |
| 7263 | w = mRequestedWidth; |
| 7264 | h = mRequestedHeight; |
| 7265 | } |
| 7266 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7267 | // Something is wrong and SurfaceFlinger will not like this, |
| 7268 | // try to revert to sane values |
| 7269 | if (w <= 0) w = 1; |
| 7270 | if (h <= 0) h = 1; |
| 7271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7272 | try { |
| 7273 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7274 | mSession.mSurfaceSession, mSession.mPid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7275 | 0, w, h, mAttrs.format, flags); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7276 | if (SHOW_TRANSACTIONS) Log.i(TAG, " CREATE SURFACE " |
| 7277 | + mSurface + " IN SESSION " |
| 7278 | + mSession.mSurfaceSession |
| 7279 | + ": pid=" + mSession.mPid + " format=" |
| 7280 | + mAttrs.format + " flags=0x" |
| 7281 | + Integer.toHexString(flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7282 | } catch (Surface.OutOfResourcesException e) { |
| 7283 | Log.w(TAG, "OutOfResourcesException creating surface"); |
| 7284 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7285 | return null; |
| 7286 | } catch (Exception e) { |
| 7287 | Log.e(TAG, "Exception creating surface", e); |
| 7288 | return null; |
| 7289 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7291 | if (localLOGV) Log.v( |
| 7292 | TAG, "Got surface: " + mSurface |
| 7293 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7294 | + ", animLayer=" + mAnimLayer); |
| 7295 | if (SHOW_TRANSACTIONS) { |
| 7296 | Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 7297 | Log.i(TAG, " SURFACE " + mSurface + ": CREATE (" |
| 7298 | + mAttrs.getTitle() + ") pos=(" + |
| 7299 | mFrame.left + "," + mFrame.top + ") (" + |
| 7300 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7301 | mAnimLayer + " HIDE"); |
| 7302 | } |
| 7303 | Surface.openTransaction(); |
| 7304 | try { |
| 7305 | try { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7306 | mSurface.setPosition(mFrame.left + mXOffset, |
| 7307 | mFrame.top + mYOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7308 | mSurface.setLayer(mAnimLayer); |
| 7309 | mSurface.hide(); |
| 7310 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7311 | if (SHOW_TRANSACTIONS) Log.i(TAG, " SURFACE " |
| 7312 | + mSurface + ": DITHER"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7313 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7314 | Surface.SURFACE_DITHER); |
| 7315 | } |
| 7316 | } catch (RuntimeException e) { |
| 7317 | Log.w(TAG, "Error creating surface in " + w, e); |
| 7318 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7319 | } |
| 7320 | mLastHidden = true; |
| 7321 | } finally { |
| 7322 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 7323 | Surface.closeTransaction(); |
| 7324 | } |
| 7325 | if (localLOGV) Log.v( |
| 7326 | TAG, "Created surface " + this); |
| 7327 | } |
| 7328 | return mSurface; |
| 7329 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7331 | void destroySurfaceLocked() { |
| 7332 | // Window is no longer on-screen, so can no longer receive |
| 7333 | // key events... if we were waiting for it to finish |
| 7334 | // handling a key event, the wait is over! |
| 7335 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 7336 | KeyWaiter.RETURN_NOTHING); |
| 7337 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7338 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 7339 | |
| 7340 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7341 | mAppToken.startingDisplayed = false; |
| 7342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7345 | mDrawPending = false; |
| 7346 | mCommitDrawPending = false; |
| 7347 | mReadyToShow = false; |
| 7348 | |
| 7349 | int i = mChildWindows.size(); |
| 7350 | while (i > 0) { |
| 7351 | i--; |
| 7352 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7353 | c.mAttachedHidden = true; |
| 7354 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7355 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7356 | if (mReportDestroySurface) { |
| 7357 | mReportDestroySurface = false; |
| 7358 | mSurfacePendingDestroy = true; |
| 7359 | try { |
| 7360 | mClient.dispatchGetNewSurface(); |
| 7361 | // We'll really destroy on the next time around. |
| 7362 | return; |
| 7363 | } catch (RemoteException e) { |
| 7364 | } |
| 7365 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7368 | if (DEBUG_VISIBILITY) { |
| 7369 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7370 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7371 | Log.w(TAG, "Window " + this + " destroying surface " |
| 7372 | + mSurface + ", session " + mSession, e); |
| 7373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7374 | if (SHOW_TRANSACTIONS) { |
| 7375 | RuntimeException ex = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7376 | if (!HIDE_STACK_CRAWLS) ex.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7377 | Log.i(TAG, " SURFACE " + mSurface + ": DESTROY (" |
| 7378 | + mAttrs.getTitle() + ")", ex); |
| 7379 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7380 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | } catch (RuntimeException e) { |
| 7382 | Log.w(TAG, "Exception thrown when destroying Window " + this |
| 7383 | + " surface " + mSurface + " session " + mSession |
| 7384 | + ": " + e.toString()); |
| 7385 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | } |
| 7389 | } |
| 7390 | |
| 7391 | boolean finishDrawingLocked() { |
| 7392 | if (mDrawPending) { |
| 7393 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.v( |
| 7394 | TAG, "finishDrawingLocked: " + mSurface); |
| 7395 | mCommitDrawPending = true; |
| 7396 | mDrawPending = false; |
| 7397 | return true; |
| 7398 | } |
| 7399 | return false; |
| 7400 | } |
| 7401 | |
| 7402 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7403 | boolean commitFinishDrawingLocked(long currentTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7404 | //Log.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| 7405 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7406 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7407 | } |
| 7408 | mCommitDrawPending = false; |
| 7409 | mReadyToShow = true; |
| 7410 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7411 | final AppWindowToken atoken = mAppToken; |
| 7412 | if (atoken == null || atoken.allDrawn || starting) { |
| 7413 | performShowLocked(); |
| 7414 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7415 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7416 | } |
| 7417 | |
| 7418 | // This must be called while inside a transaction. |
| 7419 | boolean performShowLocked() { |
| 7420 | if (DEBUG_VISIBILITY) { |
| 7421 | RuntimeException e = new RuntimeException(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7422 | if (!HIDE_STACK_CRAWLS) e.fillInStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7423 | Log.v(TAG, "performShow on " + this |
| 7424 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7425 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7426 | } |
| 7427 | if (mReadyToShow && isReadyForDisplay()) { |
| 7428 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Log.i( |
| 7429 | TAG, " SURFACE " + mSurface + ": SHOW (performShowLocked)"); |
| 7430 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + this |
| 7431 | + " during animation: policyVis=" + mPolicyVisibility |
| 7432 | + " attHidden=" + mAttachedHidden |
| 7433 | + " tok.hiddenRequested=" |
| 7434 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7435 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7436 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7437 | + " animating=" + mAnimating |
| 7438 | + " tok animating=" |
| 7439 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7440 | if (!showSurfaceRobustlyLocked(this)) { |
| 7441 | return false; |
| 7442 | } |
| 7443 | mLastAlpha = -1; |
| 7444 | mHasDrawn = true; |
| 7445 | mLastHidden = false; |
| 7446 | mReadyToShow = false; |
| 7447 | enableScreenIfNeededLocked(); |
| 7448 | |
| 7449 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7451 | int i = mChildWindows.size(); |
| 7452 | while (i > 0) { |
| 7453 | i--; |
| 7454 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7455 | if (c.mSurface != null && c.mAttachedHidden) { |
| 7456 | c.mAttachedHidden = false; |
| 7457 | c.performShowLocked(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7458 | // It hadn't been shown, which means layout not |
| 7459 | // performed on it, so now we want to make sure to |
| 7460 | // do a layout. If called from within the transaction |
| 7461 | // loop, this will cause it to restart with a new |
| 7462 | // layout. |
| 7463 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | } |
| 7465 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7467 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7468 | && mAppToken != null) { |
| 7469 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7470 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7471 | if (mAppToken.startingData != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7472 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Log.v(TAG, |
| 7473 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7474 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7475 | // If this initial window is animating, stop it -- we |
| 7476 | // will do an animation to reveal it from behind the |
| 7477 | // starting window, so there is no need for it to also |
| 7478 | // be doing its own stuff. |
| 7479 | if (mAnimation != null) { |
| 7480 | mAnimation = null; |
| 7481 | // Make sure we clean up the animation. |
| 7482 | mAnimating = true; |
| 7483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7484 | mFinishedStarting.add(mAppToken); |
| 7485 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7486 | } |
| 7487 | mAppToken.updateReportedVisibilityLocked(); |
| 7488 | } |
| 7489 | } |
| 7490 | return true; |
| 7491 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7493 | // This must be called while inside a transaction. Returns true if |
| 7494 | // there is more animation to run. |
| 7495 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7496 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7497 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7499 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7500 | mHasTransformation = true; |
| 7501 | mHasLocalTransformation = true; |
| 7502 | if (!mLocalAnimating) { |
| 7503 | if (DEBUG_ANIM) Log.v( |
| 7504 | TAG, "Starting animation in " + this + |
| 7505 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7506 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7507 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7508 | mAnimation.setStartTime(currentTime); |
| 7509 | mLocalAnimating = true; |
| 7510 | mAnimating = true; |
| 7511 | } |
| 7512 | mTransformation.clear(); |
| 7513 | final boolean more = mAnimation.getTransformation( |
| 7514 | currentTime, mTransformation); |
| 7515 | if (DEBUG_ANIM) Log.v( |
| 7516 | TAG, "Stepped animation in " + this + |
| 7517 | ": more=" + more + ", xform=" + mTransformation); |
| 7518 | if (more) { |
| 7519 | // we're not done! |
| 7520 | return true; |
| 7521 | } |
| 7522 | if (DEBUG_ANIM) Log.v( |
| 7523 | TAG, "Finished animation in " + this + |
| 7524 | " @ " + currentTime); |
| 7525 | mAnimation = null; |
| 7526 | //WindowManagerService.this.dump(); |
| 7527 | } |
| 7528 | mHasLocalTransformation = false; |
| 7529 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7530 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7531 | // When our app token is animating, we kind-of pretend like |
| 7532 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7533 | // part of this check means that we will only do this if |
| 7534 | // our window is not currently exiting, or it is not |
| 7535 | // locally animating itself. The idea being that one that |
| 7536 | // is exiting and doing a local animation should be removed |
| 7537 | // once that animation is done. |
| 7538 | mAnimating = true; |
| 7539 | mHasTransformation = true; |
| 7540 | mTransformation.clear(); |
| 7541 | return false; |
| 7542 | } else if (mHasTransformation) { |
| 7543 | // Little trick to get through the path below to act like |
| 7544 | // we have finished an animation. |
| 7545 | mAnimating = true; |
| 7546 | } else if (isAnimating()) { |
| 7547 | mAnimating = true; |
| 7548 | } |
| 7549 | } else if (mAnimation != null) { |
| 7550 | // If the display is frozen, and there is a pending animation, |
| 7551 | // clear it and make sure we run the cleanup code. |
| 7552 | mAnimating = true; |
| 7553 | mLocalAnimating = true; |
| 7554 | mAnimation = null; |
| 7555 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7556 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7557 | if (!mAnimating && !mLocalAnimating) { |
| 7558 | return false; |
| 7559 | } |
| 7560 | |
| 7561 | if (DEBUG_ANIM) Log.v( |
| 7562 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7563 | + ", reportedVisible=" |
| 7564 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7566 | mAnimating = false; |
| 7567 | mLocalAnimating = false; |
| 7568 | mAnimation = null; |
| 7569 | mAnimLayer = mLayer; |
| 7570 | if (mIsImWindow) { |
| 7571 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7572 | } else if (mIsWallpaper) { |
| 7573 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7574 | } |
| 7575 | if (DEBUG_LAYERS) Log.v(TAG, "Stepping win " + this |
| 7576 | + " anim layer: " + mAnimLayer); |
| 7577 | mHasTransformation = false; |
| 7578 | mHasLocalTransformation = false; |
| 7579 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7580 | if (!mPolicyVisibility) { |
| 7581 | // Window is no longer visible -- make sure if we were waiting |
| 7582 | // for it to be displayed before enabling the display, that |
| 7583 | // we allow the display to be enabled now. |
| 7584 | enableScreenIfNeededLocked(); |
| 7585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7586 | mTransformation.clear(); |
| 7587 | if (mHasDrawn |
| 7588 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7589 | && mAppToken != null |
| 7590 | && mAppToken.firstWindowDrawn |
| 7591 | && mAppToken.startingData != null) { |
| 7592 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Finish starting " |
| 7593 | + mToken + ": first real window done animating"); |
| 7594 | mFinishedStarting.add(mAppToken); |
| 7595 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7596 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7598 | finishExit(); |
| 7599 | |
| 7600 | if (mAppToken != null) { |
| 7601 | mAppToken.updateReportedVisibilityLocked(); |
| 7602 | } |
| 7603 | |
| 7604 | return false; |
| 7605 | } |
| 7606 | |
| 7607 | void finishExit() { |
| 7608 | if (DEBUG_ANIM) Log.v( |
| 7609 | TAG, "finishExit in " + this |
| 7610 | + ": exiting=" + mExiting |
| 7611 | + " remove=" + mRemoveOnExit |
| 7612 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7614 | final int N = mChildWindows.size(); |
| 7615 | for (int i=0; i<N; i++) { |
| 7616 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 7617 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7619 | if (!mExiting) { |
| 7620 | return; |
| 7621 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | if (isWindowAnimating()) { |
| 7624 | return; |
| 7625 | } |
| 7626 | |
| 7627 | if (localLOGV) Log.v( |
| 7628 | TAG, "Exit animation finished in " + this |
| 7629 | + ": remove=" + mRemoveOnExit); |
| 7630 | if (mSurface != null) { |
| 7631 | mDestroySurface.add(this); |
| 7632 | mDestroying = true; |
| 7633 | if (SHOW_TRANSACTIONS) Log.i( |
| 7634 | TAG, " SURFACE " + mSurface + ": HIDE (finishExit)"); |
| 7635 | try { |
| 7636 | mSurface.hide(); |
| 7637 | } catch (RuntimeException e) { |
| 7638 | Log.w(TAG, "Error hiding surface in " + this, e); |
| 7639 | } |
| 7640 | mLastHidden = true; |
| 7641 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7642 | } |
| 7643 | mExiting = false; |
| 7644 | if (mRemoveOnExit) { |
| 7645 | mPendingRemove.add(this); |
| 7646 | mRemoveOnExit = false; |
| 7647 | } |
| 7648 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7650 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7651 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7652 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7653 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7654 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7655 | return true; |
| 7656 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7658 | void computeShownFrameLocked() { |
| 7659 | final boolean selfTransformation = mHasLocalTransformation; |
| 7660 | Transformation attachedTransformation = |
| 7661 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7662 | ? mAttachedWindow.mTransformation : null; |
| 7663 | Transformation appTransformation = |
| 7664 | (mAppToken != null && mAppToken.hasTransformation) |
| 7665 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7666 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7667 | // Wallpapers are animated based on the "real" window they |
| 7668 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7669 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7670 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7671 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7672 | mWallpaperTarget.mAnimation != null && |
| 7673 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7674 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7675 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| 7676 | Log.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 7677 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7678 | } |
| 7679 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7680 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7681 | mWallpaperTarget.mAppToken.animation != null && |
| 7682 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7683 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7684 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| 7685 | Log.v(TAG, "WP target app xform: " + appTransformation); |
| 7686 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7687 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7688 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | if (selfTransformation || attachedTransformation != null |
| 7691 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7692 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7693 | final Rect frame = mFrame; |
| 7694 | final float tmpFloats[] = mTmpFloats; |
| 7695 | final Matrix tmpMatrix = mTmpMatrix; |
| 7696 | |
| 7697 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7698 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7699 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7700 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7701 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7702 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7704 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7705 | } |
| 7706 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7707 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7708 | } |
| 7709 | |
| 7710 | // "convert" it into SurfaceFlinger's format |
| 7711 | // (a 2x2 matrix + an offset) |
| 7712 | // Here we must not transform the position of the surface |
| 7713 | // since it is already included in the transformation. |
| 7714 | //Log.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7716 | tmpMatrix.getValues(tmpFloats); |
| 7717 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7718 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7719 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7720 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7721 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7722 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | int w = frame.width(); |
| 7724 | int h = frame.height(); |
| 7725 | mShownFrame.set(x, y, x+w, y+h); |
| 7726 | |
| 7727 | // Now set the alpha... but because our current hardware |
| 7728 | // can't do alpha transformation on a non-opaque surface, |
| 7729 | // turn it off if we are running an animation that is also |
| 7730 | // transforming since it is more important to have that |
| 7731 | // animation be smooth. |
| 7732 | mShownAlpha = mAlpha; |
| 7733 | if (!mLimitedAlphaCompositing |
| 7734 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7735 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7736 | && x == frame.left && y == frame.top))) { |
| 7737 | //Log.i(TAG, "Applying alpha transform"); |
| 7738 | if (selfTransformation) { |
| 7739 | mShownAlpha *= mTransformation.getAlpha(); |
| 7740 | } |
| 7741 | if (attachedTransformation != null) { |
| 7742 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7743 | } |
| 7744 | if (appTransformation != null) { |
| 7745 | mShownAlpha *= appTransformation.getAlpha(); |
| 7746 | } |
| 7747 | } else { |
| 7748 | //Log.i(TAG, "Not applying alpha transform"); |
| 7749 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7751 | if (localLOGV) Log.v( |
| 7752 | TAG, "Continuing animation in " + this + |
| 7753 | ": " + mShownFrame + |
| 7754 | ", alpha=" + mTransformation.getAlpha()); |
| 7755 | return; |
| 7756 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7758 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7759 | if (mXOffset != 0 || mYOffset != 0) { |
| 7760 | mShownFrame.offset(mXOffset, mYOffset); |
| 7761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7762 | mShownAlpha = mAlpha; |
| 7763 | mDsDx = 1; |
| 7764 | mDtDx = 0; |
| 7765 | mDsDy = 0; |
| 7766 | mDtDy = 1; |
| 7767 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7769 | /** |
| 7770 | * Is this window visible? It is not visible if there is no |
| 7771 | * surface, or we are in the process of running an exit animation |
| 7772 | * that will remove the surface, or its app token has been hidden. |
| 7773 | */ |
| 7774 | public boolean isVisibleLw() { |
| 7775 | final AppWindowToken atoken = mAppToken; |
| 7776 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7777 | && (atoken == null || !atoken.hiddenRequested) |
| 7778 | && !mExiting && !mDestroying; |
| 7779 | } |
| 7780 | |
| 7781 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7782 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7783 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7784 | * things like window flags that impact the keyguard. |
| 7785 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7786 | * for this "hidden behind keyguard" state rather than overloading |
| 7787 | * mPolicyVisibility. Ungh. |
| 7788 | */ |
| 7789 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7790 | final AppWindowToken atoken = mAppToken; |
| 7791 | return mSurface != null && !mAttachedHidden |
| 7792 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| 7793 | && !mExiting && !mDestroying; |
| 7794 | } |
| 7795 | |
| 7796 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7797 | * Is this window visible, ignoring its app token? It is not visible |
| 7798 | * if there is no surface, or we are in the process of running an exit animation |
| 7799 | * that will remove the surface. |
| 7800 | */ |
| 7801 | public boolean isWinVisibleLw() { |
| 7802 | final AppWindowToken atoken = mAppToken; |
| 7803 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7804 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7805 | && !mExiting && !mDestroying; |
| 7806 | } |
| 7807 | |
| 7808 | /** |
| 7809 | * The same as isVisible(), but follows the current hidden state of |
| 7810 | * the associated app token, not the pending requested hidden state. |
| 7811 | */ |
| 7812 | boolean isVisibleNow() { |
| 7813 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7814 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7815 | } |
| 7816 | |
| 7817 | /** |
| 7818 | * Same as isVisible(), but we also count it as visible between the |
| 7819 | * call to IWindowSession.add() and the first relayout(). |
| 7820 | */ |
| 7821 | boolean isVisibleOrAdding() { |
| 7822 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7823 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7825 | && mPolicyVisibility && !mAttachedHidden |
| 7826 | && (atoken == null || !atoken.hiddenRequested) |
| 7827 | && !mExiting && !mDestroying; |
| 7828 | } |
| 7829 | |
| 7830 | /** |
| 7831 | * Is this window currently on-screen? It is on-screen either if it |
| 7832 | * is visible or it is currently running an animation before no longer |
| 7833 | * being visible. |
| 7834 | */ |
| 7835 | boolean isOnScreen() { |
| 7836 | final AppWindowToken atoken = mAppToken; |
| 7837 | if (atoken != null) { |
| 7838 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7839 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7840 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7841 | } else { |
| 7842 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7843 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7844 | } |
| 7845 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7847 | /** |
| 7848 | * Like isOnScreen(), but we don't return true if the window is part |
| 7849 | * of a transition that has not yet been started. |
| 7850 | */ |
| 7851 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7852 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7853 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7854 | return false; |
| 7855 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7856 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7857 | final boolean animating = atoken != null |
| 7858 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7859 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7860 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7861 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7862 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7863 | } |
| 7864 | |
| 7865 | /** Is the window or its container currently animating? */ |
| 7866 | boolean isAnimating() { |
| 7867 | final WindowState attached = mAttachedWindow; |
| 7868 | final AppWindowToken atoken = mAppToken; |
| 7869 | return mAnimation != null |
| 7870 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7871 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7872 | (atoken.animation != null |
| 7873 | || atoken.inPendingTransaction)); |
| 7874 | } |
| 7875 | |
| 7876 | /** Is this window currently animating? */ |
| 7877 | boolean isWindowAnimating() { |
| 7878 | return mAnimation != null; |
| 7879 | } |
| 7880 | |
| 7881 | /** |
| 7882 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7883 | * been drawn. |
| 7884 | */ |
| 7885 | public boolean isDisplayedLw() { |
| 7886 | final AppWindowToken atoken = mAppToken; |
| 7887 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7888 | && !mDrawPending && !mCommitDrawPending |
| 7889 | && ((!mAttachedHidden && |
| 7890 | (atoken == null || !atoken.hiddenRequested)) |
| 7891 | || mAnimating); |
| 7892 | } |
| 7893 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7894 | /** |
| 7895 | * Returns true if the window has a surface that it has drawn a |
| 7896 | * complete UI in to. |
| 7897 | */ |
| 7898 | public boolean isDrawnLw() { |
| 7899 | final AppWindowToken atoken = mAppToken; |
| 7900 | return mSurface != null && !mDestroying |
| 7901 | && !mDrawPending && !mCommitDrawPending; |
| 7902 | } |
| 7903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7904 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 7905 | boolean shownFrame, boolean onlyOpaque) { |
| 7906 | if (mSurface == null) { |
| 7907 | return false; |
| 7908 | } |
| 7909 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 7910 | return false; |
| 7911 | } |
| 7912 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 7913 | return false; |
| 7914 | } |
| 7915 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7916 | |
| 7917 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7918 | return frame.left <= mCompatibleScreenFrame.left && |
| 7919 | frame.top <= mCompatibleScreenFrame.top && |
| 7920 | frame.right >= mCompatibleScreenFrame.right && |
| 7921 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 7922 | } else { |
| 7923 | return frame.left <= 0 && frame.top <= 0 |
| 7924 | && frame.right >= screenWidth |
| 7925 | && frame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7927 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7928 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7929 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7930 | * Return true if the window is opaque and fully drawn. This indicates |
| 7931 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7932 | */ |
| 7933 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7934 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7935 | || mAttrs.type == TYPE_WALLPAPER) |
| 7936 | && mSurface != null && mAnimation == null |
| 7937 | && (mAppToken == null || mAppToken.animation == null) |
| 7938 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7939 | } |
| 7940 | |
| 7941 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7942 | return |
| 7943 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7944 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7945 | // only if it's visible |
| 7946 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7947 | // and only if the application fills the compatible screen |
| 7948 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7949 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7950 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7951 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7952 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7953 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7954 | } |
| 7955 | |
| 7956 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7957 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7958 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7959 | } |
| 7960 | |
| 7961 | void removeLocked() { |
| 7962 | if (mAttachedWindow != null) { |
| 7963 | mAttachedWindow.mChildWindows.remove(this); |
| 7964 | } |
| 7965 | destroySurfaceLocked(); |
| 7966 | mSession.windowRemovedLocked(); |
| 7967 | try { |
| 7968 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7969 | } catch (RuntimeException e) { |
| 7970 | // Ignore if it has already been removed (usually because |
| 7971 | // we are doing this as part of processing a death note.) |
| 7972 | } |
| 7973 | } |
| 7974 | |
| 7975 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7976 | public void binderDied() { |
| 7977 | try { |
| 7978 | synchronized(mWindowMap) { |
| 7979 | WindowState win = windowForClientLocked(mSession, mClient); |
| 7980 | Log.i(TAG, "WIN DEATH: " + win); |
| 7981 | if (win != null) { |
| 7982 | removeWindowLocked(mSession, win); |
| 7983 | } |
| 7984 | } |
| 7985 | } catch (IllegalArgumentException ex) { |
| 7986 | // This will happen if the window has already been |
| 7987 | // removed. |
| 7988 | } |
| 7989 | } |
| 7990 | } |
| 7991 | |
| 7992 | /** Returns true if this window desires key events. */ |
| 7993 | public final boolean canReceiveKeys() { |
| 7994 | return isVisibleOrAdding() |
| 7995 | && (mViewVisibility == View.VISIBLE) |
| 7996 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7997 | } |
| 7998 | |
| 7999 | public boolean hasDrawnLw() { |
| 8000 | return mHasDrawn; |
| 8001 | } |
| 8002 | |
| 8003 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8004 | return showLw(doAnimation, true); |
| 8005 | } |
| 8006 | |
| 8007 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8008 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8009 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8010 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8011 | mPolicyVisibility = true; |
| 8012 | mPolicyVisibilityAfterAnim = true; |
| 8013 | if (doAnimation) { |
| 8014 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8015 | } |
| 8016 | if (requestAnim) { |
| 8017 | requestAnimationLocked(0); |
| 8018 | } |
| 8019 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8020 | } |
| 8021 | |
| 8022 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8023 | return hideLw(doAnimation, true); |
| 8024 | } |
| 8025 | |
| 8026 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8027 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8028 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8029 | if (!current) { |
| 8030 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8031 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8032 | if (doAnimation) { |
| 8033 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8034 | if (mAnimation == null) { |
| 8035 | doAnimation = false; |
| 8036 | } |
| 8037 | } |
| 8038 | if (doAnimation) { |
| 8039 | mPolicyVisibilityAfterAnim = false; |
| 8040 | } else { |
| 8041 | mPolicyVisibilityAfterAnim = false; |
| 8042 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8043 | // Window is no longer visible -- make sure if we were waiting |
| 8044 | // for it to be displayed before enabling the display, that |
| 8045 | // we allow the display to be enabled now. |
| 8046 | enableScreenIfNeededLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8047 | } |
| 8048 | if (requestAnim) { |
| 8049 | requestAnimationLocked(0); |
| 8050 | } |
| 8051 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8052 | } |
| 8053 | |
| 8054 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8055 | StringBuilder sb = new StringBuilder(64); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8056 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8057 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8058 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8059 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8060 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8061 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8062 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8063 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8064 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8065 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8066 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8067 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8068 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8069 | } |
| 8070 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8071 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8072 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8073 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8074 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8075 | pw.print("="); pw.print(mAnimLayer); |
| 8076 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8077 | if (mSurface != null) { |
| 8078 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| 8079 | } |
| 8080 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8081 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8082 | if (mAppToken != null) { |
| 8083 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8084 | } |
| 8085 | if (mTargetAppToken != null) { |
| 8086 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8087 | } |
| 8088 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8089 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8090 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8091 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8092 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8093 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8094 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8095 | pw.print(mPolicyVisibility); |
| 8096 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8097 | pw.print(mPolicyVisibilityAfterAnim); |
| 8098 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8099 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8100 | if (!mRelayoutCalled) { |
| 8101 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8102 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8103 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8104 | pw.print(" h="); pw.println(mRequestedHeight); |
| 8105 | if (mXOffset != 0 || mYOffset != 0) { |
| 8106 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8107 | pw.print(" y="); pw.println(mYOffset); |
| 8108 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8109 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8110 | mGivenContentInsets.printShortString(pw); |
| 8111 | pw.print(" mGivenVisibleInsets="); |
| 8112 | mGivenVisibleInsets.printShortString(pw); |
| 8113 | pw.println(); |
| 8114 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8115 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8116 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8117 | } |
| 8118 | pw.print(prefix); pw.print("mShownFrame="); |
| 8119 | mShownFrame.printShortString(pw); |
| 8120 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8121 | pw.println(); |
| 8122 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8123 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8124 | pw.println(); |
| 8125 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8126 | mContainingFrame.printShortString(pw); |
| 8127 | pw.print(" mDisplayFrame="); |
| 8128 | mDisplayFrame.printShortString(pw); |
| 8129 | pw.println(); |
| 8130 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8131 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8132 | pw.println(); |
| 8133 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8134 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8135 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8136 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8137 | pw.println(); |
| 8138 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8139 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8140 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8141 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8142 | } |
| 8143 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8144 | || mAnimation != null) { |
| 8145 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8146 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8147 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8148 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8149 | } |
| 8150 | if (mHasTransformation || mHasLocalTransformation) { |
| 8151 | pw.print(prefix); pw.print("XForm: has="); |
| 8152 | pw.print(mHasTransformation); |
| 8153 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8154 | pw.print(" "); mTransformation.printShortString(pw); |
| 8155 | pw.println(); |
| 8156 | } |
| 8157 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8158 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8159 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8160 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8161 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8162 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8163 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8164 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8165 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8166 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8167 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8168 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8169 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8170 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8171 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8172 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8173 | if (mHScale != 1 || mVScale != 1) { |
| 8174 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8175 | pw.print(" mVScale="); pw.println(mVScale); |
| 8176 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8177 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8178 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8179 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8180 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8181 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8182 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8183 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8184 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8185 | } |
| 8186 | |
| 8187 | @Override |
| 8188 | public String toString() { |
| 8189 | return "Window{" |
| 8190 | + Integer.toHexString(System.identityHashCode(this)) |
| 8191 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 8192 | } |
| 8193 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8195 | // ------------------------------------------------------------- |
| 8196 | // Window Token State |
| 8197 | // ------------------------------------------------------------- |
| 8198 | |
| 8199 | class WindowToken { |
| 8200 | // The actual token. |
| 8201 | final IBinder token; |
| 8202 | |
| 8203 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8204 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8206 | // Set if this token was explicitly added by a client, so should |
| 8207 | // not be removed when all windows are removed. |
| 8208 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8209 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8210 | // For printing. |
| 8211 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8213 | // If this is an AppWindowToken, this is non-null. |
| 8214 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8216 | // All of the windows associated with this token. |
| 8217 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8218 | |
| 8219 | // Is key dispatching paused for this token? |
| 8220 | boolean paused = false; |
| 8221 | |
| 8222 | // Should this token's windows be hidden? |
| 8223 | boolean hidden; |
| 8224 | |
| 8225 | // Temporary for finding which tokens no longer have visible windows. |
| 8226 | boolean hasVisible; |
| 8227 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8228 | // Set to true when this token is in a pending transaction where it |
| 8229 | // will be shown. |
| 8230 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8231 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8232 | // Set to true when this token is in a pending transaction where it |
| 8233 | // will be hidden. |
| 8234 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8235 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8236 | // Set to true when this token is in a pending transaction where its |
| 8237 | // windows will be put to the bottom of the list. |
| 8238 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8239 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8240 | // Set to true when this token is in a pending transaction where its |
| 8241 | // windows will be put to the top of the list. |
| 8242 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8244 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8245 | token = _token; |
| 8246 | windowType = type; |
| 8247 | explicit = _explicit; |
| 8248 | } |
| 8249 | |
| 8250 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8251 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8252 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8253 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8254 | pw.print(" hidden="); pw.print(hidden); |
| 8255 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8256 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8257 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8258 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8259 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8260 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8261 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | } |
| 8263 | |
| 8264 | @Override |
| 8265 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8266 | if (stringName == null) { |
| 8267 | StringBuilder sb = new StringBuilder(); |
| 8268 | sb.append("WindowToken{"); |
| 8269 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8270 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8271 | stringName = sb.toString(); |
| 8272 | } |
| 8273 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8274 | } |
| 8275 | }; |
| 8276 | |
| 8277 | class AppWindowToken extends WindowToken { |
| 8278 | // Non-null only for application tokens. |
| 8279 | final IApplicationToken appToken; |
| 8280 | |
| 8281 | // All of the windows and child windows that are included in this |
| 8282 | // application token. Note this list is NOT sorted! |
| 8283 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8284 | |
| 8285 | int groupId = -1; |
| 8286 | boolean appFullscreen; |
| 8287 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8289 | // These are used for determining when all windows associated with |
| 8290 | // an activity have been drawn, so they can be made visible together |
| 8291 | // at the same time. |
| 8292 | int lastTransactionSequence = mTransactionSequence-1; |
| 8293 | int numInterestingWindows; |
| 8294 | int numDrawnWindows; |
| 8295 | boolean inPendingTransaction; |
| 8296 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8298 | // Is this token going to be hidden in a little while? If so, it |
| 8299 | // won't be taken into account for setting the screen orientation. |
| 8300 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8302 | // Is this window's surface needed? This is almost like hidden, except |
| 8303 | // it will sometimes be true a little earlier: when the token has |
| 8304 | // been shown, but is still waiting for its app transition to execute |
| 8305 | // before making its windows shown. |
| 8306 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8308 | // Have we told the window clients to hide themselves? |
| 8309 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8311 | // Last visibility state we reported to the app token. |
| 8312 | boolean reportedVisible; |
| 8313 | |
| 8314 | // Set to true when the token has been removed from the window mgr. |
| 8315 | boolean removed; |
| 8316 | |
| 8317 | // Have we been asked to have this token keep the screen frozen? |
| 8318 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8320 | boolean animating; |
| 8321 | Animation animation; |
| 8322 | boolean hasTransformation; |
| 8323 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8325 | // Offset to the window of all layers in the token, for use by |
| 8326 | // AppWindowToken animations. |
| 8327 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8329 | // Information about an application starting window if displayed. |
| 8330 | StartingData startingData; |
| 8331 | WindowState startingWindow; |
| 8332 | View startingView; |
| 8333 | boolean startingDisplayed; |
| 8334 | boolean startingMoved; |
| 8335 | boolean firstWindowDrawn; |
| 8336 | |
| 8337 | AppWindowToken(IApplicationToken _token) { |
| 8338 | super(_token.asBinder(), |
| 8339 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8340 | appWindowToken = this; |
| 8341 | appToken = _token; |
| 8342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8344 | public void setAnimation(Animation anim) { |
| 8345 | if (localLOGV) Log.v( |
| 8346 | TAG, "Setting animation in " + this + ": " + anim); |
| 8347 | animation = anim; |
| 8348 | animating = false; |
| 8349 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8350 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8351 | int zorder = anim.getZAdjustment(); |
| 8352 | int adj = 0; |
| 8353 | if (zorder == Animation.ZORDER_TOP) { |
| 8354 | adj = TYPE_LAYER_OFFSET; |
| 8355 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8356 | adj = -TYPE_LAYER_OFFSET; |
| 8357 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8359 | if (animLayerAdjustment != adj) { |
| 8360 | animLayerAdjustment = adj; |
| 8361 | updateLayers(); |
| 8362 | } |
| 8363 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8365 | public void setDummyAnimation() { |
| 8366 | if (animation == null) { |
| 8367 | if (localLOGV) Log.v( |
| 8368 | TAG, "Setting dummy animation in " + this); |
| 8369 | animation = sDummyAnimation; |
| 8370 | } |
| 8371 | } |
| 8372 | |
| 8373 | public void clearAnimation() { |
| 8374 | if (animation != null) { |
| 8375 | animation = null; |
| 8376 | animating = true; |
| 8377 | } |
| 8378 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8380 | void updateLayers() { |
| 8381 | final int N = allAppWindows.size(); |
| 8382 | final int adj = animLayerAdjustment; |
| 8383 | for (int i=0; i<N; i++) { |
| 8384 | WindowState w = allAppWindows.get(i); |
| 8385 | w.mAnimLayer = w.mLayer + adj; |
| 8386 | if (DEBUG_LAYERS) Log.v(TAG, "Updating layer " + w + ": " |
| 8387 | + w.mAnimLayer); |
| 8388 | if (w == mInputMethodTarget) { |
| 8389 | setInputMethodAnimLayerAdjustment(adj); |
| 8390 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8391 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8392 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8393 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8394 | } |
| 8395 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8396 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8397 | void sendAppVisibilityToClients() { |
| 8398 | final int N = allAppWindows.size(); |
| 8399 | for (int i=0; i<N; i++) { |
| 8400 | WindowState win = allAppWindows.get(i); |
| 8401 | if (win == startingWindow && clientHidden) { |
| 8402 | // Don't hide the starting window. |
| 8403 | continue; |
| 8404 | } |
| 8405 | try { |
| 8406 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8407 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8408 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8409 | } catch (RemoteException e) { |
| 8410 | } |
| 8411 | } |
| 8412 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8414 | void showAllWindowsLocked() { |
| 8415 | final int NW = allAppWindows.size(); |
| 8416 | for (int i=0; i<NW; i++) { |
| 8417 | WindowState w = allAppWindows.get(i); |
| 8418 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 8419 | "performing show on: " + w); |
| 8420 | w.performShowLocked(); |
| 8421 | } |
| 8422 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8424 | // This must be called while inside a transaction. |
| 8425 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8426 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8427 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8429 | if (animation == sDummyAnimation) { |
| 8430 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8431 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | // when it is really time to animate, this will be set to |
| 8433 | // a real animation and the next call will execute normally. |
| 8434 | return false; |
| 8435 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8437 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8438 | if (!animating) { |
| 8439 | if (DEBUG_ANIM) Log.v( |
| 8440 | TAG, "Starting animation in " + this + |
| 8441 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8442 | + " scale=" + mTransitionAnimationScale |
| 8443 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8444 | animation.initialize(dw, dh, dw, dh); |
| 8445 | animation.setStartTime(currentTime); |
| 8446 | animating = true; |
| 8447 | } |
| 8448 | transformation.clear(); |
| 8449 | final boolean more = animation.getTransformation( |
| 8450 | currentTime, transformation); |
| 8451 | if (DEBUG_ANIM) Log.v( |
| 8452 | TAG, "Stepped animation in " + this + |
| 8453 | ": more=" + more + ", xform=" + transformation); |
| 8454 | if (more) { |
| 8455 | // we're done! |
| 8456 | hasTransformation = true; |
| 8457 | return true; |
| 8458 | } |
| 8459 | if (DEBUG_ANIM) Log.v( |
| 8460 | TAG, "Finished animation in " + this + |
| 8461 | " @ " + currentTime); |
| 8462 | animation = null; |
| 8463 | } |
| 8464 | } else if (animation != null) { |
| 8465 | // If the display is frozen, and there is a pending animation, |
| 8466 | // clear it and make sure we run the cleanup code. |
| 8467 | animating = true; |
| 8468 | animation = null; |
| 8469 | } |
| 8470 | |
| 8471 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8473 | if (!animating) { |
| 8474 | return false; |
| 8475 | } |
| 8476 | |
| 8477 | clearAnimation(); |
| 8478 | animating = false; |
| 8479 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8480 | moveInputMethodWindowsIfNeededLocked(true); |
| 8481 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8483 | if (DEBUG_ANIM) Log.v( |
| 8484 | TAG, "Animation done in " + this |
| 8485 | + ": reportedVisible=" + reportedVisible); |
| 8486 | |
| 8487 | transformation.clear(); |
| 8488 | if (animLayerAdjustment != 0) { |
| 8489 | animLayerAdjustment = 0; |
| 8490 | updateLayers(); |
| 8491 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | final int N = windows.size(); |
| 8494 | for (int i=0; i<N; i++) { |
| 8495 | ((WindowState)windows.get(i)).finishExit(); |
| 8496 | } |
| 8497 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8499 | return false; |
| 8500 | } |
| 8501 | |
| 8502 | void updateReportedVisibilityLocked() { |
| 8503 | if (appToken == null) { |
| 8504 | return; |
| 8505 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8507 | int numInteresting = 0; |
| 8508 | int numVisible = 0; |
| 8509 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8511 | if (DEBUG_VISIBILITY) Log.v(TAG, "Update reported visibility: " + this); |
| 8512 | final int N = allAppWindows.size(); |
| 8513 | for (int i=0; i<N; i++) { |
| 8514 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8515 | if (win == startingWindow || win.mAppFreezing |
| 8516 | || win.mViewVisibility != View.VISIBLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8517 | continue; |
| 8518 | } |
| 8519 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8520 | Log.v(TAG, "Win " + win + ": isDrawn=" |
| 8521 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8522 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8523 | if (!win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8524 | Log.v(TAG, "Not displayed: s=" + win.mSurface |
| 8525 | + " pv=" + win.mPolicyVisibility |
| 8526 | + " dp=" + win.mDrawPending |
| 8527 | + " cdp=" + win.mCommitDrawPending |
| 8528 | + " ah=" + win.mAttachedHidden |
| 8529 | + " th=" |
| 8530 | + (win.mAppToken != null |
| 8531 | ? win.mAppToken.hiddenRequested : false) |
| 8532 | + " a=" + win.mAnimating); |
| 8533 | } |
| 8534 | } |
| 8535 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8536 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8537 | if (!win.isAnimating()) { |
| 8538 | numVisible++; |
| 8539 | } |
| 8540 | nowGone = false; |
| 8541 | } else if (win.isAnimating()) { |
| 8542 | nowGone = false; |
| 8543 | } |
| 8544 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8546 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| 8547 | if (DEBUG_VISIBILITY) Log.v(TAG, "VIS " + this + ": interesting=" |
| 8548 | + numInteresting + " visible=" + numVisible); |
| 8549 | if (nowVisible != reportedVisible) { |
| 8550 | if (DEBUG_VISIBILITY) Log.v( |
| 8551 | TAG, "Visibility changed in " + this |
| 8552 | + ": vis=" + nowVisible); |
| 8553 | reportedVisible = nowVisible; |
| 8554 | Message m = mH.obtainMessage( |
| 8555 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8556 | nowVisible ? 1 : 0, |
| 8557 | nowGone ? 1 : 0, |
| 8558 | this); |
| 8559 | mH.sendMessage(m); |
| 8560 | } |
| 8561 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8562 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8563 | WindowState findMainWindow() { |
| 8564 | int j = windows.size(); |
| 8565 | while (j > 0) { |
| 8566 | j--; |
| 8567 | WindowState win = windows.get(j); |
| 8568 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8569 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8570 | return win; |
| 8571 | } |
| 8572 | } |
| 8573 | return null; |
| 8574 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8576 | void dump(PrintWriter pw, String prefix) { |
| 8577 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8578 | if (appToken != null) { |
| 8579 | pw.print(prefix); pw.println("app=true"); |
| 8580 | } |
| 8581 | if (allAppWindows.size() > 0) { |
| 8582 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8583 | } |
| 8584 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8585 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8586 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8587 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8588 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8589 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8590 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8591 | if (paused || freezingScreen) { |
| 8592 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8593 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8594 | } |
| 8595 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8596 | || inPendingTransaction || allDrawn) { |
| 8597 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8598 | pw.print(numInterestingWindows); |
| 8599 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8600 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8601 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8602 | } |
| 8603 | if (animating || animation != null) { |
| 8604 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8605 | pw.print(" animation="); pw.println(animation); |
| 8606 | } |
| 8607 | if (animLayerAdjustment != 0) { |
| 8608 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8609 | } |
| 8610 | if (hasTransformation) { |
| 8611 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8612 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8613 | pw.println(); |
| 8614 | } |
| 8615 | if (startingData != null || removed || firstWindowDrawn) { |
| 8616 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8617 | pw.print(" removed="); pw.print(removed); |
| 8618 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8619 | } |
| 8620 | if (startingWindow != null || startingView != null |
| 8621 | || startingDisplayed || startingMoved) { |
| 8622 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8623 | pw.print(" startingView="); pw.print(startingView); |
| 8624 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8625 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8626 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8627 | } |
| 8628 | |
| 8629 | @Override |
| 8630 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8631 | if (stringName == null) { |
| 8632 | StringBuilder sb = new StringBuilder(); |
| 8633 | sb.append("AppWindowToken{"); |
| 8634 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8635 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8636 | stringName = sb.toString(); |
| 8637 | } |
| 8638 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8639 | } |
| 8640 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8642 | // ------------------------------------------------------------- |
| 8643 | // DummyAnimation |
| 8644 | // ------------------------------------------------------------- |
| 8645 | |
| 8646 | // This is an animation that does nothing: it just immediately finishes |
| 8647 | // itself every time it is called. It is used as a stub animation in cases |
| 8648 | // where we want to synchronize multiple things that may be animating. |
| 8649 | static final class DummyAnimation extends Animation { |
| 8650 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8651 | return false; |
| 8652 | } |
| 8653 | } |
| 8654 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8656 | // ------------------------------------------------------------- |
| 8657 | // Async Handler |
| 8658 | // ------------------------------------------------------------- |
| 8659 | |
| 8660 | static final class StartingData { |
| 8661 | final String pkg; |
| 8662 | final int theme; |
| 8663 | final CharSequence nonLocalizedLabel; |
| 8664 | final int labelRes; |
| 8665 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8667 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8668 | int _labelRes, int _icon) { |
| 8669 | pkg = _pkg; |
| 8670 | theme = _theme; |
| 8671 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8672 | labelRes = _labelRes; |
| 8673 | icon = _icon; |
| 8674 | } |
| 8675 | } |
| 8676 | |
| 8677 | private final class H extends Handler { |
| 8678 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8679 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8680 | public static final int ANIMATE = 4; |
| 8681 | public static final int ADD_STARTING = 5; |
| 8682 | public static final int REMOVE_STARTING = 6; |
| 8683 | public static final int FINISHED_STARTING = 7; |
| 8684 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8685 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8686 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8687 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8688 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8689 | public static final int FORCE_GC = 15; |
| 8690 | public static final int ENABLE_SCREEN = 16; |
| 8691 | public static final int APP_FREEZE_TIMEOUT = 17; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8692 | public static final int COMPUTE_AND_SEND_NEW_CONFIGURATION = 18; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8694 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8695 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8696 | public H() { |
| 8697 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8699 | @Override |
| 8700 | public void handleMessage(Message msg) { |
| 8701 | switch (msg.what) { |
| 8702 | case REPORT_FOCUS_CHANGE: { |
| 8703 | WindowState lastFocus; |
| 8704 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8706 | synchronized(mWindowMap) { |
| 8707 | lastFocus = mLastFocus; |
| 8708 | newFocus = mCurrentFocus; |
| 8709 | if (lastFocus == newFocus) { |
| 8710 | // Focus is not changing, so nothing to do. |
| 8711 | return; |
| 8712 | } |
| 8713 | mLastFocus = newFocus; |
| 8714 | //Log.i(TAG, "Focus moving from " + lastFocus |
| 8715 | // + " to " + newFocus); |
| 8716 | if (newFocus != null && lastFocus != null |
| 8717 | && !newFocus.isDisplayedLw()) { |
| 8718 | //Log.i(TAG, "Delaying loss of focus..."); |
| 8719 | mLosingFocus.add(lastFocus); |
| 8720 | lastFocus = null; |
| 8721 | } |
| 8722 | } |
| 8723 | |
| 8724 | if (lastFocus != newFocus) { |
| 8725 | //System.out.println("Changing focus from " + lastFocus |
| 8726 | // + " to " + newFocus); |
| 8727 | if (newFocus != null) { |
| 8728 | try { |
| 8729 | //Log.i(TAG, "Gaining focus: " + newFocus); |
| 8730 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8731 | } catch (RemoteException e) { |
| 8732 | // Ignore if process has died. |
| 8733 | } |
| 8734 | } |
| 8735 | |
| 8736 | if (lastFocus != null) { |
| 8737 | try { |
| 8738 | //Log.i(TAG, "Losing focus: " + lastFocus); |
| 8739 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8740 | } catch (RemoteException e) { |
| 8741 | // Ignore if process has died. |
| 8742 | } |
| 8743 | } |
| 8744 | } |
| 8745 | } break; |
| 8746 | |
| 8747 | case REPORT_LOSING_FOCUS: { |
| 8748 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8750 | synchronized(mWindowMap) { |
| 8751 | losers = mLosingFocus; |
| 8752 | mLosingFocus = new ArrayList<WindowState>(); |
| 8753 | } |
| 8754 | |
| 8755 | final int N = losers.size(); |
| 8756 | for (int i=0; i<N; i++) { |
| 8757 | try { |
| 8758 | //Log.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| 8759 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8760 | } catch (RemoteException e) { |
| 8761 | // Ignore if process has died. |
| 8762 | } |
| 8763 | } |
| 8764 | } break; |
| 8765 | |
| 8766 | case ANIMATE: { |
| 8767 | synchronized(mWindowMap) { |
| 8768 | mAnimationPending = false; |
| 8769 | performLayoutAndPlaceSurfacesLocked(); |
| 8770 | } |
| 8771 | } break; |
| 8772 | |
| 8773 | case ADD_STARTING: { |
| 8774 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8775 | final StartingData sd = wtoken.startingData; |
| 8776 | |
| 8777 | if (sd == null) { |
| 8778 | // Animation has been canceled... do nothing. |
| 8779 | return; |
| 8780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8782 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Add starting " |
| 8783 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8785 | View view = null; |
| 8786 | try { |
| 8787 | view = mPolicy.addStartingWindow( |
| 8788 | wtoken.token, sd.pkg, |
| 8789 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8790 | sd.icon); |
| 8791 | } catch (Exception e) { |
| 8792 | Log.w(TAG, "Exception when adding starting window", e); |
| 8793 | } |
| 8794 | |
| 8795 | if (view != null) { |
| 8796 | boolean abort = false; |
| 8797 | |
| 8798 | synchronized(mWindowMap) { |
| 8799 | if (wtoken.removed || wtoken.startingData == null) { |
| 8800 | // If the window was successfully added, then |
| 8801 | // we need to remove it. |
| 8802 | if (wtoken.startingWindow != null) { |
| 8803 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8804 | "Aborted starting " + wtoken |
| 8805 | + ": removed=" + wtoken.removed |
| 8806 | + " startingData=" + wtoken.startingData); |
| 8807 | wtoken.startingWindow = null; |
| 8808 | wtoken.startingData = null; |
| 8809 | abort = true; |
| 8810 | } |
| 8811 | } else { |
| 8812 | wtoken.startingView = view; |
| 8813 | } |
| 8814 | if (DEBUG_STARTING_WINDOW && !abort) Log.v(TAG, |
| 8815 | "Added starting " + wtoken |
| 8816 | + ": startingWindow=" |
| 8817 | + wtoken.startingWindow + " startingView=" |
| 8818 | + wtoken.startingView); |
| 8819 | } |
| 8820 | |
| 8821 | if (abort) { |
| 8822 | try { |
| 8823 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8824 | } catch (Exception e) { |
| 8825 | Log.w(TAG, "Exception when removing starting window", e); |
| 8826 | } |
| 8827 | } |
| 8828 | } |
| 8829 | } break; |
| 8830 | |
| 8831 | case REMOVE_STARTING: { |
| 8832 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8833 | IBinder token = null; |
| 8834 | View view = null; |
| 8835 | synchronized (mWindowMap) { |
| 8836 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, "Remove starting " |
| 8837 | + wtoken + ": startingWindow=" |
| 8838 | + wtoken.startingWindow + " startingView=" |
| 8839 | + wtoken.startingView); |
| 8840 | if (wtoken.startingWindow != null) { |
| 8841 | view = wtoken.startingView; |
| 8842 | token = wtoken.token; |
| 8843 | wtoken.startingData = null; |
| 8844 | wtoken.startingView = null; |
| 8845 | wtoken.startingWindow = null; |
| 8846 | } |
| 8847 | } |
| 8848 | if (view != null) { |
| 8849 | try { |
| 8850 | mPolicy.removeStartingWindow(token, view); |
| 8851 | } catch (Exception e) { |
| 8852 | Log.w(TAG, "Exception when removing starting window", e); |
| 8853 | } |
| 8854 | } |
| 8855 | } break; |
| 8856 | |
| 8857 | case FINISHED_STARTING: { |
| 8858 | IBinder token = null; |
| 8859 | View view = null; |
| 8860 | while (true) { |
| 8861 | synchronized (mWindowMap) { |
| 8862 | final int N = mFinishedStarting.size(); |
| 8863 | if (N <= 0) { |
| 8864 | break; |
| 8865 | } |
| 8866 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8867 | |
| 8868 | if (DEBUG_STARTING_WINDOW) Log.v(TAG, |
| 8869 | "Finished starting " + wtoken |
| 8870 | + ": startingWindow=" + wtoken.startingWindow |
| 8871 | + " startingView=" + wtoken.startingView); |
| 8872 | |
| 8873 | if (wtoken.startingWindow == null) { |
| 8874 | continue; |
| 8875 | } |
| 8876 | |
| 8877 | view = wtoken.startingView; |
| 8878 | token = wtoken.token; |
| 8879 | wtoken.startingData = null; |
| 8880 | wtoken.startingView = null; |
| 8881 | wtoken.startingWindow = null; |
| 8882 | } |
| 8883 | |
| 8884 | try { |
| 8885 | mPolicy.removeStartingWindow(token, view); |
| 8886 | } catch (Exception e) { |
| 8887 | Log.w(TAG, "Exception when removing starting window", e); |
| 8888 | } |
| 8889 | } |
| 8890 | } break; |
| 8891 | |
| 8892 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8893 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8894 | |
| 8895 | boolean nowVisible = msg.arg1 != 0; |
| 8896 | boolean nowGone = msg.arg2 != 0; |
| 8897 | |
| 8898 | try { |
| 8899 | if (DEBUG_VISIBILITY) Log.v( |
| 8900 | TAG, "Reporting visible in " + wtoken |
| 8901 | + " visible=" + nowVisible |
| 8902 | + " gone=" + nowGone); |
| 8903 | if (nowVisible) { |
| 8904 | wtoken.appToken.windowsVisible(); |
| 8905 | } else { |
| 8906 | wtoken.appToken.windowsGone(); |
| 8907 | } |
| 8908 | } catch (RemoteException ex) { |
| 8909 | } |
| 8910 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8912 | case WINDOW_FREEZE_TIMEOUT: { |
| 8913 | synchronized (mWindowMap) { |
| 8914 | Log.w(TAG, "Window freeze timeout expired."); |
| 8915 | int i = mWindows.size(); |
| 8916 | while (i > 0) { |
| 8917 | i--; |
| 8918 | WindowState w = (WindowState)mWindows.get(i); |
| 8919 | if (w.mOrientationChanging) { |
| 8920 | w.mOrientationChanging = false; |
| 8921 | Log.w(TAG, "Force clearing orientation change: " + w); |
| 8922 | } |
| 8923 | } |
| 8924 | performLayoutAndPlaceSurfacesLocked(); |
| 8925 | } |
| 8926 | break; |
| 8927 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8929 | case HOLD_SCREEN_CHANGED: { |
| 8930 | Session oldHold; |
| 8931 | Session newHold; |
| 8932 | synchronized (mWindowMap) { |
| 8933 | oldHold = mLastReportedHold; |
| 8934 | newHold = (Session)msg.obj; |
| 8935 | mLastReportedHold = newHold; |
| 8936 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8938 | if (oldHold != newHold) { |
| 8939 | try { |
| 8940 | if (oldHold != null) { |
| 8941 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8942 | "window", |
| 8943 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8944 | } |
| 8945 | if (newHold != null) { |
| 8946 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8947 | "window", |
| 8948 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8949 | } |
| 8950 | } catch (RemoteException e) { |
| 8951 | } |
| 8952 | } |
| 8953 | break; |
| 8954 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8956 | case APP_TRANSITION_TIMEOUT: { |
| 8957 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8958 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8959 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 8960 | "*** APP TRANSITION TIMEOUT"); |
| 8961 | mAppTransitionReady = true; |
| 8962 | mAppTransitionTimeout = true; |
| 8963 | performLayoutAndPlaceSurfacesLocked(); |
| 8964 | } |
| 8965 | } |
| 8966 | break; |
| 8967 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8969 | case PERSIST_ANIMATION_SCALE: { |
| 8970 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8971 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8972 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8973 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8974 | break; |
| 8975 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8977 | case FORCE_GC: { |
| 8978 | synchronized(mWindowMap) { |
| 8979 | if (mAnimationPending) { |
| 8980 | // If we are animating, don't do the gc now but |
| 8981 | // delay a bit so we don't interrupt the animation. |
| 8982 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8983 | 2000); |
| 8984 | return; |
| 8985 | } |
| 8986 | // If we are currently rotating the display, it will |
| 8987 | // schedule a new message when done. |
| 8988 | if (mDisplayFrozen) { |
| 8989 | return; |
| 8990 | } |
| 8991 | mFreezeGcPending = 0; |
| 8992 | } |
| 8993 | Runtime.getRuntime().gc(); |
| 8994 | break; |
| 8995 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8997 | case ENABLE_SCREEN: { |
| 8998 | performEnableScreen(); |
| 8999 | break; |
| 9000 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9002 | case APP_FREEZE_TIMEOUT: { |
| 9003 | synchronized (mWindowMap) { |
| 9004 | Log.w(TAG, "App freeze timeout expired."); |
| 9005 | int i = mAppTokens.size(); |
| 9006 | while (i > 0) { |
| 9007 | i--; |
| 9008 | AppWindowToken tok = mAppTokens.get(i); |
| 9009 | if (tok.freezingScreen) { |
| 9010 | Log.w(TAG, "Force clearing freeze: " + tok); |
| 9011 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9012 | } |
| 9013 | } |
| 9014 | } |
| 9015 | break; |
| 9016 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9017 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9018 | case COMPUTE_AND_SEND_NEW_CONFIGURATION: { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 9019 | if (updateOrientationFromAppTokensUnchecked(null, null) != null) { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9020 | sendNewConfiguration(); |
| 9021 | } |
| 9022 | break; |
| 9023 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9025 | } |
| 9026 | } |
| 9027 | } |
| 9028 | |
| 9029 | // ------------------------------------------------------------- |
| 9030 | // IWindowManager API |
| 9031 | // ------------------------------------------------------------- |
| 9032 | |
| 9033 | public IWindowSession openSession(IInputMethodClient client, |
| 9034 | IInputContext inputContext) { |
| 9035 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9036 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 9037 | return new Session(client, inputContext); |
| 9038 | } |
| 9039 | |
| 9040 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9041 | synchronized (mWindowMap) { |
| 9042 | // The focus for the client is the window immediately below |
| 9043 | // where we would place the input method window. |
| 9044 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9045 | WindowState imFocus; |
| 9046 | if (idx > 0) { |
| 9047 | imFocus = (WindowState)mWindows.get(idx-1); |
| 9048 | if (imFocus != null) { |
| 9049 | if (imFocus.mSession.mClient != null && |
| 9050 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9051 | return true; |
| 9052 | } |
| 9053 | } |
| 9054 | } |
| 9055 | } |
| 9056 | return false; |
| 9057 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9059 | // ------------------------------------------------------------- |
| 9060 | // Internals |
| 9061 | // ------------------------------------------------------------- |
| 9062 | |
| 9063 | final WindowState windowForClientLocked(Session session, IWindow client) { |
| 9064 | return windowForClientLocked(session, client.asBinder()); |
| 9065 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9067 | final WindowState windowForClientLocked(Session session, IBinder client) { |
| 9068 | WindowState win = mWindowMap.get(client); |
| 9069 | if (localLOGV) Log.v( |
| 9070 | TAG, "Looking up client " + client + ": " + win); |
| 9071 | if (win == null) { |
| 9072 | RuntimeException ex = new RuntimeException(); |
| 9073 | Log.w(TAG, "Requested window " + client + " does not exist", ex); |
| 9074 | return null; |
| 9075 | } |
| 9076 | if (session != null && win.mSession != session) { |
| 9077 | RuntimeException ex = new RuntimeException(); |
| 9078 | Log.w(TAG, "Requested window " + client + " is in session " + |
| 9079 | win.mSession + ", not " + session, ex); |
| 9080 | return null; |
| 9081 | } |
| 9082 | |
| 9083 | return win; |
| 9084 | } |
| 9085 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9086 | final void rebuildAppWindowListLocked() { |
| 9087 | int NW = mWindows.size(); |
| 9088 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9089 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9090 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9091 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9092 | // First remove all existing app windows. |
| 9093 | i=0; |
| 9094 | while (i < NW) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9095 | WindowState w = (WindowState)mWindows.get(i); |
| 9096 | if (w.mAppToken != null) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9097 | WindowState win = (WindowState)mWindows.remove(i); |
| 9098 | if (DEBUG_WINDOW_MOVEMENT) Log.v(TAG, |
| 9099 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9100 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9101 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9102 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9103 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9104 | && lastWallpaper == i-1) { |
| 9105 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9106 | } |
| 9107 | i++; |
| 9108 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9109 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9110 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9111 | // so skip them before adding app tokens. |
| 9112 | lastWallpaper++; |
| 9113 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9114 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9115 | // First add all of the exiting app tokens... these are no longer |
| 9116 | // in the main app list, but still have windows shown. We put them |
| 9117 | // in the back because now that the animation is over we no longer |
| 9118 | // will care about them. |
| 9119 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9120 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9121 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9122 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9123 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9124 | // And add in the still active app tokens in Z order. |
| 9125 | NT = mAppTokens.size(); |
| 9126 | for (int j=0; j<NT; j++) { |
| 9127 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9128 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9129 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9130 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9131 | if (i != numRemoved) { |
| 9132 | Log.w(TAG, "Rebuild removed " + numRemoved |
| 9133 | + " windows but added " + i); |
| 9134 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9135 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9137 | private final void assignLayersLocked() { |
| 9138 | int N = mWindows.size(); |
| 9139 | int curBaseLayer = 0; |
| 9140 | int curLayer = 0; |
| 9141 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9143 | for (i=0; i<N; i++) { |
| 9144 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9145 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9146 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9147 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9148 | w.mLayer = curLayer; |
| 9149 | } else { |
| 9150 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9151 | w.mLayer = curLayer; |
| 9152 | } |
| 9153 | if (w.mTargetAppToken != null) { |
| 9154 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9155 | } else if (w.mAppToken != null) { |
| 9156 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9157 | } else { |
| 9158 | w.mAnimLayer = w.mLayer; |
| 9159 | } |
| 9160 | if (w.mIsImWindow) { |
| 9161 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9162 | } else if (w.mIsWallpaper) { |
| 9163 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9164 | } |
| 9165 | if (DEBUG_LAYERS) Log.v(TAG, "Assign layer " + w + ": " |
| 9166 | + w.mAnimLayer); |
| 9167 | //System.out.println( |
| 9168 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9169 | } |
| 9170 | } |
| 9171 | |
| 9172 | private boolean mInLayout = false; |
| 9173 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9174 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9175 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9176 | throw new RuntimeException("Recursive call!"); |
| 9177 | } |
| 9178 | Log.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| 9179 | return; |
| 9180 | } |
| 9181 | |
| 9182 | boolean recoveringMemory = false; |
| 9183 | if (mForceRemoves != null) { |
| 9184 | recoveringMemory = true; |
| 9185 | // Wait a little it for things to settle down, and off we go. |
| 9186 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9187 | WindowState ws = mForceRemoves.get(i); |
| 9188 | Log.i(TAG, "Force removing: " + ws); |
| 9189 | removeWindowInnerLocked(ws.mSession, ws); |
| 9190 | } |
| 9191 | mForceRemoves = null; |
| 9192 | Log.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 9193 | Object tmp = new Object(); |
| 9194 | synchronized (tmp) { |
| 9195 | try { |
| 9196 | tmp.wait(250); |
| 9197 | } catch (InterruptedException e) { |
| 9198 | } |
| 9199 | } |
| 9200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9202 | mInLayout = true; |
| 9203 | try { |
| 9204 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9206 | int i = mPendingRemove.size()-1; |
| 9207 | if (i >= 0) { |
| 9208 | while (i >= 0) { |
| 9209 | WindowState w = mPendingRemove.get(i); |
| 9210 | removeWindowInnerLocked(w.mSession, w); |
| 9211 | i--; |
| 9212 | } |
| 9213 | mPendingRemove.clear(); |
| 9214 | |
| 9215 | mInLayout = false; |
| 9216 | assignLayersLocked(); |
| 9217 | mLayoutNeeded = true; |
| 9218 | performLayoutAndPlaceSurfacesLocked(); |
| 9219 | |
| 9220 | } else { |
| 9221 | mInLayout = false; |
| 9222 | if (mLayoutNeeded) { |
| 9223 | requestAnimationLocked(0); |
| 9224 | } |
| 9225 | } |
| 9226 | } catch (RuntimeException e) { |
| 9227 | mInLayout = false; |
| 9228 | Log.e(TAG, "Unhandled exception while layout out windows", e); |
| 9229 | } |
| 9230 | } |
| 9231 | |
| 9232 | private final void performLayoutLockedInner() { |
| 9233 | final int dw = mDisplay.getWidth(); |
| 9234 | final int dh = mDisplay.getHeight(); |
| 9235 | |
| 9236 | final int N = mWindows.size(); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9237 | int repeats = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | int i; |
| 9239 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9240 | if (DEBUG_LAYOUT) Log.v(TAG, "performLayout: needed=" |
| 9241 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9243 | // FIRST LOOP: Perform a layout, if needed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9244 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9245 | while (mLayoutNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9246 | mPolicy.beginLayoutLw(dw, dh); |
| 9247 | |
| 9248 | // First perform layout of any root windows (not attached |
| 9249 | // to another window). |
| 9250 | int topAttached = -1; |
| 9251 | for (i = N-1; i >= 0; i--) { |
| 9252 | WindowState win = (WindowState) mWindows.get(i); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9253 | |
| 9254 | // Don't do layout of a window if it is not visible, or |
| 9255 | // soon won't be visible, to avoid wasting time and funky |
| 9256 | // changes while a window is animating away. |
| 9257 | final AppWindowToken atoken = win.mAppToken; |
| 9258 | final boolean gone = win.mViewVisibility == View.GONE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9259 | || !win.mRelayoutCalled |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9260 | || win.mRootToken.hidden |
| 9261 | || (atoken != null && atoken.hiddenRequested) |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9262 | || win.mAttachedHidden |
| 9263 | || win.mExiting || win.mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9264 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9265 | if (win.mLayoutAttached) { |
| 9266 | if (DEBUG_LAYOUT) Log.v(TAG, "First pass " + win |
| 9267 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9268 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9269 | if (DEBUG_LAYOUT && gone) Log.v(TAG, " (mViewVisibility=" |
| 9270 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9271 | + win.mRelayoutCalled + " hidden=" |
| 9272 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9273 | + (atoken != null && atoken.hiddenRequested) |
| 9274 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9275 | } |
| 9276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9277 | // If this view is GONE, then skip it -- keep the current |
| 9278 | // frame, and let the caller know so they can ignore it |
| 9279 | // if they want. (We do the normal layout for INVISIBLE |
| 9280 | // windows, since that means "perform layout as normal, |
| 9281 | // just don't display"). |
| 9282 | if (!gone || !win.mHaveFrame) { |
| 9283 | if (!win.mLayoutAttached) { |
| 9284 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9285 | if (DEBUG_LAYOUT) Log.v(TAG, "-> mFrame=" |
| 9286 | + win.mFrame + " mContainingFrame=" |
| 9287 | + win.mContainingFrame + " mDisplayFrame=" |
| 9288 | + win.mDisplayFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9289 | } else { |
| 9290 | if (topAttached < 0) topAttached = i; |
| 9291 | } |
| 9292 | } |
| 9293 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9295 | // Now perform layout of attached windows, which usually |
| 9296 | // depend on the position of the window they are attached to. |
| 9297 | // XXX does not deal with windows that are attached to windows |
| 9298 | // that are themselves attached. |
| 9299 | for (i = topAttached; i >= 0; i--) { |
| 9300 | WindowState win = (WindowState) mWindows.get(i); |
| 9301 | |
| 9302 | // If this view is GONE, then skip it -- keep the current |
| 9303 | // frame, and let the caller know so they can ignore it |
| 9304 | // if they want. (We do the normal layout for INVISIBLE |
| 9305 | // windows, since that means "perform layout as normal, |
| 9306 | // just don't display"). |
| 9307 | if (win.mLayoutAttached) { |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9308 | if (DEBUG_LAYOUT) Log.v(TAG, "Second pass " + win |
| 9309 | + " mHaveFrame=" + win.mHaveFrame |
| 9310 | + " mViewVisibility=" + win.mViewVisibility |
| 9311 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9312 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9313 | || !win.mHaveFrame) { |
| 9314 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9315 | if (DEBUG_LAYOUT) Log.v(TAG, "-> mFrame=" |
| 9316 | + win.mFrame + " mContainingFrame=" |
| 9317 | + win.mContainingFrame + " mDisplayFrame=" |
| 9318 | + win.mDisplayFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9319 | } |
| 9320 | } |
| 9321 | } |
| 9322 | |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9323 | int changes = mPolicy.finishLayoutLw(); |
| 9324 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9325 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9326 | assignLayersLocked(); |
| 9327 | } |
| 9328 | } |
| 9329 | if (changes == 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9330 | mLayoutNeeded = false; |
| 9331 | } else if (repeats > 2) { |
| 9332 | Log.w(TAG, "Layout repeat aborted after too many iterations"); |
| 9333 | mLayoutNeeded = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9334 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9335 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9336 | null, null); |
| 9337 | if (newConfig != null) { |
| 9338 | mLayoutNeeded = true; |
| 9339 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9340 | } |
| 9341 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9342 | } else { |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9343 | if (DEBUG_LAYOUT) Log.v(TAG, "Repeating layout because changes=0x" |
| 9344 | + Integer.toHexString(changes)); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9345 | repeats++; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9346 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9347 | if (DEBUG_LAYOUT) Log.v(TAG, "Computing new config from layout"); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9348 | Configuration newConfig = updateOrientationFromAppTokensLocked( |
| 9349 | null, null); |
| 9350 | if (newConfig != null) { |
| 9351 | mH.sendEmptyMessage(H.COMPUTE_AND_SEND_NEW_CONFIGURATION); |
| 9352 | } |
| 9353 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9354 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9355 | } |
| 9356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9358 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9359 | boolean recoveringMemory) { |
| 9360 | final long currentTime = SystemClock.uptimeMillis(); |
| 9361 | final int dw = mDisplay.getWidth(); |
| 9362 | final int dh = mDisplay.getHeight(); |
| 9363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9364 | int i; |
| 9365 | |
| 9366 | // FIRST LOOP: Perform a layout, if needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9367 | performLayoutLockedInner(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9369 | if (mFxSession == null) { |
| 9370 | mFxSession = new SurfaceSession(); |
| 9371 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9373 | if (SHOW_TRANSACTIONS) Log.i(TAG, ">>> OPEN TRANSACTION"); |
| 9374 | |
| 9375 | // Initialize state of exiting tokens. |
| 9376 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9377 | mExitingTokens.get(i).hasVisible = false; |
| 9378 | } |
| 9379 | |
| 9380 | // Initialize state of exiting applications. |
| 9381 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9382 | mExitingAppTokens.get(i).hasVisible = false; |
| 9383 | } |
| 9384 | |
| 9385 | // SECOND LOOP: Execute animations and update visibility of windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9386 | boolean orientationChangeComplete = true; |
| 9387 | Session holdScreen = null; |
| 9388 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9389 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9390 | boolean focusDisplayed = false; |
| 9391 | boolean animating = false; |
| 9392 | |
| 9393 | Surface.openTransaction(); |
| 9394 | try { |
| 9395 | boolean restart; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9396 | boolean forceHiding = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9397 | boolean wallpaperForceHidingChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9398 | |
| 9399 | do { |
| 9400 | final int transactionSequence = ++mTransactionSequence; |
| 9401 | |
| 9402 | // Update animations of all applications, including those |
| 9403 | // associated with exiting/removed apps |
| 9404 | boolean tokensAnimating = false; |
| 9405 | final int NAT = mAppTokens.size(); |
| 9406 | for (i=0; i<NAT; i++) { |
| 9407 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9408 | tokensAnimating = true; |
| 9409 | } |
| 9410 | } |
| 9411 | final int NEAT = mExitingAppTokens.size(); |
| 9412 | for (i=0; i<NEAT; i++) { |
| 9413 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9414 | tokensAnimating = true; |
| 9415 | } |
| 9416 | } |
| 9417 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9418 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "*** ANIM STEP: seq=" |
| 9419 | + transactionSequence + " tokensAnimating=" |
| 9420 | + tokensAnimating); |
| 9421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9422 | animating = tokensAnimating; |
| 9423 | restart = false; |
| 9424 | |
| 9425 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9426 | boolean wallpaperMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9427 | boolean focusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9428 | |
| 9429 | mPolicy.beginAnimationLw(dw, dh); |
| 9430 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9431 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9433 | for (i=N-1; i>=0; i--) { |
| 9434 | WindowState w = (WindowState)mWindows.get(i); |
| 9435 | |
| 9436 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9437 | |
| 9438 | if (w.mSurface != null) { |
| 9439 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9440 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9441 | if ((w.mAttrs.flags |
| 9442 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9443 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9444 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9445 | wallpaperMayChange = true; |
| 9446 | } |
| 9447 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9448 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9449 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9450 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9451 | animating = true; |
| 9452 | //w.dump(" "); |
| 9453 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9454 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9455 | wallpaperMayChange = true; |
| 9456 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9457 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9458 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9459 | if (!wasAnimating && animating) { |
| 9460 | wallpaperForceHidingChanged = true; |
| 9461 | focusMayChange = true; |
| 9462 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9463 | forceHiding = true; |
| 9464 | } |
| 9465 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9466 | boolean changed; |
| 9467 | if (forceHiding) { |
| 9468 | changed = w.hideLw(false, false); |
| 9469 | } else { |
| 9470 | changed = w.showLw(false, false); |
| 9471 | if (changed && wallpaperForceHidingChanged |
| 9472 | && w.isReadyForDisplay()) { |
| 9473 | // Assume we will need to animate. If |
| 9474 | // we don't (because the wallpaper will |
| 9475 | // stay with the lock screen), then we will |
| 9476 | // clean up later. |
| 9477 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9478 | if (a != null) { |
| 9479 | w.setAnimation(a); |
| 9480 | } |
| 9481 | } |
| 9482 | } |
| 9483 | if (changed && (attrs.flags |
| 9484 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9485 | wallpaperMayChange = true; |
| 9486 | } |
| 9487 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9489 | mPolicy.animatingWindowLw(w, attrs); |
| 9490 | } |
| 9491 | |
| 9492 | final AppWindowToken atoken = w.mAppToken; |
| 9493 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9494 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9495 | atoken.lastTransactionSequence = transactionSequence; |
| 9496 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9497 | atoken.startingDisplayed = false; |
| 9498 | } |
| 9499 | if ((w.isOnScreen() || w.mAttrs.type |
| 9500 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9501 | && !w.mExiting && !w.mDestroying) { |
| 9502 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9503 | Log.v(TAG, "Eval win " + w + ": isDrawn=" |
| 9504 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9506 | if (!w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9507 | Log.v(TAG, "Not displayed: s=" + w.mSurface |
| 9508 | + " pv=" + w.mPolicyVisibility |
| 9509 | + " dp=" + w.mDrawPending |
| 9510 | + " cdp=" + w.mCommitDrawPending |
| 9511 | + " ah=" + w.mAttachedHidden |
| 9512 | + " th=" + atoken.hiddenRequested |
| 9513 | + " a=" + w.mAnimating); |
| 9514 | } |
| 9515 | } |
| 9516 | if (w != atoken.startingWindow) { |
| 9517 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9518 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9519 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9520 | atoken.numDrawnWindows++; |
| 9521 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG, |
| 9522 | "tokenMayBeDrawn: " + atoken |
| 9523 | + " freezingScreen=" + atoken.freezingScreen |
| 9524 | + " mAppFreezing=" + w.mAppFreezing); |
| 9525 | tokenMayBeDrawn = true; |
| 9526 | } |
| 9527 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9528 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9529 | atoken.startingDisplayed = true; |
| 9530 | } |
| 9531 | } |
| 9532 | } else if (w.mReadyToShow) { |
| 9533 | w.performShowLocked(); |
| 9534 | } |
| 9535 | } |
| 9536 | |
| 9537 | if (mPolicy.finishAnimationLw()) { |
| 9538 | restart = true; |
| 9539 | } |
| 9540 | |
| 9541 | if (tokenMayBeDrawn) { |
| 9542 | // See if any windows have been drawn, so they (and others |
| 9543 | // associated with them) can now be shown. |
| 9544 | final int NT = mTokenList.size(); |
| 9545 | for (i=0; i<NT; i++) { |
| 9546 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9547 | if (wtoken == null) { |
| 9548 | continue; |
| 9549 | } |
| 9550 | if (wtoken.freezingScreen) { |
| 9551 | int numInteresting = wtoken.numInterestingWindows; |
| 9552 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9553 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9554 | "allDrawn: " + wtoken |
| 9555 | + " interesting=" + numInteresting |
| 9556 | + " drawn=" + wtoken.numDrawnWindows); |
| 9557 | wtoken.showAllWindowsLocked(); |
| 9558 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9559 | orientationChangeComplete = true; |
| 9560 | } |
| 9561 | } else if (!wtoken.allDrawn) { |
| 9562 | int numInteresting = wtoken.numInterestingWindows; |
| 9563 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 9564 | if (DEBUG_VISIBILITY) Log.v(TAG, |
| 9565 | "allDrawn: " + wtoken |
| 9566 | + " interesting=" + numInteresting |
| 9567 | + " drawn=" + wtoken.numDrawnWindows); |
| 9568 | wtoken.allDrawn = true; |
| 9569 | restart = true; |
| 9570 | |
| 9571 | // We can now show all of the drawn windows! |
| 9572 | if (!mOpeningApps.contains(wtoken)) { |
| 9573 | wtoken.showAllWindowsLocked(); |
| 9574 | } |
| 9575 | } |
| 9576 | } |
| 9577 | } |
| 9578 | } |
| 9579 | |
| 9580 | // If we are ready to perform an app transition, check through |
| 9581 | // all of the app tokens to be shown and see if they are ready |
| 9582 | // to go. |
| 9583 | if (mAppTransitionReady) { |
| 9584 | int NN = mOpeningApps.size(); |
| 9585 | boolean goodToGo = true; |
| 9586 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9587 | "Checking " + NN + " opening apps (frozen=" |
| 9588 | + mDisplayFrozen + " timeout=" |
| 9589 | + mAppTransitionTimeout + ")..."); |
| 9590 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9591 | // If the display isn't frozen, wait to do anything until |
| 9592 | // all of the apps are ready. Otherwise just go because |
| 9593 | // we'll unfreeze the display when everyone is ready. |
| 9594 | for (i=0; i<NN && goodToGo; i++) { |
| 9595 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9596 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9597 | "Check opening app" + wtoken + ": allDrawn=" |
| 9598 | + wtoken.allDrawn + " startingDisplayed=" |
| 9599 | + wtoken.startingDisplayed); |
| 9600 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9601 | && !wtoken.startingMoved) { |
| 9602 | goodToGo = false; |
| 9603 | } |
| 9604 | } |
| 9605 | } |
| 9606 | if (goodToGo) { |
| 9607 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "**** GOOD TO GO"); |
| 9608 | int transit = mNextAppTransition; |
| 9609 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9610 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9611 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9612 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9614 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9615 | mAppTransitionTimeout = false; |
| 9616 | mStartingIconInTransition = false; |
| 9617 | mSkipAppTransitionAnimation = false; |
| 9618 | |
| 9619 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9620 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9621 | // If there are applications waiting to come to the |
| 9622 | // top of the stack, now is the time to move their windows. |
| 9623 | // (Note that we don't do apps going to the bottom |
| 9624 | // here -- we want to keep their windows in the old |
| 9625 | // Z-order until the animation completes.) |
| 9626 | if (mToTopApps.size() > 0) { |
| 9627 | NN = mAppTokens.size(); |
| 9628 | for (i=0; i<NN; i++) { |
| 9629 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9630 | if (wtoken.sendingToTop) { |
| 9631 | wtoken.sendingToTop = false; |
| 9632 | moveAppWindowsLocked(wtoken, NN, false); |
| 9633 | } |
| 9634 | } |
| 9635 | mToTopApps.clear(); |
| 9636 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9637 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9638 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9639 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9640 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9641 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9642 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9643 | // The top-most window will supply the layout params, |
| 9644 | // and we will determine it below. |
| 9645 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9646 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9647 | int bestAnimLayer = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9648 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9649 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9650 | "New wallpaper target=" + mWallpaperTarget |
| 9651 | + ", lower target=" + mLowerWallpaperTarget |
| 9652 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9653 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9654 | // Do a first pass through the tokens for two |
| 9655 | // things: |
| 9656 | // (1) Determine if both the closing and opening |
| 9657 | // app token sets are wallpaper targets, in which |
| 9658 | // case special animations are needed |
| 9659 | // (since the wallpaper needs to stay static |
| 9660 | // behind them). |
| 9661 | // (2) Find the layout params of the top-most |
| 9662 | // application window in the tokens, which is |
| 9663 | // what will control the animation theme. |
| 9664 | final int NC = mClosingApps.size(); |
| 9665 | NN = NC + mOpeningApps.size(); |
| 9666 | for (i=0; i<NN; i++) { |
| 9667 | AppWindowToken wtoken; |
| 9668 | int mode; |
| 9669 | if (i < NC) { |
| 9670 | wtoken = mClosingApps.get(i); |
| 9671 | mode = 1; |
| 9672 | } else { |
| 9673 | wtoken = mOpeningApps.get(i-NC); |
| 9674 | mode = 2; |
| 9675 | } |
| 9676 | if (mLowerWallpaperTarget != null) { |
| 9677 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9678 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9679 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9680 | } |
| 9681 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9682 | if (wtoken.appFullscreen) { |
| 9683 | WindowState ws = wtoken.findMainWindow(); |
| 9684 | if (ws != null) { |
| 9685 | // If this is a compatibility mode |
| 9686 | // window, we will always use its anim. |
| 9687 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9688 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9689 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9690 | bestAnimLayer = Integer.MAX_VALUE; |
| 9691 | } else if (ws.mLayer > bestAnimLayer) { |
| 9692 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9693 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9694 | bestAnimLayer = ws.mLayer; |
| 9695 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9696 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9697 | } |
| 9698 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9699 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9700 | if (foundWallpapers == 3) { |
| 9701 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9702 | "Wallpaper animation!"); |
| 9703 | switch (transit) { |
| 9704 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9705 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9706 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9707 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9708 | break; |
| 9709 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9710 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9711 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9712 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9713 | break; |
| 9714 | } |
| 9715 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9716 | "New transit: " + transit); |
| 9717 | } else if (oldWallpaper != null) { |
| 9718 | // We are transitioning from an activity with |
| 9719 | // a wallpaper to one without. |
| 9720 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| 9721 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9722 | "New transit away from wallpaper: " + transit); |
| 9723 | } else if (mWallpaperTarget != null) { |
| 9724 | // We are transitioning from an activity without |
| 9725 | // a wallpaper to now showing the wallpaper |
| 9726 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| 9727 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9728 | "New transit into wallpaper: " + transit); |
| 9729 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9730 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9731 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9732 | mLastEnterAnimToken = animToken; |
| 9733 | mLastEnterAnimParams = animLp; |
| 9734 | } else if (mLastEnterAnimParams != null) { |
| 9735 | animLp = mLastEnterAnimParams; |
| 9736 | mLastEnterAnimToken = null; |
| 9737 | mLastEnterAnimParams = null; |
| 9738 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9739 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9740 | // If all closing windows are obscured, then there is |
| 9741 | // no need to do an animation. This is the case, for |
| 9742 | // example, when this transition is being done behind |
| 9743 | // the lock screen. |
| 9744 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9745 | animLp = null; |
| 9746 | } |
| 9747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9748 | NN = mOpeningApps.size(); |
| 9749 | for (i=0; i<NN; i++) { |
| 9750 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 9751 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9752 | "Now opening app" + wtoken); |
| 9753 | wtoken.reportedVisible = false; |
| 9754 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9755 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9756 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9757 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9758 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9759 | wtoken.showAllWindowsLocked(); |
| 9760 | } |
| 9761 | NN = mClosingApps.size(); |
| 9762 | for (i=0; i<NN; i++) { |
| 9763 | AppWindowToken wtoken = mClosingApps.get(i); |
| 9764 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, |
| 9765 | "Now closing app" + wtoken); |
| 9766 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9767 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9768 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9769 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9770 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9771 | // Force the allDrawn flag, because we want to start |
| 9772 | // this guy's animations regardless of whether it's |
| 9773 | // gotten drawn. |
| 9774 | wtoken.allDrawn = true; |
| 9775 | } |
| 9776 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9777 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9778 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9779 | mOpeningApps.clear(); |
| 9780 | mClosingApps.clear(); |
| 9781 | |
| 9782 | // This has changed the visibility of windows, so perform |
| 9783 | // a new layout to get them all up-to-date. |
| 9784 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9785 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9786 | assignLayersLocked(); |
| 9787 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9788 | performLayoutLockedInner(); |
| 9789 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9790 | focusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9791 | |
| 9792 | restart = true; |
| 9793 | } |
| 9794 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9795 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9796 | if (!animating && mAppTransitionRunning) { |
| 9797 | // We have finished the animation of an app transition. To do |
| 9798 | // this, we have delayed a lot of operations like showing and |
| 9799 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9800 | // reflects the correct Z-order, but the window list may now |
| 9801 | // be out of sync with it. So here we will just rebuild the |
| 9802 | // entire app window list. Fun! |
| 9803 | mAppTransitionRunning = false; |
| 9804 | // Clear information about apps that were moving. |
| 9805 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9806 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9807 | rebuildAppWindowListLocked(); |
| 9808 | restart = true; |
| 9809 | moveInputMethodWindowsIfNeededLocked(false); |
| 9810 | wallpaperMayChange = true; |
| 9811 | mLayoutNeeded = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9812 | // Since the window list has been rebuilt, focus might |
| 9813 | // have to be recomputed since the actual order of windows |
| 9814 | // might have changed again. |
| 9815 | focusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9816 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9817 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9818 | int adjResult = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9819 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9820 | if (wallpaperForceHidingChanged && !restart && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9821 | // At this point, there was a window with a wallpaper that |
| 9822 | // was force hiding other windows behind it, but now it |
| 9823 | // is going away. This may be simple -- just animate |
| 9824 | // away the wallpaper and its window -- or it may be |
| 9825 | // hard -- the wallpaper now needs to be shown behind |
| 9826 | // something that was hidden. |
| 9827 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9828 | if (mLowerWallpaperTarget != null |
| 9829 | && mLowerWallpaperTarget.mAppToken != null) { |
| 9830 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9831 | "wallpaperForceHiding changed with lower=" |
| 9832 | + mLowerWallpaperTarget); |
| 9833 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9834 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9835 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9836 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9837 | // The lower target has become hidden before we |
| 9838 | // actually started the animation... let's completely |
| 9839 | // re-evaluate everything. |
| 9840 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| 9841 | restart = true; |
| 9842 | } |
| 9843 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9844 | adjResult = adjustWallpaperWindowsLocked(); |
| 9845 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9846 | wallpaperForceHidingChanged = false; |
| 9847 | if (DEBUG_WALLPAPER) Log.v(TAG, "****** OLD: " + oldWallpaper |
| 9848 | + " NEW: " + mWallpaperTarget |
| 9849 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9850 | if (mLowerWallpaperTarget == null) { |
| 9851 | // Whoops, we don't need a special wallpaper animation. |
| 9852 | // Clear them out. |
| 9853 | forceHiding = false; |
| 9854 | for (i=N-1; i>=0; i--) { |
| 9855 | WindowState w = (WindowState)mWindows.get(i); |
| 9856 | if (w.mSurface != null) { |
| 9857 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9858 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| 9859 | if (DEBUG_FOCUS) Log.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9860 | forceHiding = true; |
| 9861 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9862 | if (!w.mAnimating) { |
| 9863 | // We set the animation above so it |
| 9864 | // is not yet running. |
| 9865 | w.clearAnimation(); |
| 9866 | } |
| 9867 | } |
| 9868 | } |
| 9869 | } |
| 9870 | } |
| 9871 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9872 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9873 | if (wallpaperMayChange) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9874 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9875 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9876 | adjResult = adjustWallpaperWindowsLocked(); |
| 9877 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9878 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9879 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9880 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9881 | "Wallpaper layer changed: assigning layers + relayout"); |
| 9882 | restart = true; |
| 9883 | mLayoutNeeded = true; |
| 9884 | assignLayersLocked(); |
| 9885 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| 9886 | if (DEBUG_WALLPAPER) Log.v(TAG, |
| 9887 | "Wallpaper visibility changed: relayout"); |
| 9888 | restart = true; |
| 9889 | mLayoutNeeded = true; |
| 9890 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9891 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9892 | if (focusMayChange) { |
| 9893 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9894 | restart = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9895 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9896 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9897 | } |
| 9898 | |
| 9899 | if (mLayoutNeeded) { |
| 9900 | restart = true; |
| 9901 | performLayoutLockedInner(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9902 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9903 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9904 | if (DEBUG_APP_TRANSITIONS) Log.v(TAG, "*** ANIM STEP: restart=" |
| 9905 | + restart); |
| 9906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9907 | } while (restart); |
| 9908 | |
| 9909 | // THIRD LOOP: Update the surfaces of all windows. |
| 9910 | |
| 9911 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9912 | |
| 9913 | boolean obscured = false; |
| 9914 | boolean blurring = false; |
| 9915 | boolean dimming = false; |
| 9916 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9917 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9918 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9919 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9920 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | for (i=N-1; i>=0; i--) { |
| 9923 | WindowState w = (WindowState)mWindows.get(i); |
| 9924 | |
| 9925 | boolean displayed = false; |
| 9926 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9927 | final int attrFlags = attrs.flags; |
| 9928 | |
| 9929 | if (w.mSurface != null) { |
| 9930 | w.computeShownFrameLocked(); |
| 9931 | if (localLOGV) Log.v( |
| 9932 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9933 | + ": new=" + w.mShownFrame + ", old=" |
| 9934 | + w.mLastShownFrame); |
| 9935 | |
| 9936 | boolean resize; |
| 9937 | int width, height; |
| 9938 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9939 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9940 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9941 | // for a scaled surface, we just want to use |
| 9942 | // the requested size. |
| 9943 | width = w.mRequestedWidth; |
| 9944 | height = w.mRequestedHeight; |
| 9945 | w.mLastRequestedWidth = width; |
| 9946 | w.mLastRequestedHeight = height; |
| 9947 | w.mLastShownFrame.set(w.mShownFrame); |
| 9948 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9949 | if (SHOW_TRANSACTIONS) Log.i( |
| 9950 | TAG, " SURFACE " + w.mSurface |
| 9951 | + ": POS " + w.mShownFrame.left |
| 9952 | + ", " + w.mShownFrame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9953 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9954 | } catch (RuntimeException e) { |
| 9955 | Log.w(TAG, "Error positioning surface in " + w, e); |
| 9956 | if (!recoveringMemory) { |
| 9957 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9958 | } |
| 9959 | } |
| 9960 | } else { |
| 9961 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9962 | width = w.mShownFrame.width(); |
| 9963 | height = w.mShownFrame.height(); |
| 9964 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9965 | } |
| 9966 | |
| 9967 | if (resize) { |
| 9968 | if (width < 1) width = 1; |
| 9969 | if (height < 1) height = 1; |
| 9970 | if (w.mSurface != null) { |
| 9971 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9972 | if (SHOW_TRANSACTIONS) Log.i( |
| 9973 | TAG, " SURFACE " + w.mSurface + ": POS " |
| 9974 | + w.mShownFrame.left + "," |
| 9975 | + w.mShownFrame.top + " SIZE " |
| 9976 | + w.mShownFrame.width() + "x" |
| 9977 | + w.mShownFrame.height()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9978 | w.mSurface.setSize(width, height); |
| 9979 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9980 | w.mShownFrame.top); |
| 9981 | } catch (RuntimeException e) { |
| 9982 | // If something goes wrong with the surface (such |
| 9983 | // as running out of memory), don't take down the |
| 9984 | // entire system. |
| 9985 | Log.e(TAG, "Failure updating surface of " + w |
| 9986 | + "size=(" + width + "x" + height |
| 9987 | + "), pos=(" + w.mShownFrame.left |
| 9988 | + "," + w.mShownFrame.top + ")", e); |
| 9989 | if (!recoveringMemory) { |
| 9990 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9991 | } |
| 9992 | } |
| 9993 | } |
| 9994 | } |
| 9995 | if (!w.mAppFreezing) { |
| 9996 | w.mContentInsetsChanged = |
| 9997 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9998 | w.mVisibleInsetsChanged = |
| 9999 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10000 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10001 | || w.mContentInsetsChanged |
| 10002 | || w.mVisibleInsetsChanged) { |
| 10003 | w.mLastFrame.set(w.mFrame); |
| 10004 | w.mLastContentInsets.set(w.mContentInsets); |
| 10005 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10006 | // If the screen is currently frozen, then keep |
| 10007 | // it frozen until this window draws at its new |
| 10008 | // orientation. |
| 10009 | if (mDisplayFrozen) { |
| 10010 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10011 | "Resizing while display frozen: " + w); |
| 10012 | w.mOrientationChanging = true; |
| 10013 | if (mWindowsFreezingScreen) { |
| 10014 | mWindowsFreezingScreen = true; |
| 10015 | // XXX should probably keep timeout from |
| 10016 | // when we first froze the display. |
| 10017 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10018 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10019 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10020 | } |
| 10021 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10022 | // If the orientation is changing, then we need to |
| 10023 | // hold off on unfreezing the display until this |
| 10024 | // window has been redrawn; to do that, we need |
| 10025 | // to go through the process of getting informed |
| 10026 | // by the application when it has finished drawing. |
| 10027 | if (w.mOrientationChanging) { |
| 10028 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10029 | "Orientation start waiting for draw in " |
| 10030 | + w + ", surface " + w.mSurface); |
| 10031 | w.mDrawPending = true; |
| 10032 | w.mCommitDrawPending = false; |
| 10033 | w.mReadyToShow = false; |
| 10034 | if (w.mAppToken != null) { |
| 10035 | w.mAppToken.allDrawn = false; |
| 10036 | } |
| 10037 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10038 | if (DEBUG_ORIENTATION) Log.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10039 | "Resizing window " + w + " to " + w.mFrame); |
| 10040 | mResizingWindows.add(w); |
| 10041 | } else if (w.mOrientationChanging) { |
| 10042 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| 10043 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10044 | "Orientation not waiting for draw in " |
| 10045 | + w + ", surface " + w.mSurface); |
| 10046 | w.mOrientationChanging = false; |
| 10047 | } |
| 10048 | } |
| 10049 | } |
| 10050 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10051 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10052 | if (!w.mLastHidden) { |
| 10053 | //dump(); |
| 10054 | w.mLastHidden = true; |
| 10055 | if (SHOW_TRANSACTIONS) Log.i( |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10056 | TAG, " SURFACE " + w.mSurface + ": HIDE (performLayout)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10057 | if (w.mSurface != null) { |
| 10058 | try { |
| 10059 | w.mSurface.hide(); |
| 10060 | } catch (RuntimeException e) { |
| 10061 | Log.w(TAG, "Exception hiding surface in " + w); |
| 10062 | } |
| 10063 | } |
| 10064 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 10065 | } |
| 10066 | // If we are waiting for this window to handle an |
| 10067 | // orientation change, well, it is hidden, so |
| 10068 | // doesn't really matter. Note that this does |
| 10069 | // introduce a potential glitch if the window |
| 10070 | // becomes unhidden before it has drawn for the |
| 10071 | // new orientation. |
| 10072 | if (w.mOrientationChanging) { |
| 10073 | w.mOrientationChanging = false; |
| 10074 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10075 | "Orientation change skips hidden " + w); |
| 10076 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10077 | } else if (w.mLastLayer != w.mAnimLayer |
| 10078 | || w.mLastAlpha != w.mShownAlpha |
| 10079 | || w.mLastDsDx != w.mDsDx |
| 10080 | || w.mLastDtDx != w.mDtDx |
| 10081 | || w.mLastDsDy != w.mDsDy |
| 10082 | || w.mLastDtDy != w.mDtDy |
| 10083 | || w.mLastHScale != w.mHScale |
| 10084 | || w.mLastVScale != w.mVScale |
| 10085 | || w.mLastHidden) { |
| 10086 | displayed = true; |
| 10087 | w.mLastAlpha = w.mShownAlpha; |
| 10088 | w.mLastLayer = w.mAnimLayer; |
| 10089 | w.mLastDsDx = w.mDsDx; |
| 10090 | w.mLastDtDx = w.mDtDx; |
| 10091 | w.mLastDsDy = w.mDsDy; |
| 10092 | w.mLastDtDy = w.mDtDy; |
| 10093 | w.mLastHScale = w.mHScale; |
| 10094 | w.mLastVScale = w.mVScale; |
| 10095 | if (SHOW_TRANSACTIONS) Log.i( |
| 10096 | TAG, " SURFACE " + w.mSurface + ": alpha=" |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10097 | + w.mShownAlpha + " layer=" + w.mAnimLayer |
| 10098 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10099 | + "," + (w.mDtDx*w.mVScale) |
| 10100 | + "][" + (w.mDsDy*w.mHScale) |
| 10101 | + "," + (w.mDtDy*w.mVScale) + "]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10102 | if (w.mSurface != null) { |
| 10103 | try { |
| 10104 | w.mSurface.setAlpha(w.mShownAlpha); |
| 10105 | w.mSurface.setLayer(w.mAnimLayer); |
| 10106 | w.mSurface.setMatrix( |
| 10107 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10108 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10109 | } catch (RuntimeException e) { |
| 10110 | Log.w(TAG, "Error updating surface in " + w, e); |
| 10111 | if (!recoveringMemory) { |
| 10112 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10113 | } |
| 10114 | } |
| 10115 | } |
| 10116 | |
| 10117 | if (w.mLastHidden && !w.mDrawPending |
| 10118 | && !w.mCommitDrawPending |
| 10119 | && !w.mReadyToShow) { |
| 10120 | if (SHOW_TRANSACTIONS) Log.i( |
| 10121 | TAG, " SURFACE " + w.mSurface + ": SHOW (performLayout)"); |
| 10122 | if (DEBUG_VISIBILITY) Log.v(TAG, "Showing " + w |
| 10123 | + " during relayout"); |
| 10124 | if (showSurfaceRobustlyLocked(w)) { |
| 10125 | w.mHasDrawn = true; |
| 10126 | w.mLastHidden = false; |
| 10127 | } else { |
| 10128 | w.mOrientationChanging = false; |
| 10129 | } |
| 10130 | } |
| 10131 | if (w.mSurface != null) { |
| 10132 | w.mToken.hasVisible = true; |
| 10133 | } |
| 10134 | } else { |
| 10135 | displayed = true; |
| 10136 | } |
| 10137 | |
| 10138 | if (displayed) { |
| 10139 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10140 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10141 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10142 | covered = true; |
| 10143 | } |
| 10144 | } |
| 10145 | if (w.mOrientationChanging) { |
| 10146 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10147 | orientationChangeComplete = false; |
| 10148 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10149 | "Orientation continue waiting for draw in " + w); |
| 10150 | } else { |
| 10151 | w.mOrientationChanging = false; |
| 10152 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10153 | "Orientation change complete in " + w); |
| 10154 | } |
| 10155 | } |
| 10156 | w.mToken.hasVisible = true; |
| 10157 | } |
| 10158 | } else if (w.mOrientationChanging) { |
| 10159 | if (DEBUG_ORIENTATION) Log.v(TAG, |
| 10160 | "Orientation change skips hidden " + w); |
| 10161 | w.mOrientationChanging = false; |
| 10162 | } |
| 10163 | |
| 10164 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10165 | |
| 10166 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10167 | focusDisplayed = true; |
| 10168 | } |
| 10169 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10170 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10172 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10173 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10174 | if (w.mSurface != null) { |
| 10175 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10176 | holdScreen = w.mSession; |
| 10177 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10178 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10179 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10180 | screenBrightness = w.mAttrs.screenBrightness; |
| 10181 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10182 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10183 | && buttonBrightness < 0) { |
| 10184 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10185 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10186 | if (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10187 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10188 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) { |
| 10189 | syswin = true; |
| 10190 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10191 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10192 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10193 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10194 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10195 | // This window completely covers everything behind it, |
| 10196 | // so we want to leave all of them as unblurred (for |
| 10197 | // performance reasons). |
| 10198 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10199 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| 10200 | if (SHOW_TRANSACTIONS) Log.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10201 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10202 | obscured = true; |
| 10203 | if (mBackgroundFillerSurface == null) { |
| 10204 | try { |
| 10205 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 10206 | 0, dw, dh, |
| 10207 | PixelFormat.OPAQUE, |
| 10208 | Surface.FX_SURFACE_NORMAL); |
| 10209 | } catch (Exception e) { |
| 10210 | Log.e(TAG, "Exception creating filler surface", e); |
| 10211 | } |
| 10212 | } |
| 10213 | try { |
| 10214 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10215 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10216 | // Using the same layer as Dim because they will never be shown at the |
| 10217 | // same time. |
| 10218 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10219 | mBackgroundFillerSurface.show(); |
| 10220 | } catch (RuntimeException e) { |
| 10221 | Log.e(TAG, "Exception showing filler surface"); |
| 10222 | } |
| 10223 | backgroundFillerShown = true; |
| 10224 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10225 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10226 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| 10227 | if (localLOGV) Log.v(TAG, "Win " + w |
| 10228 | + ": blurring=" + blurring |
| 10229 | + " obscured=" + obscured |
| 10230 | + " displayed=" + displayed); |
| 10231 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10232 | if (!dimming) { |
| 10233 | //Log.i(TAG, "DIM BEHIND: " + w); |
| 10234 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10235 | if (mDimAnimator == null) { |
| 10236 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10237 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10238 | mDimAnimator.show(dw, dh); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10239 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10240 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10241 | } |
| 10242 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10243 | if (!blurring) { |
| 10244 | //Log.i(TAG, "BLUR BEHIND: " + w); |
| 10245 | blurring = true; |
| 10246 | mBlurShown = true; |
| 10247 | if (mBlurSurface == null) { |
| 10248 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 10249 | + mBlurSurface + ": CREATE"); |
| 10250 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10251 | mBlurSurface = new Surface(mFxSession, 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10252 | -1, 16, 16, |
| 10253 | PixelFormat.OPAQUE, |
| 10254 | Surface.FX_SURFACE_BLUR); |
| 10255 | } catch (Exception e) { |
| 10256 | Log.e(TAG, "Exception creating Blur surface", e); |
| 10257 | } |
| 10258 | } |
| 10259 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " |
| 10260 | + mBlurSurface + ": SHOW pos=(0,0) (" + |
| 10261 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| 10262 | if (mBlurSurface != null) { |
| 10263 | mBlurSurface.setPosition(0, 0); |
| 10264 | mBlurSurface.setSize(dw, dh); |
| 10265 | try { |
| 10266 | mBlurSurface.show(); |
| 10267 | } catch (RuntimeException e) { |
| 10268 | Log.w(TAG, "Failure showing blur surface", e); |
| 10269 | } |
| 10270 | } |
| 10271 | } |
| 10272 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10273 | } |
| 10274 | } |
| 10275 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10276 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10277 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10278 | // This is the wallpaper target and its obscured state |
| 10279 | // changed... make sure the current wallaper's visibility |
| 10280 | // has been updated accordingly. |
| 10281 | updateWallpaperVisibilityLocked(); |
| 10282 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10283 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10284 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10285 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10286 | mBackgroundFillerShown = false; |
| 10287 | if (SHOW_TRANSACTIONS) Log.d(TAG, "hiding background filler"); |
| 10288 | try { |
| 10289 | mBackgroundFillerSurface.hide(); |
| 10290 | } catch (RuntimeException e) { |
| 10291 | Log.e(TAG, "Exception hiding filler surface", e); |
| 10292 | } |
| 10293 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10294 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10295 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10296 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10297 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10298 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10300 | if (!blurring && mBlurShown) { |
| 10301 | if (SHOW_TRANSACTIONS) Log.i(TAG, " BLUR " + mBlurSurface |
| 10302 | + ": HIDE"); |
| 10303 | try { |
| 10304 | mBlurSurface.hide(); |
| 10305 | } catch (IllegalArgumentException e) { |
| 10306 | Log.w(TAG, "Illegal argument exception hiding blur surface"); |
| 10307 | } |
| 10308 | mBlurShown = false; |
| 10309 | } |
| 10310 | |
| 10311 | if (SHOW_TRANSACTIONS) Log.i(TAG, "<<< CLOSE TRANSACTION"); |
| 10312 | } catch (RuntimeException e) { |
| 10313 | Log.e(TAG, "Unhandled exception in Window Manager", e); |
| 10314 | } |
| 10315 | |
| 10316 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10318 | if (DEBUG_ORIENTATION && mDisplayFrozen) Log.v(TAG, |
| 10319 | "With display frozen, orientationChangeComplete=" |
| 10320 | + orientationChangeComplete); |
| 10321 | if (orientationChangeComplete) { |
| 10322 | if (mWindowsFreezingScreen) { |
| 10323 | mWindowsFreezingScreen = false; |
| 10324 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10325 | } |
| 10326 | if (mAppsFreezingScreen == 0) { |
| 10327 | stopFreezingDisplayLocked(); |
| 10328 | } |
| 10329 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10331 | i = mResizingWindows.size(); |
| 10332 | if (i > 0) { |
| 10333 | do { |
| 10334 | i--; |
| 10335 | WindowState win = mResizingWindows.get(i); |
| 10336 | try { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10337 | if (DEBUG_ORIENTATION) Log.v(TAG, "Reporting new frame to " |
| 10338 | + win + ": " + win.mFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10339 | win.mClient.resized(win.mFrame.width(), |
| 10340 | win.mFrame.height(), win.mLastContentInsets, |
| 10341 | win.mLastVisibleInsets, win.mDrawPending); |
| 10342 | win.mContentInsetsChanged = false; |
| 10343 | win.mVisibleInsetsChanged = false; |
| 10344 | } catch (RemoteException e) { |
| 10345 | win.mOrientationChanging = false; |
| 10346 | } |
| 10347 | } while (i > 0); |
| 10348 | mResizingWindows.clear(); |
| 10349 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10351 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10352 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10353 | i = mDestroySurface.size(); |
| 10354 | if (i > 0) { |
| 10355 | do { |
| 10356 | i--; |
| 10357 | WindowState win = mDestroySurface.get(i); |
| 10358 | win.mDestroying = false; |
| 10359 | if (mInputMethodWindow == win) { |
| 10360 | mInputMethodWindow = null; |
| 10361 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10362 | if (win == mWallpaperTarget) { |
| 10363 | wallpaperDestroyed = true; |
| 10364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10365 | win.destroySurfaceLocked(); |
| 10366 | } while (i > 0); |
| 10367 | mDestroySurface.clear(); |
| 10368 | } |
| 10369 | |
| 10370 | // Time to remove any exiting tokens? |
| 10371 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10372 | WindowToken token = mExitingTokens.get(i); |
| 10373 | if (!token.hasVisible) { |
| 10374 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10375 | if (token.windowType == TYPE_WALLPAPER) { |
| 10376 | mWallpaperTokens.remove(token); |
| 10377 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10378 | } |
| 10379 | } |
| 10380 | |
| 10381 | // Time to remove any exiting applications? |
| 10382 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10383 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10384 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10385 | // Make sure there is no animation running on this token, |
| 10386 | // so any windows associated with it will be removed as |
| 10387 | // soon as their animations are complete |
| 10388 | token.animation = null; |
| 10389 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10390 | mAppTokens.remove(token); |
| 10391 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10392 | if (mLastEnterAnimToken == token) { |
| 10393 | mLastEnterAnimToken = null; |
| 10394 | mLastEnterAnimParams = null; |
| 10395 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10396 | } |
| 10397 | } |
| 10398 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10399 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10400 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10401 | if (!animating && mAppTransitionRunning) { |
| 10402 | // We have finished the animation of an app transition. To do |
| 10403 | // this, we have delayed a lot of operations like showing and |
| 10404 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10405 | // reflects the correct Z-order, but the window list may now |
| 10406 | // be out of sync with it. So here we will just rebuild the |
| 10407 | // entire app window list. Fun! |
| 10408 | mAppTransitionRunning = false; |
| 10409 | needRelayout = true; |
| 10410 | rebuildAppWindowListLocked(); |
| 10411 | // Clear information about apps that were moving. |
| 10412 | mToBottomApps.clear(); |
| 10413 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10415 | if (focusDisplayed) { |
| 10416 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10417 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10418 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10419 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10420 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10421 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10422 | requestAnimationLocked(0); |
| 10423 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10424 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10425 | } |
| 10426 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 10427 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10428 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10429 | } else { |
| 10430 | mPowerManager.setScreenBrightnessOverride((int) |
| 10431 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10432 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10433 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10434 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10435 | } else { |
| 10436 | mPowerManager.setButtonBrightnessOverride((int) |
| 10437 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10438 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10439 | if (holdScreen != mHoldingScreenOn) { |
| 10440 | mHoldingScreenOn = holdScreen; |
| 10441 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10442 | mH.sendMessage(m); |
| 10443 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10444 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10445 | if (mTurnOnScreen) { |
| 10446 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10447 | LocalPowerManager.BUTTON_EVENT, true); |
| 10448 | mTurnOnScreen = false; |
| 10449 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10450 | |
| 10451 | // Check to see if we are now in a state where the screen should |
| 10452 | // be enabled, because the window obscured flags have changed. |
| 10453 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10454 | } |
| 10455 | |
| 10456 | void requestAnimationLocked(long delay) { |
| 10457 | if (!mAnimationPending) { |
| 10458 | mAnimationPending = true; |
| 10459 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10460 | } |
| 10461 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10463 | /** |
| 10464 | * Have the surface flinger show a surface, robustly dealing with |
| 10465 | * error conditions. In particular, if there is not enough memory |
| 10466 | * to show the surface, then we will try to get rid of other surfaces |
| 10467 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10468 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10469 | * @return Returns true if the surface was successfully shown. |
| 10470 | */ |
| 10471 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10472 | try { |
| 10473 | if (win.mSurface != null) { |
| 10474 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10475 | if (win.mTurnOnScreen) { |
| 10476 | win.mTurnOnScreen = false; |
| 10477 | mTurnOnScreen = true; |
| 10478 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10479 | } |
| 10480 | return true; |
| 10481 | } catch (RuntimeException e) { |
| 10482 | Log.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| 10483 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10485 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10487 | return false; |
| 10488 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10490 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10491 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10492 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10493 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10494 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10496 | if (mForceRemoves == null) { |
| 10497 | mForceRemoves = new ArrayList<WindowState>(); |
| 10498 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10500 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10501 | try { |
| 10502 | // There was some problem... first, do a sanity check of the |
| 10503 | // window list to make sure we haven't left any dangling surfaces |
| 10504 | // around. |
| 10505 | int N = mWindows.size(); |
| 10506 | boolean leakedSurface = false; |
| 10507 | Log.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| 10508 | for (int i=0; i<N; i++) { |
| 10509 | WindowState ws = (WindowState)mWindows.get(i); |
| 10510 | if (ws.mSurface != null) { |
| 10511 | if (!mSessions.contains(ws.mSession)) { |
| 10512 | Log.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| 10513 | + ws + " surface=" + ws.mSurface |
| 10514 | + " token=" + win.mToken |
| 10515 | + " pid=" + ws.mSession.mPid |
| 10516 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10517 | ws.mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10518 | ws.mSurface = null; |
| 10519 | mForceRemoves.add(ws); |
| 10520 | i--; |
| 10521 | N--; |
| 10522 | leakedSurface = true; |
| 10523 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| 10524 | Log.w(TAG, "LEAKED SURFACE (app token hidden): " |
| 10525 | + ws + " surface=" + ws.mSurface |
| 10526 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10527 | ws.mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10528 | ws.mSurface = null; |
| 10529 | leakedSurface = true; |
| 10530 | } |
| 10531 | } |
| 10532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10534 | boolean killedApps = false; |
| 10535 | if (!leakedSurface) { |
| 10536 | Log.w(TAG, "No leaked surfaces; killing applicatons!"); |
| 10537 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10538 | for (int i=0; i<N; i++) { |
| 10539 | WindowState ws = (WindowState)mWindows.get(i); |
| 10540 | if (ws.mSurface != null) { |
| 10541 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10542 | } |
| 10543 | } |
| 10544 | if (pidCandidates.size() > 0) { |
| 10545 | int[] pids = new int[pidCandidates.size()]; |
| 10546 | for (int i=0; i<pids.length; i++) { |
| 10547 | pids[i] = pidCandidates.keyAt(i); |
| 10548 | } |
| 10549 | try { |
| 10550 | if (mActivityManager.killPidsForMemory(pids)) { |
| 10551 | killedApps = true; |
| 10552 | } |
| 10553 | } catch (RemoteException e) { |
| 10554 | } |
| 10555 | } |
| 10556 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10558 | if (leakedSurface || killedApps) { |
| 10559 | // We managed to reclaim some memory, so get rid of the trouble |
| 10560 | // surface and ask the app to request another one. |
| 10561 | Log.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 10562 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10563 | surface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10564 | win.mSurface = null; |
| 10565 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10567 | try { |
| 10568 | win.mClient.dispatchGetNewSurface(); |
| 10569 | } catch (RemoteException e) { |
| 10570 | } |
| 10571 | } |
| 10572 | } finally { |
| 10573 | Binder.restoreCallingIdentity(callingIdentity); |
| 10574 | } |
| 10575 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10577 | private boolean updateFocusedWindowLocked(int mode) { |
| 10578 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10579 | if (mCurrentFocus != newFocus) { |
| 10580 | // This check makes sure that we don't already have the focus |
| 10581 | // change message pending. |
| 10582 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10583 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| 10584 | if (localLOGV) Log.v( |
| 10585 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10586 | final WindowState oldFocus = mCurrentFocus; |
| 10587 | mCurrentFocus = newFocus; |
| 10588 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10590 | final WindowState imWindow = mInputMethodWindow; |
| 10591 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10592 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10593 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10594 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10595 | mLayoutNeeded = true; |
| 10596 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10597 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10598 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10599 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10600 | // Client will do the layout, but we need to assign layers |
| 10601 | // for handleNewWindowLocked() below. |
| 10602 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10603 | } |
| 10604 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10605 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10606 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10607 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 10608 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10609 | return true; |
| 10610 | } |
| 10611 | return false; |
| 10612 | } |
| 10613 | |
| 10614 | private WindowState computeFocusedWindowLocked() { |
| 10615 | WindowState result = null; |
| 10616 | WindowState win; |
| 10617 | |
| 10618 | int i = mWindows.size() - 1; |
| 10619 | int nextAppIndex = mAppTokens.size()-1; |
| 10620 | WindowToken nextApp = nextAppIndex >= 0 |
| 10621 | ? mAppTokens.get(nextAppIndex) : null; |
| 10622 | |
| 10623 | while (i >= 0) { |
| 10624 | win = (WindowState)mWindows.get(i); |
| 10625 | |
| 10626 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10627 | TAG, "Looking for focus: " + i |
| 10628 | + " = " + win |
| 10629 | + ", flags=" + win.mAttrs.flags |
| 10630 | + ", canReceive=" + win.canReceiveKeys()); |
| 10631 | |
| 10632 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10634 | // If this window's application has been removed, just skip it. |
| 10635 | if (thisApp != null && thisApp.removed) { |
| 10636 | i--; |
| 10637 | continue; |
| 10638 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10640 | // If there is a focused app, don't allow focus to go to any |
| 10641 | // windows below it. If this is an application window, step |
| 10642 | // through the app tokens until we find its app. |
| 10643 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10644 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10645 | int origAppIndex = nextAppIndex; |
| 10646 | while (nextAppIndex > 0) { |
| 10647 | if (nextApp == mFocusedApp) { |
| 10648 | // Whoops, we are below the focused app... no focus |
| 10649 | // for you! |
| 10650 | if (localLOGV || DEBUG_FOCUS) Log.v( |
| 10651 | TAG, "Reached focused app: " + mFocusedApp); |
| 10652 | return null; |
| 10653 | } |
| 10654 | nextAppIndex--; |
| 10655 | nextApp = mAppTokens.get(nextAppIndex); |
| 10656 | if (nextApp == thisApp) { |
| 10657 | break; |
| 10658 | } |
| 10659 | } |
| 10660 | if (thisApp != nextApp) { |
| 10661 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10662 | // happen, but if it does we can get totally hosed... |
| 10663 | // so restart at the original app. |
| 10664 | nextAppIndex = origAppIndex; |
| 10665 | nextApp = mAppTokens.get(nextAppIndex); |
| 10666 | } |
| 10667 | } |
| 10668 | |
| 10669 | // Dispatch to this window if it is wants key events. |
| 10670 | if (win.canReceiveKeys()) { |
| 10671 | if (DEBUG_FOCUS) Log.v( |
| 10672 | TAG, "Found focus @ " + i + " = " + win); |
| 10673 | result = win; |
| 10674 | break; |
| 10675 | } |
| 10676 | |
| 10677 | i--; |
| 10678 | } |
| 10679 | |
| 10680 | return result; |
| 10681 | } |
| 10682 | |
| 10683 | private void startFreezingDisplayLocked() { |
| 10684 | if (mDisplayFrozen) { |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10685 | // Freezing the display also suspends key event delivery, to |
| 10686 | // keep events from going astray while the display is reconfigured. |
| 10687 | // If someone has changed orientation again while the screen is |
| 10688 | // still frozen, the events will continue to be blocked while the |
| 10689 | // successive orientation change is processed. To prevent spurious |
| 10690 | // ANRs, we reset the event dispatch timeout in this case. |
| 10691 | synchronized (mKeyWaiter) { |
| 10692 | mKeyWaiter.mWasFrozen = true; |
| 10693 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10694 | return; |
| 10695 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10697 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10699 | long now = SystemClock.uptimeMillis(); |
| 10700 | //Log.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| 10701 | if (mFreezeGcPending != 0) { |
| 10702 | if (now > (mFreezeGcPending+1000)) { |
| 10703 | //Log.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| 10704 | mH.removeMessages(H.FORCE_GC); |
| 10705 | Runtime.getRuntime().gc(); |
| 10706 | mFreezeGcPending = now; |
| 10707 | } |
| 10708 | } else { |
| 10709 | mFreezeGcPending = now; |
| 10710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10712 | mDisplayFrozen = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10713 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10714 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10715 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10716 | mAppTransitionReady = true; |
| 10717 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10719 | if (PROFILE_ORIENTATION) { |
| 10720 | File file = new File("/data/system/frozen"); |
| 10721 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10722 | } |
| 10723 | Surface.freezeDisplay(0); |
| 10724 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10726 | private void stopFreezingDisplayLocked() { |
| 10727 | if (!mDisplayFrozen) { |
| 10728 | return; |
| 10729 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10731 | mDisplayFrozen = false; |
| 10732 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10733 | if (PROFILE_ORIENTATION) { |
| 10734 | Debug.stopMethodTracing(); |
| 10735 | } |
| 10736 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10737 | |
Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10738 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 10739 | // too because regular key delivery processing should resume immediately. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10740 | synchronized (mKeyWaiter) { |
| 10741 | mKeyWaiter.mWasFrozen = true; |
| 10742 | mKeyWaiter.notifyAll(); |
| 10743 | } |
| 10744 | |
| 10745 | // A little kludge: a lot could have happened while the |
| 10746 | // display was frozen, so now that we are coming back we |
| 10747 | // do a gc so that any remote references the system |
| 10748 | // processes holds on others can be released if they are |
| 10749 | // no longer needed. |
| 10750 | mH.removeMessages(H.FORCE_GC); |
| 10751 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10752 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10753 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10754 | mScreenFrozenLock.release(); |
| 10755 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10757 | @Override |
| 10758 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10759 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10760 | != PackageManager.PERMISSION_GRANTED) { |
| 10761 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10762 | + Binder.getCallingPid() |
| 10763 | + ", uid=" + Binder.getCallingUid()); |
| 10764 | return; |
| 10765 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10767 | synchronized(mWindowMap) { |
| 10768 | pw.println("Current Window Manager state:"); |
| 10769 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 10770 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10771 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10772 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10773 | w.dump(pw, " "); |
| 10774 | } |
| 10775 | if (mInputMethodDialogs.size() > 0) { |
| 10776 | pw.println(" "); |
| 10777 | pw.println(" Input method dialogs:"); |
| 10778 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10779 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10780 | 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] | 10781 | } |
| 10782 | } |
| 10783 | if (mPendingRemove.size() > 0) { |
| 10784 | pw.println(" "); |
| 10785 | pw.println(" Remove pending for:"); |
| 10786 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10787 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10788 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10789 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10790 | w.dump(pw, " "); |
| 10791 | } |
| 10792 | } |
| 10793 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10794 | pw.println(" "); |
| 10795 | pw.println(" Windows force removing:"); |
| 10796 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10797 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10798 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10799 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10800 | w.dump(pw, " "); |
| 10801 | } |
| 10802 | } |
| 10803 | if (mDestroySurface.size() > 0) { |
| 10804 | pw.println(" "); |
| 10805 | pw.println(" Windows waiting to destroy their surface:"); |
| 10806 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10807 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10808 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10809 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10810 | w.dump(pw, " "); |
| 10811 | } |
| 10812 | } |
| 10813 | if (mLosingFocus.size() > 0) { |
| 10814 | pw.println(" "); |
| 10815 | pw.println(" Windows losing focus:"); |
| 10816 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10817 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10818 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10819 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10820 | w.dump(pw, " "); |
| 10821 | } |
| 10822 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10823 | if (mResizingWindows.size() > 0) { |
| 10824 | pw.println(" "); |
| 10825 | pw.println(" Windows waiting to resize:"); |
| 10826 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10827 | WindowState w = mResizingWindows.get(i); |
| 10828 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10829 | pw.print(w); pw.println(":"); |
| 10830 | w.dump(pw, " "); |
| 10831 | } |
| 10832 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10833 | if (mSessions.size() > 0) { |
| 10834 | pw.println(" "); |
| 10835 | pw.println(" All active sessions:"); |
| 10836 | Iterator<Session> it = mSessions.iterator(); |
| 10837 | while (it.hasNext()) { |
| 10838 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10839 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10840 | s.dump(pw, " "); |
| 10841 | } |
| 10842 | } |
| 10843 | if (mTokenMap.size() > 0) { |
| 10844 | pw.println(" "); |
| 10845 | pw.println(" All tokens:"); |
| 10846 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10847 | while (it.hasNext()) { |
| 10848 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10849 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10850 | token.dump(pw, " "); |
| 10851 | } |
| 10852 | } |
| 10853 | if (mTokenList.size() > 0) { |
| 10854 | pw.println(" "); |
| 10855 | pw.println(" Window token list:"); |
| 10856 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10857 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10858 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10859 | } |
| 10860 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10861 | if (mWallpaperTokens.size() > 0) { |
| 10862 | pw.println(" "); |
| 10863 | pw.println(" Wallpaper tokens:"); |
| 10864 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10865 | WindowToken token = mWallpaperTokens.get(i); |
| 10866 | pw.print(" Wallpaper #"); pw.print(i); |
| 10867 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10868 | token.dump(pw, " "); |
| 10869 | } |
| 10870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10871 | if (mAppTokens.size() > 0) { |
| 10872 | pw.println(" "); |
| 10873 | pw.println(" Application tokens in Z order:"); |
| 10874 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10875 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10876 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10877 | } |
| 10878 | } |
| 10879 | if (mFinishedStarting.size() > 0) { |
| 10880 | pw.println(" "); |
| 10881 | pw.println(" Finishing start of application tokens:"); |
| 10882 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10883 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10884 | pw.print(" Finished Starting #"); pw.print(i); |
| 10885 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10886 | token.dump(pw, " "); |
| 10887 | } |
| 10888 | } |
| 10889 | if (mExitingTokens.size() > 0) { |
| 10890 | pw.println(" "); |
| 10891 | pw.println(" Exiting tokens:"); |
| 10892 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10893 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10894 | pw.print(" Exiting #"); pw.print(i); |
| 10895 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10896 | token.dump(pw, " "); |
| 10897 | } |
| 10898 | } |
| 10899 | if (mExitingAppTokens.size() > 0) { |
| 10900 | pw.println(" "); |
| 10901 | pw.println(" Exiting application tokens:"); |
| 10902 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10903 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10904 | pw.print(" Exiting App #"); pw.print(i); |
| 10905 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10906 | token.dump(pw, " "); |
| 10907 | } |
| 10908 | } |
| 10909 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10910 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10911 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10912 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10913 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10914 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10915 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10916 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10917 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10918 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10919 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10920 | pw.print(" mInTouchMode="); pw.println(mInTouchMode); |
| 10921 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10922 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10923 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10924 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10925 | if (mDimAnimator != null) { |
| 10926 | mDimAnimator.printTo(pw); |
| 10927 | } else { |
| 10928 | pw.print( " no DimAnimator "); |
| 10929 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10930 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10931 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10932 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10933 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10934 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10935 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10936 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10937 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| 10938 | pw.print(" mAppsFreezingScreen="); pw.println(mAppsFreezingScreen); |
| 10939 | pw.print(" mRotation="); pw.print(mRotation); |
| 10940 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10941 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10942 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10943 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10944 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10945 | pw.print(" mNextAppTransition=0x"); |
| 10946 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10947 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10948 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10949 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10950 | if (mNextAppTransitionPackage != null) { |
| 10951 | pw.print(" mNextAppTransitionPackage="); |
| 10952 | pw.print(mNextAppTransitionPackage); |
| 10953 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10954 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10955 | pw.print(", mNextAppTransitionExit=0x"); |
| 10956 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10957 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10958 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10959 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10960 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10961 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10962 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10963 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10964 | if (mOpeningApps.size() > 0) { |
| 10965 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10966 | } |
| 10967 | if (mClosingApps.size() > 0) { |
| 10968 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10969 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10970 | if (mToTopApps.size() > 0) { |
| 10971 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10972 | } |
| 10973 | if (mToBottomApps.size() > 0) { |
| 10974 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10975 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10976 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10977 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10978 | pw.println(" KeyWaiter state:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10979 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 10980 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 10981 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 10982 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 10983 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 10984 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10985 | } |
| 10986 | } |
| 10987 | |
| 10988 | public void monitor() { |
| 10989 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10990 | synchronized (mKeyguardTokenWatcher) { } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10991 | synchronized (mKeyWaiter) { } |
| 10992 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10993 | |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10994 | public void virtualKeyFeedback(KeyEvent event) { |
| 10995 | mPolicy.keyFeedbackFromInput(event); |
| 10996 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10997 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10998 | /** |
| 10999 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11000 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11001 | */ |
| 11002 | private static class DimAnimator { |
| 11003 | Surface mDimSurface; |
| 11004 | boolean mDimShown = false; |
| 11005 | float mDimCurrentAlpha; |
| 11006 | float mDimTargetAlpha; |
| 11007 | float mDimDeltaPerMs; |
| 11008 | long mLastDimAnimTime; |
| 11009 | |
| 11010 | DimAnimator (SurfaceSession session) { |
| 11011 | if (mDimSurface == null) { |
| 11012 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 11013 | + mDimSurface + ": CREATE"); |
| 11014 | try { |
| 11015 | mDimSurface = new Surface(session, 0, -1, 16, 16, PixelFormat.OPAQUE, |
| 11016 | Surface.FX_SURFACE_DIM); |
| 11017 | } catch (Exception e) { |
| 11018 | Log.e(TAG, "Exception creating Dim surface", e); |
| 11019 | } |
| 11020 | } |
| 11021 | } |
| 11022 | |
| 11023 | /** |
| 11024 | * Show the dim surface. |
| 11025 | */ |
| 11026 | void show(int dw, int dh) { |
| 11027 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11028 | dw + "x" + dh + ")"); |
| 11029 | mDimShown = true; |
| 11030 | try { |
| 11031 | mDimSurface.setPosition(0, 0); |
| 11032 | mDimSurface.setSize(dw, dh); |
| 11033 | mDimSurface.show(); |
| 11034 | } catch (RuntimeException e) { |
| 11035 | Log.w(TAG, "Failure showing dim surface", e); |
| 11036 | } |
| 11037 | } |
| 11038 | |
| 11039 | /** |
| 11040 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11041 | * {@link updateSurface} after all windows are examined. |
| 11042 | */ |
| 11043 | void updateParameters(WindowState w, long currentTime) { |
| 11044 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11045 | |
| 11046 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11047 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 11048 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11049 | if (mDimTargetAlpha != target) { |
| 11050 | // If the desired dim level has changed, then |
| 11051 | // start an animation to it. |
| 11052 | mLastDimAnimTime = currentTime; |
| 11053 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11054 | ? w.mAnimation.computeDurationHint() |
| 11055 | : DEFAULT_DIM_DURATION; |
| 11056 | if (target > mDimTargetAlpha) { |
| 11057 | // This is happening behind the activity UI, |
| 11058 | // so we can make it run a little longer to |
| 11059 | // give a stronger impression without disrupting |
| 11060 | // the user. |
| 11061 | duration *= DIM_DURATION_MULTIPLIER; |
| 11062 | } |
| 11063 | if (duration < 1) { |
| 11064 | // Don't divide by zero |
| 11065 | duration = 1; |
| 11066 | } |
| 11067 | mDimTargetAlpha = target; |
| 11068 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11069 | } |
| 11070 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11071 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11072 | /** |
| 11073 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11074 | * false when the animation is finished and the dim surface is hidden. |
| 11075 | */ |
| 11076 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11077 | if (!dimming) { |
| 11078 | if (mDimTargetAlpha != 0) { |
| 11079 | mLastDimAnimTime = currentTime; |
| 11080 | mDimTargetAlpha = 0; |
| 11081 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11082 | } |
| 11083 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11084 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11085 | boolean animating = false; |
| 11086 | if (mLastDimAnimTime != 0) { |
| 11087 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11088 | * (currentTime-mLastDimAnimTime); |
| 11089 | boolean more = true; |
| 11090 | if (displayFrozen) { |
| 11091 | // If the display is frozen, there is no reason to animate. |
| 11092 | more = false; |
| 11093 | } else if (mDimDeltaPerMs > 0) { |
| 11094 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11095 | more = false; |
| 11096 | } |
| 11097 | } else if (mDimDeltaPerMs < 0) { |
| 11098 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11099 | more = false; |
| 11100 | } |
| 11101 | } else { |
| 11102 | more = false; |
| 11103 | } |
| 11104 | |
| 11105 | // Do we need to continue animating? |
| 11106 | if (more) { |
| 11107 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 11108 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11109 | mLastDimAnimTime = currentTime; |
| 11110 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11111 | animating = true; |
| 11112 | } else { |
| 11113 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11114 | mLastDimAnimTime = 0; |
| 11115 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " |
| 11116 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11117 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11118 | if (!dimming) { |
| 11119 | if (SHOW_TRANSACTIONS) Log.i(TAG, " DIM " + mDimSurface |
| 11120 | + ": HIDE"); |
| 11121 | try { |
| 11122 | mDimSurface.hide(); |
| 11123 | } catch (RuntimeException e) { |
| 11124 | Log.w(TAG, "Illegal argument exception hiding dim surface"); |
| 11125 | } |
| 11126 | mDimShown = false; |
| 11127 | } |
| 11128 | } |
| 11129 | } |
| 11130 | return animating; |
| 11131 | } |
| 11132 | |
| 11133 | public void printTo(PrintWriter pw) { |
| 11134 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11135 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11136 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11137 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11138 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11139 | } |
| 11140 | } |
| 11141 | |
| 11142 | /** |
| 11143 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11144 | * This is used for opening/closing transition for apps in compatible mode. |
| 11145 | */ |
| 11146 | private static class FadeInOutAnimation extends Animation { |
| 11147 | int mWidth; |
| 11148 | boolean mFadeIn; |
| 11149 | |
| 11150 | public FadeInOutAnimation(boolean fadeIn) { |
| 11151 | setInterpolator(new AccelerateInterpolator()); |
| 11152 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11153 | mFadeIn = fadeIn; |
| 11154 | } |
| 11155 | |
| 11156 | @Override |
| 11157 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11158 | float x = interpolatedTime; |
| 11159 | if (!mFadeIn) { |
| 11160 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11161 | } |
| 11162 | if (x < 0.5) { |
| 11163 | // move the window out of the screen. |
| 11164 | t.getMatrix().setTranslate(mWidth, 0); |
| 11165 | } else { |
| 11166 | t.getMatrix().setTranslate(0, 0);// show |
| 11167 | t.setAlpha((x - 0.5f) * 2); |
| 11168 | } |
| 11169 | } |
| 11170 | |
| 11171 | @Override |
| 11172 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11173 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11174 | mWidth = width; |
| 11175 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11176 | |
| 11177 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11178 | public int getZAdjustment() { |
| 11179 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11180 | } |
| 11181 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11182 | } |