| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import static android.os.LocalPowerManager.CHEEK_EVENT; |
| 20 | import static android.os.LocalPowerManager.OTHER_EVENT; |
| 21 | import static android.os.LocalPowerManager.TOUCH_EVENT; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 22 | import static android.os.LocalPowerManager.LONG_TOUCH_EVENT; |
| 23 | import static android.os.LocalPowerManager.TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 25 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 26 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 32 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 33 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 36 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS; |
| 38 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 39 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 40 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 41 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
| 44 | import com.android.internal.app.IBatteryStats; |
| 45 | import com.android.internal.policy.PolicyManager; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 46 | import com.android.internal.policy.impl.PhoneWindowManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import com.android.internal.view.IInputContext; |
| 48 | import com.android.internal.view.IInputMethodClient; |
| 49 | import com.android.internal.view.IInputMethodManager; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 50 | import com.android.internal.view.WindowManagerPolicyThread; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import com.android.server.KeyInputQueue.QueuedEvent; |
| 52 | import com.android.server.am.BatteryStatsService; |
| 53 | |
| 54 | import android.Manifest; |
| 55 | import android.app.ActivityManagerNative; |
| 56 | import android.app.IActivityManager; |
| 57 | import android.content.Context; |
| 58 | import android.content.pm.ActivityInfo; |
| 59 | import android.content.pm.PackageManager; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 60 | import android.content.res.CompatibilityInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.content.res.Configuration; |
| 62 | import android.graphics.Matrix; |
| 63 | import android.graphics.PixelFormat; |
| 64 | import android.graphics.Rect; |
| 65 | import android.graphics.Region; |
| 66 | import android.os.BatteryStats; |
| 67 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 68 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.os.Debug; |
| 70 | import android.os.Handler; |
| 71 | import android.os.IBinder; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 72 | import android.os.LatencyTimer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.os.LocalPowerManager; |
| 74 | import android.os.Looper; |
| 75 | import android.os.Message; |
| 76 | import android.os.Parcel; |
| 77 | import android.os.ParcelFileDescriptor; |
| 78 | import android.os.Power; |
| 79 | import android.os.PowerManager; |
| 80 | import android.os.Process; |
| 81 | import android.os.RemoteException; |
| 82 | import android.os.ServiceManager; |
| 83 | import android.os.SystemClock; |
| 84 | import android.os.SystemProperties; |
| 85 | import android.os.TokenWatcher; |
| 86 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 87 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.util.EventLog; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 89 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.util.SparseIntArray; |
| 91 | import android.view.Display; |
| 92 | import android.view.Gravity; |
| 93 | import android.view.IApplicationToken; |
| 94 | import android.view.IOnKeyguardExitResult; |
| 95 | import android.view.IRotationWatcher; |
| 96 | import android.view.IWindow; |
| 97 | import android.view.IWindowManager; |
| 98 | import android.view.IWindowSession; |
| 99 | import android.view.KeyEvent; |
| 100 | import android.view.MotionEvent; |
| 101 | import android.view.RawInputEvent; |
| 102 | import android.view.Surface; |
| 103 | import android.view.SurfaceSession; |
| 104 | import android.view.View; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 105 | import android.view.ViewConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.ViewTreeObserver; |
| 107 | import android.view.WindowManager; |
| 108 | import android.view.WindowManagerImpl; |
| 109 | import android.view.WindowManagerPolicy; |
| 110 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 111 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import android.view.animation.Animation; |
| 113 | import android.view.animation.AnimationUtils; |
| 114 | import android.view.animation.Transformation; |
| 115 | |
| 116 | import java.io.BufferedWriter; |
| 117 | import java.io.File; |
| 118 | import java.io.FileDescriptor; |
| 119 | import java.io.IOException; |
| 120 | import java.io.OutputStream; |
| 121 | import java.io.OutputStreamWriter; |
| 122 | import java.io.PrintWriter; |
| 123 | import java.io.StringWriter; |
| 124 | import java.net.Socket; |
| 125 | import java.util.ArrayList; |
| 126 | import java.util.HashMap; |
| 127 | import java.util.HashSet; |
| 128 | import java.util.Iterator; |
| 129 | import java.util.List; |
| 130 | |
| 131 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 132 | public class WindowManagerService extends IWindowManager.Stub |
| 133 | implements Watchdog.Monitor, KeyInputQueue.HapticFeedbackCallback { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | static final String TAG = "WindowManager"; |
| 135 | static final boolean DEBUG = false; |
| 136 | static final boolean DEBUG_FOCUS = false; |
| 137 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 138 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 139 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | static final boolean DEBUG_LAYERS = false; |
| 141 | static final boolean DEBUG_INPUT = false; |
| 142 | static final boolean DEBUG_INPUT_METHOD = false; |
| 143 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 146 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 148 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 149 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 150 | static final boolean DEBUG_WALLPAPER = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 152 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 153 | static final boolean MEASURE_LATENCY = false; |
| 154 | static private LatencyTimer lt; |
| 155 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | static final boolean PROFILE_ORIENTATION = false; |
| 157 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 158 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | /** How long to wait for subsequent key repeats, in milliseconds */ |
| 161 | static final int KEY_REPEAT_DELAY = 50; |
| 162 | |
| 163 | /** How much to multiply the policy's type layer, to reserve room |
| 164 | * for multiple windows of the same type and Z-ordering adjustment |
| 165 | * with TYPE_LAYER_OFFSET. */ |
| 166 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 169 | * or below others in the same layer. */ |
| 170 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | /** How much to increment the layer for each window, to reserve room |
| 173 | * for effect surfaces between them. |
| 174 | */ |
| 175 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 176 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** The maximum length we will accept for a loaded animation duration: |
| 178 | * this is 10 seconds. |
| 179 | */ |
| 180 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 181 | |
| 182 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 183 | * value to another, when no window animation is driving it. |
| 184 | */ |
| 185 | static final int DEFAULT_DIM_DURATION = 200; |
| 186 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 187 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 188 | * compatible windows. |
| 189 | */ |
| 190 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 193 | */ |
| 194 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 195 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 196 | static final int INJECT_FAILED = 0; |
| 197 | static final int INJECT_SUCCEEDED = 1; |
| 198 | static final int INJECT_NO_PERMISSION = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 199 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 201 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 202 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 203 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 204 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 205 | /** The minimum time between dispatching touch events. */ |
| 206 | int mMinWaitTimeBetweenTouchEvents = 1000 / 35; |
| 207 | |
| 208 | // Last touch event time |
| 209 | long mLastTouchEventTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 210 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 211 | // Last touch event type |
| 212 | int mLastTouchEventType = OTHER_EVENT; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 213 | |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 214 | // Time to wait before calling useractivity again. This saves CPU usage |
| 215 | // when we get a flood of touch events. |
| 216 | static final int MIN_TIME_BETWEEN_USERACTIVITIES = 1000; |
| 217 | |
| 218 | // Last time we call user activity |
| 219 | long mLastUserActivityCallTime = 0; |
| 220 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 221 | // Last time we updated battery stats |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 222 | long mLastBatteryStatsCallTime = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 225 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 229 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 230 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 231 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 233 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 235 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 236 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | public void acquired() { |
| 238 | mPolicy.enableKeyguard(false); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 239 | mKeyguardDisabled = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | } |
| 241 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 242 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 243 | synchronized (mKeyguardTokenWatcher) { |
| 244 | mKeyguardDisabled = false; |
| 245 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | }; |
| 249 | |
| 250 | final Context mContext; |
| 251 | |
| 252 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 255 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 257 | |
| 258 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 259 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | /** |
| 263 | * All currently active sessions with clients. |
| 264 | */ |
| 265 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | /** |
| 268 | * Mapping from an IWindow IBinder to the server's Window object. |
| 269 | * This is also used as the lock for all of our state. |
| 270 | */ |
| 271 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 272 | |
| 273 | /** |
| 274 | * Mapping from a token IBinder to a WindowToken object. |
| 275 | */ |
| 276 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 277 | new HashMap<IBinder, WindowToken>(); |
| 278 | |
| 279 | /** |
| 280 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 281 | * over them. |
| 282 | */ |
| 283 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | /** |
| 286 | * Window tokens that are in the process of exiting, but still |
| 287 | * on screen for animations. |
| 288 | */ |
| 289 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 290 | |
| 291 | /** |
| 292 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 293 | * controlling the ordering of windows in different applications. This |
| 294 | * contains WindowToken objects. |
| 295 | */ |
| 296 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 297 | |
| 298 | /** |
| 299 | * Application tokens that are in the process of exiting, but still |
| 300 | * on screen for animations. |
| 301 | */ |
| 302 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 303 | |
| 304 | /** |
| 305 | * List of window tokens that have finished starting their application, |
| 306 | * and now need to have the policy remove their windows. |
| 307 | */ |
| 308 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 309 | |
| 310 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 311 | * This was the app token that was used to retrieve the last enter |
| 312 | * animation. It will be used for the next exit animation. |
| 313 | */ |
| 314 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 315 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 316 | /** |
| 317 | * These were the layout params used to retrieve the last enter animation. |
| 318 | * They will be used for the next exit animation. |
| 319 | */ |
| 320 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 321 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 322 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | * Z-ordered (bottom-most first) list of all Window objects. |
| 324 | */ |
| 325 | final ArrayList mWindows = new ArrayList(); |
| 326 | |
| 327 | /** |
| 328 | * Windows that are being resized. Used so we can tell the client about |
| 329 | * the resize after closing the transaction in which we resized the |
| 330 | * underlying surface. |
| 331 | */ |
| 332 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 333 | |
| 334 | /** |
| 335 | * Windows whose animations have ended and now must be removed. |
| 336 | */ |
| 337 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 338 | |
| 339 | /** |
| 340 | * Windows whose surface should be destroyed. |
| 341 | */ |
| 342 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 343 | |
| 344 | /** |
| 345 | * Windows that have lost input focus and are waiting for the new |
| 346 | * focus window to be displayed before they are told about this. |
| 347 | */ |
| 348 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 349 | |
| 350 | /** |
| 351 | * This is set when we have run out of memory, and will either be an empty |
| 352 | * list or contain windows that need to be force removed. |
| 353 | */ |
| 354 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 359 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | Surface mBlurSurface; |
| 361 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | final float[] mTmpFloats = new float[9]; |
| 366 | |
| 367 | boolean mSafeMode; |
| 368 | boolean mDisplayEnabled = false; |
| 369 | boolean mSystemBooted = false; |
| 370 | int mRotation = 0; |
| 371 | int mRequestedRotation = 0; |
| 372 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 373 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | ArrayList<IRotationWatcher> mRotationWatchers |
| 375 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 376 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | boolean mLayoutNeeded = true; |
| 378 | boolean mAnimationPending = false; |
| 379 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 380 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | boolean mWindowsFreezingScreen = false; |
| 382 | long mFreezeGcPending = 0; |
| 383 | int mAppsFreezingScreen = 0; |
| 384 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 385 | int mLayoutSeq = 0; |
| 386 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 387 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 388 | boolean mFocusMayChange; |
| 389 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 390 | Configuration mCurConfiguration = new Configuration(); |
| 391 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | // This is held as long as we have the screen frozen, to give us time to |
| 393 | // perform a rotation animation when turning off shows the lock screen which |
| 394 | // changes the orientation. |
| 395 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 396 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | // State management of app transitions. When we are preparing for a |
| 398 | // transition, mNextAppTransition will be the kind of transition to |
| 399 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 400 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 401 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 402 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 403 | String mNextAppTransitionPackage; |
| 404 | int mNextAppTransitionEnter; |
| 405 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 407 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | boolean mAppTransitionTimeout = false; |
| 409 | boolean mStartingIconInTransition = false; |
| 410 | boolean mSkipAppTransitionAnimation = false; |
| 411 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 412 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 413 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 414 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 415 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | //flag to detect fat touch events |
| 417 | boolean mFatTouch = false; |
| 418 | Display mDisplay; |
| 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 | H mH = new H(); |
| 421 | |
| 422 | WindowState mCurrentFocus = null; |
| 423 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 424 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | // This just indicates the window the input method is on top of, not |
| 426 | // necessarily the window its input is going to. |
| 427 | WindowState mInputMethodTarget = null; |
| 428 | WindowState mUpcomingInputMethodTarget = null; |
| 429 | boolean mInputMethodTargetWaitingAnim; |
| 430 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | WindowState mInputMethodWindow = null; |
| 433 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 434 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 435 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 436 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 437 | // If non-null, this is the currently visible window that is associated |
| 438 | // with the wallpaper. |
| 439 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 440 | // If non-null, we are in the middle of animating from one wallpaper target |
| 441 | // to another, and this is the lower one in Z-order. |
| 442 | WindowState mLowerWallpaperTarget = null; |
| 443 | // If non-null, we are in the middle of animating from one wallpaper target |
| 444 | // to another, and this is the higher one in Z-order. |
| 445 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 446 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 447 | float mLastWallpaperX = -1; |
| 448 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 449 | float mLastWallpaperXStep = -1; |
| 450 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 451 | boolean mSendingPointersToWallpaper = false; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 452 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 453 | // changing its scroll position. |
| 454 | WindowState mWaitingOnWallpaper; |
| 455 | // The last time we had a timeout when waiting for a wallpaper. |
| 456 | long mLastWallpaperTimeoutTime; |
| 457 | // We give a wallpaper up to 150ms to finish scrolling. |
| 458 | static final long WALLPAPER_TIMEOUT = 150; |
| 459 | // Time we wait after a timeout before trying to wait again. |
| 460 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | AppWindowToken mFocusedApp = null; |
| 463 | |
| 464 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | float mWindowAnimationScale = 1.0f; |
| 467 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 468 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | final KeyWaiter mKeyWaiter = new KeyWaiter(); |
| 470 | final KeyQ mQueue; |
| 471 | final InputDispatcherThread mInputThread; |
| 472 | |
| 473 | // Who is holding the screen on. |
| 474 | Session mHoldingScreenOn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 475 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 476 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 477 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | /** |
| 479 | * Whether the UI is currently running in touch mode (not showing |
| 480 | * navigational focus because the user is directly pressing the screen). |
| 481 | */ |
| 482 | boolean mInTouchMode = false; |
| 483 | |
| 484 | private ViewServer mViewServer; |
| 485 | |
| 486 | final Rect mTempRect = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 487 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 488 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 489 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 490 | |
| 491 | // The frame use to limit the size of the app running in compatibility mode. |
| 492 | Rect mCompatibleScreenFrame = new Rect(); |
| 493 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 494 | Surface mBackgroundFillerSurface = null; |
| 495 | boolean mBackgroundFillerShown = false; |
| 496 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | public static WindowManagerService main(Context context, |
| 498 | PowerManagerService pm, boolean haveInputMethods) { |
| 499 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 500 | thr.start(); |
| 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 | synchronized (thr) { |
| 503 | while (thr.mService == null) { |
| 504 | try { |
| 505 | thr.wait(); |
| 506 | } catch (InterruptedException e) { |
| 507 | } |
| 508 | } |
| 509 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 510 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | return thr.mService; |
| 512 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 513 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | static class WMThread extends Thread { |
| 515 | WindowManagerService mService; |
| 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 | private final Context mContext; |
| 518 | private final PowerManagerService mPM; |
| 519 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 520 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | public WMThread(Context context, PowerManagerService pm, |
| 522 | boolean haveInputMethods) { |
| 523 | super("WindowManager"); |
| 524 | mContext = context; |
| 525 | mPM = pm; |
| 526 | mHaveInputMethods = haveInputMethods; |
| 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 | public void run() { |
| 530 | Looper.prepare(); |
| 531 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 532 | mHaveInputMethods); |
| 533 | android.os.Process.setThreadPriority( |
| 534 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | synchronized (this) { |
| 537 | mService = s; |
| 538 | notifyAll(); |
| 539 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 540 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | Looper.loop(); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | static class PolicyThread extends Thread { |
| 546 | private final WindowManagerPolicy mPolicy; |
| 547 | private final WindowManagerService mService; |
| 548 | private final Context mContext; |
| 549 | private final PowerManagerService mPM; |
| 550 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | public PolicyThread(WindowManagerPolicy policy, |
| 553 | WindowManagerService service, Context context, |
| 554 | PowerManagerService pm) { |
| 555 | super("WindowManagerPolicy"); |
| 556 | mPolicy = policy; |
| 557 | mService = service; |
| 558 | mContext = context; |
| 559 | mPM = pm; |
| 560 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 561 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | public void run() { |
| 563 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 564 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 565 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 567 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | android.os.Process.setThreadPriority( |
| 569 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 570 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | synchronized (this) { |
| 573 | mRunning = true; |
| 574 | notifyAll(); |
| 575 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 576 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | Looper.loop(); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | private WindowManagerService(Context context, PowerManagerService pm, |
| 582 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 583 | if (MEASURE_LATENCY) { |
| 584 | lt = new LatencyTimer(100, 1000); |
| 585 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 586 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | mContext = context; |
| 588 | mHaveInputMethods = haveInputMethods; |
| 589 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 590 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | mPowerManager = pm; |
| 593 | mPowerManager.setPolicy(mPolicy); |
| 594 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 595 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 596 | "SCREEN_FROZEN"); |
| 597 | mScreenFrozenLock.setReferenceCounted(false); |
| 598 | |
| 599 | mActivityManager = ActivityManagerNative.getDefault(); |
| 600 | mBatteryStats = BatteryStatsService.getService(); |
| 601 | |
| 602 | // Get persisted window scale setting |
| 603 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 604 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 605 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 606 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 607 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 608 | int max_events_per_sec = 35; |
| 609 | try { |
| 610 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 611 | .get("windowsmgr.max_events_per_sec")); |
| 612 | if (max_events_per_sec < 1) { |
| 613 | max_events_per_sec = 35; |
| 614 | } |
| 615 | } catch (NumberFormatException e) { |
| 616 | } |
| 617 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 618 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | mQueue = new KeyQ(); |
| 620 | |
| 621 | mInputThread = new InputDispatcherThread(); |
| 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 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 624 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 625 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | synchronized (thr) { |
| 627 | while (!thr.mRunning) { |
| 628 | try { |
| 629 | thr.wait(); |
| 630 | } catch (InterruptedException e) { |
| 631 | } |
| 632 | } |
| 633 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 634 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | mInputThread.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | // Add ourself to the Watchdog monitors. |
| 638 | Watchdog.getInstance().addMonitor(this); |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 643 | throws RemoteException { |
| 644 | try { |
| 645 | return super.onTransact(code, data, reply, flags); |
| 646 | } catch (RuntimeException e) { |
| 647 | // The window manager only throws security exceptions, so let's |
| 648 | // log all others. |
| 649 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 650 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | } |
| 652 | throw e; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | private void placeWindowAfter(Object pos, WindowState window) { |
| 657 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 658 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | TAG, "Adding window " + window + " at " |
| 660 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 661 | mWindows.add(i+1, window); |
| 662 | } |
| 663 | |
| 664 | private void placeWindowBefore(Object pos, WindowState window) { |
| 665 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 666 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | TAG, "Adding window " + window + " at " |
| 668 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 669 | mWindows.add(i, window); |
| 670 | } |
| 671 | |
| 672 | //This method finds out the index of a window that has the same app token as |
| 673 | //win. used for z ordering the windows in mWindows |
| 674 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 675 | //use a local variable to cache mWindows |
| 676 | ArrayList localmWindows = mWindows; |
| 677 | int jmax = localmWindows.size(); |
| 678 | if(jmax == 0) { |
| 679 | return -1; |
| 680 | } |
| 681 | for(int j = (jmax-1); j >= 0; j--) { |
| 682 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 683 | if(wentry.mAppToken == win.mAppToken) { |
| 684 | return j; |
| 685 | } |
| 686 | } |
| 687 | return -1; |
| 688 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 691 | final IWindow client = win.mClient; |
| 692 | final WindowToken token = win.mToken; |
| 693 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 694 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | final int N = localmWindows.size(); |
| 696 | final WindowState attached = win.mAttachedWindow; |
| 697 | int i; |
| 698 | if (attached == null) { |
| 699 | int tokenWindowsPos = token.windows.size(); |
| 700 | if (token.appWindowToken != null) { |
| 701 | int index = tokenWindowsPos-1; |
| 702 | if (index >= 0) { |
| 703 | // If this application has existing windows, we |
| 704 | // simply place the new window on top of them... but |
| 705 | // keep the starting window on top. |
| 706 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 707 | // Base windows go behind everything else. |
| 708 | placeWindowBefore(token.windows.get(0), win); |
| 709 | tokenWindowsPos = 0; |
| 710 | } else { |
| 711 | AppWindowToken atoken = win.mAppToken; |
| 712 | if (atoken != null && |
| 713 | token.windows.get(index) == atoken.startingWindow) { |
| 714 | placeWindowBefore(token.windows.get(index), win); |
| 715 | tokenWindowsPos--; |
| 716 | } else { |
| 717 | int newIdx = findIdxBasedOnAppTokens(win); |
| 718 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 719 | //there is a window above this one associated with the same |
| 720 | //apptoken note that the window could be a floating window |
| 721 | //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] | 722 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 723 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 724 | TAG, "Adding window " + win + " at " |
| 725 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | localmWindows.add(newIdx+1, win); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 727 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 731 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | TAG, "Figuring out where to add app window " |
| 733 | + client.asBinder() + " (token=" + token + ")"); |
| 734 | // Figure out where the window should go, based on the |
| 735 | // order of applications. |
| 736 | final int NA = mAppTokens.size(); |
| 737 | Object pos = null; |
| 738 | for (i=NA-1; i>=0; i--) { |
| 739 | AppWindowToken t = mAppTokens.get(i); |
| 740 | if (t == token) { |
| 741 | i--; |
| 742 | break; |
| 743 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 744 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 745 | // We haven't reached the token yet; if this token |
| 746 | // is not going to the bottom and has windows, we can |
| 747 | // use it as an anchor for when we do reach the token. |
| 748 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | pos = t.windows.get(0); |
| 750 | } |
| 751 | } |
| 752 | // We now know the index into the apps. If we found |
| 753 | // an app window above, that gives us the position; else |
| 754 | // we need to look some more. |
| 755 | if (pos != null) { |
| 756 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 757 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 759 | if (atoken != null) { |
| 760 | final int NC = atoken.windows.size(); |
| 761 | if (NC > 0) { |
| 762 | WindowState bottom = atoken.windows.get(0); |
| 763 | if (bottom.mSubLayer < 0) { |
| 764 | pos = bottom; |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | placeWindowBefore(pos, win); |
| 769 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 770 | // Continue looking down until we find the first |
| 771 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | while (i >= 0) { |
| 773 | AppWindowToken t = mAppTokens.get(i); |
| 774 | final int NW = t.windows.size(); |
| 775 | if (NW > 0) { |
| 776 | pos = t.windows.get(NW-1); |
| 777 | break; |
| 778 | } |
| 779 | i--; |
| 780 | } |
| 781 | if (pos != null) { |
| 782 | // Move in front of any windows attached to this |
| 783 | // one. |
| 784 | WindowToken atoken = |
| 785 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 786 | if (atoken != null) { |
| 787 | final int NC = atoken.windows.size(); |
| 788 | if (NC > 0) { |
| 789 | WindowState top = atoken.windows.get(NC-1); |
| 790 | if (top.mSubLayer >= 0) { |
| 791 | pos = top; |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | placeWindowAfter(pos, win); |
| 796 | } else { |
| 797 | // Just search for the start of this layer. |
| 798 | final int myLayer = win.mBaseLayer; |
| 799 | for (i=0; i<N; i++) { |
| 800 | WindowState w = (WindowState)localmWindows.get(i); |
| 801 | if (w.mBaseLayer > myLayer) { |
| 802 | break; |
| 803 | } |
| 804 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 805 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 806 | TAG, "Adding window " + win + " at " |
| 807 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | localmWindows.add(i, win); |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | } else { |
| 813 | // Figure out where window should go, based on layer. |
| 814 | final int myLayer = win.mBaseLayer; |
| 815 | for (i=N-1; i>=0; i--) { |
| 816 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 817 | i++; |
| 818 | break; |
| 819 | } |
| 820 | } |
| 821 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 822 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 823 | TAG, "Adding window " + win + " at " |
| 824 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | localmWindows.add(i, win); |
| 826 | } |
| 827 | if (addToToken) { |
| 828 | token.windows.add(tokenWindowsPos, win); |
| 829 | } |
| 830 | |
| 831 | } else { |
| 832 | // Figure out this window's ordering relative to the window |
| 833 | // it is attached to. |
| 834 | final int NA = token.windows.size(); |
| 835 | final int sublayer = win.mSubLayer; |
| 836 | int largestSublayer = Integer.MIN_VALUE; |
| 837 | WindowState windowWithLargestSublayer = null; |
| 838 | for (i=0; i<NA; i++) { |
| 839 | WindowState w = token.windows.get(i); |
| 840 | final int wSublayer = w.mSubLayer; |
| 841 | if (wSublayer >= largestSublayer) { |
| 842 | largestSublayer = wSublayer; |
| 843 | windowWithLargestSublayer = w; |
| 844 | } |
| 845 | if (sublayer < 0) { |
| 846 | // For negative sublayers, we go below all windows |
| 847 | // in the same sublayer. |
| 848 | if (wSublayer >= sublayer) { |
| 849 | if (addToToken) { |
| 850 | token.windows.add(i, win); |
| 851 | } |
| 852 | placeWindowBefore( |
| 853 | wSublayer >= 0 ? attached : w, win); |
| 854 | break; |
| 855 | } |
| 856 | } else { |
| 857 | // For positive sublayers, we go above all windows |
| 858 | // in the same sublayer. |
| 859 | if (wSublayer > sublayer) { |
| 860 | if (addToToken) { |
| 861 | token.windows.add(i, win); |
| 862 | } |
| 863 | placeWindowBefore(w, win); |
| 864 | break; |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | if (i >= NA) { |
| 869 | if (addToToken) { |
| 870 | token.windows.add(win); |
| 871 | } |
| 872 | if (sublayer < 0) { |
| 873 | placeWindowBefore(attached, win); |
| 874 | } else { |
| 875 | placeWindowAfter(largestSublayer >= 0 |
| 876 | ? windowWithLargestSublayer |
| 877 | : attached, |
| 878 | win); |
| 879 | } |
| 880 | } |
| 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 | if (win.mAppToken != null && addToToken) { |
| 884 | win.mAppToken.allAppWindows.add(win); |
| 885 | } |
| 886 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 887 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | static boolean canBeImeTarget(WindowState w) { |
| 889 | final int fl = w.mAttrs.flags |
| 890 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 891 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 892 | return w.isVisibleOrAdding(); |
| 893 | } |
| 894 | return false; |
| 895 | } |
| 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 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 898 | final ArrayList localmWindows = mWindows; |
| 899 | final int N = localmWindows.size(); |
| 900 | WindowState w = null; |
| 901 | int i = N; |
| 902 | while (i > 0) { |
| 903 | i--; |
| 904 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 905 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 906 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | // + Integer.toHexString(w.mAttrs.flags)); |
| 908 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 909 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | // Yet more tricksyness! If this window is a "starting" |
| 912 | // window, we do actually want to be on top of it, but |
| 913 | // it is not -really- where input will go. So if the caller |
| 914 | // is not actually looking to move the IME, look down below |
| 915 | // for a real window to target... |
| 916 | if (!willMove |
| 917 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 918 | && i > 0) { |
| 919 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 920 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 921 | i--; |
| 922 | w = wb; |
| 923 | } |
| 924 | } |
| 925 | break; |
| 926 | } |
| 927 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 930 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 931 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 933 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | if (willMove && w != null) { |
| 935 | final WindowState curTarget = mInputMethodTarget; |
| 936 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 937 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | // Now some fun for dealing with window animations that |
| 939 | // modify the Z order. We need to look at all windows below |
| 940 | // the current target that are in this app, finding the highest |
| 941 | // visible one in layering. |
| 942 | AppWindowToken token = curTarget.mAppToken; |
| 943 | WindowState highestTarget = null; |
| 944 | int highestPos = 0; |
| 945 | if (token.animating || token.animation != null) { |
| 946 | int pos = 0; |
| 947 | pos = localmWindows.indexOf(curTarget); |
| 948 | while (pos >= 0) { |
| 949 | WindowState win = (WindowState)localmWindows.get(pos); |
| 950 | if (win.mAppToken != token) { |
| 951 | break; |
| 952 | } |
| 953 | if (!win.mRemoved) { |
| 954 | if (highestTarget == null || win.mAnimLayer > |
| 955 | highestTarget.mAnimLayer) { |
| 956 | highestTarget = win; |
| 957 | highestPos = pos; |
| 958 | } |
| 959 | } |
| 960 | pos--; |
| 961 | } |
| 962 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 963 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 965 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | + mNextAppTransition + " " + highestTarget |
| 967 | + " animating=" + highestTarget.isAnimating() |
| 968 | + " layer=" + highestTarget.mAnimLayer |
| 969 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 970 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 971 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | // If we are currently setting up for an animation, |
| 973 | // hold everything until we can find out what will happen. |
| 974 | mInputMethodTargetWaitingAnim = true; |
| 975 | mInputMethodTarget = highestTarget; |
| 976 | return highestPos + 1; |
| 977 | } else if (highestTarget.isAnimating() && |
| 978 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 979 | // If the window we are currently targeting is involved |
| 980 | // with an animation, and it is on top of the next target |
| 981 | // we will be over, then hold off on moving until |
| 982 | // that is done. |
| 983 | mInputMethodTarget = highestTarget; |
| 984 | return highestPos + 1; |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 989 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 990 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | if (w != null) { |
| 992 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 993 | if (DEBUG_INPUT_METHOD) { |
| 994 | RuntimeException e = null; |
| 995 | if (!HIDE_STACK_CRAWLS) { |
| 996 | e = new RuntimeException(); |
| 997 | e.fillInStackTrace(); |
| 998 | } |
| 999 | Slog.w(TAG, "Moving IM target from " |
| 1000 | + mInputMethodTarget + " to " + w, e); |
| 1001 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | mInputMethodTarget = w; |
| 1003 | if (w.mAppToken != null) { |
| 1004 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1005 | } else { |
| 1006 | setInputMethodAnimLayerAdjustment(0); |
| 1007 | } |
| 1008 | } |
| 1009 | return i+1; |
| 1010 | } |
| 1011 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1012 | if (DEBUG_INPUT_METHOD) { |
| 1013 | RuntimeException e = null; |
| 1014 | if (!HIDE_STACK_CRAWLS) { |
| 1015 | e = new RuntimeException(); |
| 1016 | e.fillInStackTrace(); |
| 1017 | } |
| 1018 | Slog.w(TAG, "Moving IM target from " |
| 1019 | + mInputMethodTarget + " to null", e); |
| 1020 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | mInputMethodTarget = null; |
| 1022 | setInputMethodAnimLayerAdjustment(0); |
| 1023 | } |
| 1024 | return -1; |
| 1025 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1026 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1028 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1029 | if (pos >= 0) { |
| 1030 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1031 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1032 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | mWindows.add(pos, win); |
| 1034 | moveInputMethodDialogsLocked(pos+1); |
| 1035 | return; |
| 1036 | } |
| 1037 | win.mTargetAppToken = null; |
| 1038 | addWindowToListInOrderLocked(win, true); |
| 1039 | moveInputMethodDialogsLocked(pos); |
| 1040 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1041 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1043 | if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | mInputMethodAnimLayerAdjustment = adj; |
| 1045 | WindowState imw = mInputMethodWindow; |
| 1046 | if (imw != null) { |
| 1047 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1048 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | + " anim layer: " + imw.mAnimLayer); |
| 1050 | int wi = imw.mChildWindows.size(); |
| 1051 | while (wi > 0) { |
| 1052 | wi--; |
| 1053 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1054 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1055 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | + " anim layer: " + cw.mAnimLayer); |
| 1057 | } |
| 1058 | } |
| 1059 | int di = mInputMethodDialogs.size(); |
| 1060 | while (di > 0) { |
| 1061 | di --; |
| 1062 | imw = mInputMethodDialogs.get(di); |
| 1063 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1064 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | + " anim layer: " + imw.mAnimLayer); |
| 1066 | } |
| 1067 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1068 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1070 | int wpos = mWindows.indexOf(win); |
| 1071 | if (wpos >= 0) { |
| 1072 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1073 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | mWindows.remove(wpos); |
| 1075 | int NC = win.mChildWindows.size(); |
| 1076 | while (NC > 0) { |
| 1077 | NC--; |
| 1078 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1079 | int cpos = mWindows.indexOf(cw); |
| 1080 | if (cpos >= 0) { |
| 1081 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1082 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1083 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | mWindows.remove(cpos); |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | return interestingPos; |
| 1089 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1090 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1092 | addWindowToListInOrderLocked(win, false); |
| 1093 | // This is a hack to get all of the child windows added as well |
| 1094 | // at the right position. Child windows should be rare and |
| 1095 | // this case should be rare, so it shouldn't be that big a deal. |
| 1096 | int wpos = mWindows.indexOf(win); |
| 1097 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1098 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1099 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | mWindows.remove(wpos); |
| 1101 | reAddWindowLocked(wpos, win); |
| 1102 | } |
| 1103 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1104 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | void logWindowList(String prefix) { |
| 1106 | int N = mWindows.size(); |
| 1107 | while (N > 0) { |
| 1108 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1109 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | } |
| 1111 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1112 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | void moveInputMethodDialogsLocked(int pos) { |
| 1114 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1117 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | for (int i=0; i<N; i++) { |
| 1119 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1120 | } |
| 1121 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1122 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | logWindowList(" "); |
| 1124 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1125 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | if (pos >= 0) { |
| 1127 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1128 | if (pos < mWindows.size()) { |
| 1129 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1130 | if (wp == mInputMethodWindow) { |
| 1131 | pos++; |
| 1132 | } |
| 1133 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1134 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | for (int i=0; i<N; i++) { |
| 1136 | WindowState win = dialogs.get(i); |
| 1137 | win.mTargetAppToken = targetAppToken; |
| 1138 | pos = reAddWindowLocked(pos, win); |
| 1139 | } |
| 1140 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1141 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | logWindowList(" "); |
| 1143 | } |
| 1144 | return; |
| 1145 | } |
| 1146 | for (int i=0; i<N; i++) { |
| 1147 | WindowState win = dialogs.get(i); |
| 1148 | win.mTargetAppToken = null; |
| 1149 | reAddWindowToListInOrderLocked(win); |
| 1150 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1151 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | logWindowList(" "); |
| 1153 | } |
| 1154 | } |
| 1155 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1156 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1158 | final WindowState imWin = mInputMethodWindow; |
| 1159 | final int DN = mInputMethodDialogs.size(); |
| 1160 | if (imWin == null && DN == 0) { |
| 1161 | return false; |
| 1162 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1165 | if (imPos >= 0) { |
| 1166 | // In this case, the input method windows are to be placed |
| 1167 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1168 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | // First check to see if the input method windows are already |
| 1170 | // located here, and contiguous. |
| 1171 | final int N = mWindows.size(); |
| 1172 | WindowState firstImWin = imPos < N |
| 1173 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | // Figure out the actual input method window that should be |
| 1176 | // at the bottom of their stack. |
| 1177 | WindowState baseImWin = imWin != null |
| 1178 | ? imWin : mInputMethodDialogs.get(0); |
| 1179 | if (baseImWin.mChildWindows.size() > 0) { |
| 1180 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1181 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 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 (firstImWin == baseImWin) { |
| 1185 | // The windows haven't moved... but are they still contiguous? |
| 1186 | // First find the top IM window. |
| 1187 | int pos = imPos+1; |
| 1188 | while (pos < N) { |
| 1189 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1190 | break; |
| 1191 | } |
| 1192 | pos++; |
| 1193 | } |
| 1194 | pos++; |
| 1195 | // Now there should be no more input method windows above. |
| 1196 | while (pos < N) { |
| 1197 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1198 | break; |
| 1199 | } |
| 1200 | pos++; |
| 1201 | } |
| 1202 | if (pos >= N) { |
| 1203 | // All is good! |
| 1204 | return false; |
| 1205 | } |
| 1206 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1207 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | if (imWin != null) { |
| 1209 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1210 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | logWindowList(" "); |
| 1212 | } |
| 1213 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1214 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1215 | Slog.v(TAG, "List after moving with new pos " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1216 | logWindowList(" "); |
| 1217 | } |
| 1218 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1219 | reAddWindowLocked(imPos, imWin); |
| 1220 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1221 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | logWindowList(" "); |
| 1223 | } |
| 1224 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1225 | } else { |
| 1226 | moveInputMethodDialogsLocked(imPos); |
| 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 | } else { |
| 1230 | // In this case, the input method windows go in a fixed layer, |
| 1231 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1232 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1234 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | tmpRemoveWindowLocked(0, imWin); |
| 1236 | imWin.mTargetAppToken = null; |
| 1237 | reAddWindowToListInOrderLocked(imWin); |
| 1238 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1239 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | logWindowList(" "); |
| 1241 | } |
| 1242 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1243 | } else { |
| 1244 | moveInputMethodDialogsLocked(-1);; |
| 1245 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | if (needAssignLayers) { |
| 1250 | assignLayersLocked(); |
| 1251 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | return true; |
| 1254 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1255 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | void adjustInputMethodDialogsLocked() { |
| 1257 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1258 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1259 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1260 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1261 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1262 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1263 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1264 | ? wallpaperTarget.mAppToken.animation : null) |
| 1265 | + " upper=" + mUpperWallpaperTarget |
| 1266 | + " lower=" + mLowerWallpaperTarget); |
| 1267 | return (wallpaperTarget != null |
| 1268 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1269 | && wallpaperTarget.mAppToken.animation != null))) |
| 1270 | || mUpperWallpaperTarget != null |
| 1271 | || mLowerWallpaperTarget != null; |
| 1272 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1273 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1274 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1275 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1276 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1277 | int adjustWallpaperWindowsLocked() { |
| 1278 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1279 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1280 | final int dw = mDisplay.getWidth(); |
| 1281 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1282 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1283 | // First find top-most window that has asked to be on top of the |
| 1284 | // wallpaper; all wallpapers go behind it. |
| 1285 | final ArrayList localmWindows = mWindows; |
| 1286 | int N = localmWindows.size(); |
| 1287 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1288 | WindowState foundW = null; |
| 1289 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1290 | WindowState topCurW = null; |
| 1291 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1292 | int i = N; |
| 1293 | while (i > 0) { |
| 1294 | i--; |
| 1295 | w = (WindowState)localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1296 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1297 | if (topCurW == null) { |
| 1298 | topCurW = w; |
| 1299 | topCurI = i; |
| 1300 | } |
| 1301 | continue; |
| 1302 | } |
| 1303 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1304 | if (w.mAppToken != null) { |
| 1305 | // If this window's app token is hidden and not animating, |
| 1306 | // it is of no interest to us. |
| 1307 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1308 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1309 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1310 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1311 | continue; |
| 1312 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1313 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1314 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1315 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1316 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1317 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1318 | && (mWallpaperTarget == w |
| 1319 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1320 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1321 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1322 | foundW = w; |
| 1323 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1324 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1325 | && w.mAppToken.animation != null) |
| 1326 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1327 | // The current wallpaper target is animating, so we'll |
| 1328 | // look behind it for another possible target and figure |
| 1329 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1330 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1331 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1332 | continue; |
| 1333 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1334 | break; |
| 1335 | } |
| 1336 | } |
| 1337 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1338 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1339 | // If we are currently waiting for an app transition, and either |
| 1340 | // the current target or the next target are involved with it, |
| 1341 | // then hold off on doing anything with the wallpaper. |
| 1342 | // Note that we are checking here for just whether the target |
| 1343 | // is part of an app token... which is potentially overly aggressive |
| 1344 | // (the app token may not be involved in the transition), but good |
| 1345 | // enough (we'll just wait until whatever transition is pending |
| 1346 | // executes). |
| 1347 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1348 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1349 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1350 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1351 | } |
| 1352 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1353 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1354 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1355 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1356 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1357 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1358 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1359 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1360 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1361 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1362 | + " oldTarget: " + mWallpaperTarget); |
| 1363 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1364 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1365 | mLowerWallpaperTarget = null; |
| 1366 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1367 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1368 | WindowState oldW = mWallpaperTarget; |
| 1369 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1370 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1371 | // Now what is happening... if the current and new targets are |
| 1372 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1373 | if (foundW != null && oldW != null) { |
| 1374 | boolean oldAnim = oldW.mAnimation != null |
| 1375 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1376 | boolean foundAnim = foundW.mAnimation != null |
| 1377 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1378 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1379 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1380 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1381 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1382 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1383 | int oldI = localmWindows.indexOf(oldW); |
| 1384 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1385 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1386 | } |
| 1387 | if (oldI >= 0) { |
| 1388 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1389 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1390 | + "=" + oldW + "; new#" + foundI |
| 1391 | + "=" + foundW); |
| 1392 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1393 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1394 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1395 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1396 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1397 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1398 | } |
| 1399 | mWallpaperTarget = oldW; |
| 1400 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1401 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1402 | // Now set the upper and lower wallpaper targets |
| 1403 | // correctly, and make sure that we are positioning |
| 1404 | // the wallpaper below the lower. |
| 1405 | if (foundI > oldI) { |
| 1406 | // The new target is on top of the old one. |
| 1407 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1408 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1409 | } |
| 1410 | mUpperWallpaperTarget = foundW; |
| 1411 | mLowerWallpaperTarget = oldW; |
| 1412 | foundW = oldW; |
| 1413 | foundI = oldI; |
| 1414 | } else { |
| 1415 | // The new target is below the old one. |
| 1416 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1417 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1418 | } |
| 1419 | mUpperWallpaperTarget = oldW; |
| 1420 | mLowerWallpaperTarget = foundW; |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1425 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1426 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1427 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1428 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1429 | || (mLowerWallpaperTarget.mAppToken != null |
| 1430 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1431 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1432 | || (mUpperWallpaperTarget.mAppToken != null |
| 1433 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1434 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1435 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1436 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1437 | } |
| 1438 | mLowerWallpaperTarget = null; |
| 1439 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1440 | } |
| 1441 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1442 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1443 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1444 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1445 | // The window is visible to the compositor... but is it visible |
| 1446 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1447 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1448 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1449 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1450 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1451 | // its layer adjustment. Only do this if we are not transfering |
| 1452 | // between two wallpaper targets. |
| 1453 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1454 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1455 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1456 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1457 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1458 | * TYPE_LAYER_MULTIPLIER |
| 1459 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1460 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1461 | // Now w is the window we are supposed to be behind... but we |
| 1462 | // 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] | 1463 | // AND any starting window associated with it, AND below the |
| 1464 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1465 | while (foundI > 0) { |
| 1466 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1467 | if (wb.mBaseLayer < maxLayer && |
| 1468 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1469 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1470 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1471 | // This window is not related to the previous one in any |
| 1472 | // interesting way, so stop here. |
| 1473 | break; |
| 1474 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1475 | foundW = wb; |
| 1476 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1477 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1478 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1479 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1480 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1481 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1482 | if (foundW == null && topCurW != null) { |
| 1483 | // There is no wallpaper target, so it goes at the bottom. |
| 1484 | // We will assume it is the same place as last time, if known. |
| 1485 | foundW = topCurW; |
| 1486 | foundI = topCurI+1; |
| 1487 | } else { |
| 1488 | // Okay i is the position immediately above the wallpaper. Look at |
| 1489 | // what is below it for later. |
| 1490 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1491 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1492 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1493 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1494 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1495 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1496 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1497 | } |
| 1498 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1499 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1500 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1501 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1502 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1503 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1504 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1505 | // are correctly placed. |
| 1506 | int curTokenIndex = mWallpaperTokens.size(); |
| 1507 | while (curTokenIndex > 0) { |
| 1508 | curTokenIndex--; |
| 1509 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1510 | if (token.hidden == visible) { |
| 1511 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1512 | token.hidden = !visible; |
| 1513 | // Need to do a layout to ensure the wallpaper now has the |
| 1514 | // correct size. |
| 1515 | mLayoutNeeded = true; |
| 1516 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1517 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1518 | int curWallpaperIndex = token.windows.size(); |
| 1519 | while (curWallpaperIndex > 0) { |
| 1520 | curWallpaperIndex--; |
| 1521 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1522 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1523 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1524 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1525 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1526 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1527 | // First, make sure the client has the current visibility |
| 1528 | // state. |
| 1529 | if (wallpaper.mWallpaperVisible != visible) { |
| 1530 | wallpaper.mWallpaperVisible = visible; |
| 1531 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1532 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1533 | "Setting visibility of wallpaper " + wallpaper |
| 1534 | + ": " + visible); |
| 1535 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1536 | } catch (RemoteException e) { |
| 1537 | } |
| 1538 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1539 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1540 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1541 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1542 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1543 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1544 | // First, if this window is at the current index, then all |
| 1545 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1546 | if (wallpaper == foundW) { |
| 1547 | foundI--; |
| 1548 | foundW = foundI > 0 |
| 1549 | ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1550 | continue; |
| 1551 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1552 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1553 | // The window didn't match... the current wallpaper window, |
| 1554 | // wherever it is, is in the wrong place, so make sure it is |
| 1555 | // not in the list. |
| 1556 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1557 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1558 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1559 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1560 | localmWindows.remove(oldIndex); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1561 | if (oldIndex < foundI) { |
| 1562 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1563 | } |
| 1564 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1565 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1566 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1567 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1568 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1569 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1570 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1571 | localmWindows.add(foundI, wallpaper); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1572 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1575 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1576 | return changed; |
| 1577 | } |
| 1578 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1579 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1580 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1581 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1582 | mWallpaperAnimLayerAdjustment = adj; |
| 1583 | int curTokenIndex = mWallpaperTokens.size(); |
| 1584 | while (curTokenIndex > 0) { |
| 1585 | curTokenIndex--; |
| 1586 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1587 | int curWallpaperIndex = token.windows.size(); |
| 1588 | while (curWallpaperIndex > 0) { |
| 1589 | curWallpaperIndex--; |
| 1590 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1591 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1592 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1593 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1594 | } |
| 1595 | } |
| 1596 | } |
| 1597 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1598 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1599 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1600 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1601 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1602 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1603 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1604 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1605 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1606 | changed = wallpaperWin.mXOffset != offset; |
| 1607 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1608 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1609 | + wallpaperWin + " x: " + offset); |
| 1610 | wallpaperWin.mXOffset = offset; |
| 1611 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1612 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1613 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1614 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1615 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1616 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1617 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1618 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1619 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1620 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1621 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1622 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1623 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1624 | + wallpaperWin + " y: " + offset); |
| 1625 | changed = true; |
| 1626 | wallpaperWin.mYOffset = offset; |
| 1627 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1628 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1629 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1630 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1631 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1632 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1633 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1634 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1635 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1636 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1637 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1638 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1639 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1640 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1641 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1642 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1643 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1644 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1645 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1646 | if (mWaitingOnWallpaper != null) { |
| 1647 | long start = SystemClock.uptimeMillis(); |
| 1648 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1649 | < start) { |
| 1650 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1651 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1652 | "Waiting for offset complete..."); |
| 1653 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1654 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1655 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1656 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1657 | if ((start+WALLPAPER_TIMEOUT) |
| 1658 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1659 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1660 | + wallpaperWin); |
| 1661 | mLastWallpaperTimeoutTime = start; |
| 1662 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1663 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1664 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1665 | } |
| 1666 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1667 | } catch (RemoteException e) { |
| 1668 | } |
| 1669 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1670 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1671 | return changed; |
| 1672 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1673 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1674 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1675 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1676 | if (mWaitingOnWallpaper != null && |
| 1677 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1678 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1679 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1683 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1684 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1685 | final int dw = mDisplay.getWidth(); |
| 1686 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1687 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1688 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1689 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1690 | WindowState target = mWallpaperTarget; |
| 1691 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1692 | if (target.mWallpaperX >= 0) { |
| 1693 | mLastWallpaperX = target.mWallpaperX; |
| 1694 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1695 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1696 | } |
| 1697 | if (target.mWallpaperY >= 0) { |
| 1698 | mLastWallpaperY = target.mWallpaperY; |
| 1699 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1700 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1701 | } |
| 1702 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1703 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1704 | int curTokenIndex = mWallpaperTokens.size(); |
| 1705 | while (curTokenIndex > 0) { |
| 1706 | curTokenIndex--; |
| 1707 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1708 | int curWallpaperIndex = token.windows.size(); |
| 1709 | while (curWallpaperIndex > 0) { |
| 1710 | curWallpaperIndex--; |
| 1711 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1712 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1713 | wallpaper.computeShownFrameLocked(); |
| 1714 | changed = true; |
| 1715 | // We only want to be synchronous with one wallpaper. |
| 1716 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1720 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1721 | return changed; |
| 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 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1725 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1726 | final int dw = mDisplay.getWidth(); |
| 1727 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1728 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1729 | int curTokenIndex = mWallpaperTokens.size(); |
| 1730 | while (curTokenIndex > 0) { |
| 1731 | curTokenIndex--; |
| 1732 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1733 | if (token.hidden == visible) { |
| 1734 | token.hidden = !visible; |
| 1735 | // Need to do a layout to ensure the wallpaper now has the |
| 1736 | // correct size. |
| 1737 | mLayoutNeeded = true; |
| 1738 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1739 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1740 | int curWallpaperIndex = token.windows.size(); |
| 1741 | while (curWallpaperIndex > 0) { |
| 1742 | curWallpaperIndex--; |
| 1743 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1744 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1745 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1746 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1747 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1748 | if (wallpaper.mWallpaperVisible != visible) { |
| 1749 | wallpaper.mWallpaperVisible = visible; |
| 1750 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1751 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1752 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1753 | + ": " + visible); |
| 1754 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1755 | } catch (RemoteException e) { |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1761 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1762 | void sendPointerToWallpaperLocked(WindowState srcWin, |
| 1763 | MotionEvent pointer, long eventTime) { |
| 1764 | int curTokenIndex = mWallpaperTokens.size(); |
| 1765 | while (curTokenIndex > 0) { |
| 1766 | curTokenIndex--; |
| 1767 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1768 | int curWallpaperIndex = token.windows.size(); |
| 1769 | while (curWallpaperIndex > 0) { |
| 1770 | curWallpaperIndex--; |
| 1771 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1772 | if ((wallpaper.mAttrs.flags & |
| 1773 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 1774 | continue; |
| 1775 | } |
| 1776 | try { |
| 1777 | MotionEvent ev = MotionEvent.obtainNoHistory(pointer); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1778 | if (srcWin != null) { |
| 1779 | ev.offsetLocation(srcWin.mFrame.left-wallpaper.mFrame.left, |
| 1780 | srcWin.mFrame.top-wallpaper.mFrame.top); |
| 1781 | } else { |
| 1782 | ev.offsetLocation(-wallpaper.mFrame.left, -wallpaper.mFrame.top); |
| 1783 | } |
| 1784 | switch (pointer.getAction()) { |
| 1785 | case MotionEvent.ACTION_DOWN: |
| 1786 | mSendingPointersToWallpaper = true; |
| 1787 | break; |
| 1788 | case MotionEvent.ACTION_UP: |
| 1789 | mSendingPointersToWallpaper = false; |
| 1790 | break; |
| 1791 | } |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1792 | wallpaper.mClient.dispatchPointer(ev, eventTime, false); |
| 1793 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1794 | Slog.w(TAG, "Failure sending pointer to wallpaper", e); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1799 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1800 | void dispatchPointerElsewhereLocked(WindowState srcWin, WindowState relWin, |
| 1801 | MotionEvent pointer, long eventTime, boolean skipped) { |
| 1802 | if (relWin != null) { |
| 1803 | mPolicy.dispatchedPointerEventLw(pointer, relWin.mFrame.left, relWin.mFrame.top); |
| 1804 | } else { |
| 1805 | mPolicy.dispatchedPointerEventLw(pointer, 0, 0); |
| 1806 | } |
| 1807 | |
| 1808 | // If we sent an initial down to the wallpaper, then continue |
| 1809 | // sending events until the final up. |
| 1810 | if (mSendingPointersToWallpaper) { |
| 1811 | if (skipped) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1812 | Slog.i(TAG, "Sending skipped pointer to wallpaper!"); |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1813 | } |
| 1814 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1815 | |
| 1816 | // If we are on top of the wallpaper, then the wallpaper also |
| 1817 | // gets to see this movement. |
| 1818 | } else if (srcWin != null |
| 1819 | && pointer.getAction() == MotionEvent.ACTION_DOWN |
| 1820 | && mWallpaperTarget == srcWin |
| 1821 | && srcWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 1822 | sendPointerToWallpaperLocked(relWin, pointer, eventTime); |
| 1823 | } |
| 1824 | } |
| 1825 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1826 | public int addWindow(Session session, IWindow client, |
| 1827 | WindowManager.LayoutParams attrs, int viewVisibility, |
| 1828 | Rect outContentInsets) { |
| 1829 | int res = mPolicy.checkAddPermission(attrs); |
| 1830 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1831 | return res; |
| 1832 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | boolean reportNewConfig = false; |
| 1835 | WindowState attachedWindow = null; |
| 1836 | WindowState win = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | synchronized(mWindowMap) { |
| 1839 | // Instantiating a Display requires talking with the simulator, |
| 1840 | // so don't do it until we know the system is mostly up and |
| 1841 | // running. |
| 1842 | if (mDisplay == null) { |
| 1843 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1844 | mDisplay = wm.getDefaultDisplay(); |
| 1845 | mQueue.setDisplay(mDisplay); |
| 1846 | reportNewConfig = true; |
| 1847 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1848 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1849 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1850 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1852 | } |
| 1853 | |
| 1854 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1855 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1856 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1857 | Slog.w(TAG, "Attempted to add window with token that is not a window: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1858 | + attrs.token + ". Aborting."); |
| 1859 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1860 | } |
| 1861 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1862 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1863 | Slog.w(TAG, "Attempted to add window with token that is a sub-window: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1864 | + attrs.token + ". Aborting."); |
| 1865 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | boolean addToken = false; |
| 1870 | WindowToken token = mTokenMap.get(attrs.token); |
| 1871 | if (token == null) { |
| 1872 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1873 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1874 | Slog.w(TAG, "Attempted to add application window with unknown token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | + attrs.token + ". Aborting."); |
| 1876 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1877 | } |
| 1878 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1879 | Slog.w(TAG, "Attempted to add input method window with unknown token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | + attrs.token + ". Aborting."); |
| 1881 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1882 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1883 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1884 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1885 | + attrs.token + ". Aborting."); |
| 1886 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1887 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | token = new WindowToken(attrs.token, -1, false); |
| 1889 | addToken = true; |
| 1890 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1891 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1892 | AppWindowToken atoken = token.appWindowToken; |
| 1893 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1894 | Slog.w(TAG, "Attempted to add window with non-application token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1895 | + token + ". Aborting."); |
| 1896 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1897 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1898 | Slog.w(TAG, "Attempted to add window with exiting application token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1899 | + token + ". Aborting."); |
| 1900 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1901 | } |
| 1902 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1903 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1904 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1905 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1906 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1907 | } |
| 1908 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1909 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1910 | Slog.w(TAG, "Attempted to add input method window with bad token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1911 | + attrs.token + ". Aborting."); |
| 1912 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1913 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1914 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1915 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1916 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1917 | + attrs.token + ". Aborting."); |
| 1918 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1919 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | win = new WindowState(session, client, token, |
| 1923 | attachedWindow, attrs, viewVisibility); |
| 1924 | if (win.mDeathRecipient == null) { |
| 1925 | // Client has apparently died, so there is no reason to |
| 1926 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1927 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1928 | + " that is dead, aborting."); |
| 1929 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1930 | } |
| 1931 | |
| 1932 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1933 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1934 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1935 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1936 | return res; |
| 1937 | } |
| 1938 | |
| 1939 | // From now on, no exceptions or errors allowed! |
| 1940 | |
| 1941 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1944 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | if (addToken) { |
| 1946 | mTokenMap.put(attrs.token, token); |
| 1947 | mTokenList.add(token); |
| 1948 | } |
| 1949 | win.attach(); |
| 1950 | mWindowMap.put(client.asBinder(), win); |
| 1951 | |
| 1952 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1953 | token.appWindowToken != null) { |
| 1954 | token.appWindowToken.startingWindow = win; |
| 1955 | } |
| 1956 | |
| 1957 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1958 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1960 | mInputMethodWindow = win; |
| 1961 | addInputMethodWindowToListLocked(win); |
| 1962 | imMayMove = false; |
| 1963 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1964 | mInputMethodDialogs.add(win); |
| 1965 | addWindowToListInOrderLocked(win, true); |
| 1966 | adjustInputMethodDialogsLocked(); |
| 1967 | imMayMove = false; |
| 1968 | } else { |
| 1969 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1970 | if (attrs.type == TYPE_WALLPAPER) { |
| 1971 | mLastWallpaperTimeoutTime = 0; |
| 1972 | adjustWallpaperWindowsLocked(); |
| 1973 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1974 | adjustWallpaperWindowsLocked(); |
| 1975 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1976 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1981 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | if (mInTouchMode) { |
| 1983 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1984 | } |
| 1985 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1986 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1987 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1988 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1989 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | if (win.canReceiveKeys()) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1991 | if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) |
| 1992 | == true) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | imMayMove = false; |
| 1994 | } |
| 1995 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1998 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | assignLayersLocked(); |
| 2002 | // Don't do layout here, the window must call |
| 2003 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2004 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | //dump(); |
| 2006 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2007 | if (focusChanged) { |
| 2008 | if (mCurrentFocus != null) { |
| 2009 | mKeyWaiter.handleNewWindowLocked(mCurrentFocus); |
| 2010 | } |
| 2011 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2012 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | TAG, "New client " + client.asBinder() |
| 2014 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2015 | |
| 2016 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2017 | reportNewConfig = true; |
| 2018 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 2022 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 2023 | // identity anyway, so it's safe to just clear & restore around this whole |
| 2024 | // block. |
| 2025 | final long origId = Binder.clearCallingIdentity(); |
| 2026 | if (reportNewConfig) { |
| 2027 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | } |
| 2029 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2030 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2031 | return res; |
| 2032 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2033 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | public void removeWindow(Session session, IWindow client) { |
| 2035 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2036 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | if (win == null) { |
| 2038 | return; |
| 2039 | } |
| 2040 | removeWindowLocked(session, win); |
| 2041 | } |
| 2042 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2043 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | public void removeWindowLocked(Session session, WindowState win) { |
| 2045 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2046 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2047 | TAG, "Remove " + win + " client=" |
| 2048 | + Integer.toHexString(System.identityHashCode( |
| 2049 | win.mClient.asBinder())) |
| 2050 | + ", surface=" + win.mSurface); |
| 2051 | |
| 2052 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2053 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2054 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2055 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2056 | + " mExiting=" + win.mExiting |
| 2057 | + " isAnimating=" + win.isAnimating() |
| 2058 | + " app-animation=" |
| 2059 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2060 | + " inPendingTransaction=" |
| 2061 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2062 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2063 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2064 | boolean wasVisible = false; |
| 2065 | // First, see if we need to run an animation. If we do, we have |
| 2066 | // to hold off on removing the window until the animation is done. |
| 2067 | // If the display is frozen, just remove immediately, since the |
| 2068 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2069 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2070 | // If we are not currently running the exit animation, we |
| 2071 | // need to see about starting one. |
| 2072 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2073 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2075 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2076 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2077 | } |
| 2078 | // Try starting an animation. |
| 2079 | if (applyAnimationLocked(win, transit, false)) { |
| 2080 | win.mExiting = true; |
| 2081 | } |
| 2082 | } |
| 2083 | if (win.mExiting || win.isAnimating()) { |
| 2084 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2085 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | win.mExiting = true; |
| 2087 | win.mRemoveOnExit = true; |
| 2088 | mLayoutNeeded = true; |
| 2089 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2090 | performLayoutAndPlaceSurfacesLocked(); |
| 2091 | if (win.mAppToken != null) { |
| 2092 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2093 | } |
| 2094 | //dump(); |
| 2095 | Binder.restoreCallingIdentity(origId); |
| 2096 | return; |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | removeWindowInnerLocked(session, win); |
| 2101 | // Removing a visible window will effect the computed orientation |
| 2102 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2103 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2104 | != mForcedAppOrientation |
| 2105 | && updateOrientationFromAppTokensLocked()) { |
| 2106 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | } |
| 2108 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2109 | Binder.restoreCallingIdentity(origId); |
| 2110 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 2113 | mKeyWaiter.finishedKey(session, win.mClient, true, |
| 2114 | KeyWaiter.RETURN_NOTHING); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | mKeyWaiter.releasePendingPointerLocked(win.mSession); |
| 2116 | mKeyWaiter.releasePendingTrackballLocked(win.mSession); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2117 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2118 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2119 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | if (mInputMethodTarget == win) { |
| 2121 | moveInputMethodWindowsIfNeededLocked(false); |
| 2122 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2123 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2124 | if (false) { |
| 2125 | RuntimeException e = new RuntimeException("here"); |
| 2126 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2127 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2128 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2130 | mPolicy.removeWindowLw(win); |
| 2131 | win.removeLocked(); |
| 2132 | |
| 2133 | mWindowMap.remove(win.mClient.asBinder()); |
| 2134 | mWindows.remove(win); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2135 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | |
| 2137 | if (mInputMethodWindow == win) { |
| 2138 | mInputMethodWindow = null; |
| 2139 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2140 | mInputMethodDialogs.remove(win); |
| 2141 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2142 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | final WindowToken token = win.mToken; |
| 2144 | final AppWindowToken atoken = win.mAppToken; |
| 2145 | token.windows.remove(win); |
| 2146 | if (atoken != null) { |
| 2147 | atoken.allAppWindows.remove(win); |
| 2148 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2149 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | TAG, "**** Removing window " + win + ": count=" |
| 2151 | + token.windows.size()); |
| 2152 | if (token.windows.size() == 0) { |
| 2153 | if (!token.explicit) { |
| 2154 | mTokenMap.remove(token.token); |
| 2155 | mTokenList.remove(token); |
| 2156 | } else if (atoken != null) { |
| 2157 | atoken.firstWindowDrawn = false; |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | if (atoken != null) { |
| 2162 | if (atoken.startingWindow == win) { |
| 2163 | atoken.startingWindow = null; |
| 2164 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2165 | // If this is the last window and we had requested a starting |
| 2166 | // transition window, well there is no point now. |
| 2167 | atoken.startingData = null; |
| 2168 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2169 | // If this is the last window except for a starting transition |
| 2170 | // window, we need to get rid of the starting transition. |
| 2171 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2172 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | + ": no more real windows"); |
| 2174 | } |
| 2175 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2176 | mH.sendMessage(m); |
| 2177 | } |
| 2178 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2179 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2180 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2181 | mLastWallpaperTimeoutTime = 0; |
| 2182 | adjustWallpaperWindowsLocked(); |
| 2183 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2184 | adjustWallpaperWindowsLocked(); |
| 2185 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2187 | if (!mInLayout) { |
| 2188 | assignLayersLocked(); |
| 2189 | mLayoutNeeded = true; |
| 2190 | performLayoutAndPlaceSurfacesLocked(); |
| 2191 | if (win.mAppToken != null) { |
| 2192 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2193 | } |
| 2194 | } |
| 2195 | } |
| 2196 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2197 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2198 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2199 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2200 | if (where != null) { |
| 2201 | Slog.i(TAG, str, where); |
| 2202 | } else { |
| 2203 | Slog.i(TAG, str); |
| 2204 | } |
| 2205 | } |
| 2206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2207 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2208 | long origId = Binder.clearCallingIdentity(); |
| 2209 | try { |
| 2210 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2211 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2212 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2213 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | Surface.openTransaction(); |
| 2215 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2216 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2217 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | w.mSurface.setTransparentRegionHint(region); |
| 2219 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2220 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2221 | Surface.closeTransaction(); |
| 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | } finally { |
| 2226 | Binder.restoreCallingIdentity(origId); |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2231 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | Rect visibleInsets) { |
| 2233 | long origId = Binder.clearCallingIdentity(); |
| 2234 | try { |
| 2235 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2236 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2237 | if (w != null) { |
| 2238 | w.mGivenInsetsPending = false; |
| 2239 | w.mGivenContentInsets.set(contentInsets); |
| 2240 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2241 | w.mTouchableInsets = touchableInsets; |
| 2242 | mLayoutNeeded = true; |
| 2243 | performLayoutAndPlaceSurfacesLocked(); |
| 2244 | } |
| 2245 | } |
| 2246 | } finally { |
| 2247 | Binder.restoreCallingIdentity(origId); |
| 2248 | } |
| 2249 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2252 | Rect outDisplayFrame) { |
| 2253 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2254 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | if (win == null) { |
| 2256 | outDisplayFrame.setEmpty(); |
| 2257 | return; |
| 2258 | } |
| 2259 | outDisplayFrame.set(win.mDisplayFrame); |
| 2260 | } |
| 2261 | } |
| 2262 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2263 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2264 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2265 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2266 | window.mWallpaperX = x; |
| 2267 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2268 | window.mWallpaperXStep = xStep; |
| 2269 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2270 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2271 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2272 | } |
| 2273 | } |
| 2274 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2275 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2276 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2277 | synchronized (mWindowMap) { |
| 2278 | if (mWaitingOnWallpaper != null && |
| 2279 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2280 | mWaitingOnWallpaper = null; |
| 2281 | mWindowMap.notifyAll(); |
| 2282 | } |
| 2283 | } |
| 2284 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2285 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2286 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2287 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2288 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2289 | || window == mUpperWallpaperTarget) { |
| 2290 | boolean doWait = sync; |
| 2291 | int curTokenIndex = mWallpaperTokens.size(); |
| 2292 | while (curTokenIndex > 0) { |
| 2293 | curTokenIndex--; |
| 2294 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2295 | int curWallpaperIndex = token.windows.size(); |
| 2296 | while (curWallpaperIndex > 0) { |
| 2297 | curWallpaperIndex--; |
| 2298 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2299 | try { |
| 2300 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2301 | x, y, z, extras, sync); |
| 2302 | // We only want to be synchronous with one wallpaper. |
| 2303 | sync = false; |
| 2304 | } catch (RemoteException e) { |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2308 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2309 | if (doWait) { |
| 2310 | // XXX Need to wait for result. |
| 2311 | } |
| 2312 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2313 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2314 | return null; |
| 2315 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2316 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | public int relayoutWindow(Session session, IWindow client, |
| 2318 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2319 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2320 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2321 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | boolean displayed = false; |
| 2323 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2324 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2327 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2328 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | if (win == null) { |
| 2330 | return 0; |
| 2331 | } |
| 2332 | win.mRequestedWidth = requestedWidth; |
| 2333 | win.mRequestedHeight = requestedHeight; |
| 2334 | |
| 2335 | if (attrs != null) { |
| 2336 | mPolicy.adjustWindowParamsLw(attrs); |
| 2337 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2339 | int attrChanges = 0; |
| 2340 | int flagChanges = 0; |
| 2341 | if (attrs != null) { |
| 2342 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2343 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2344 | } |
| 2345 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2346 | if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | |
| 2348 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2349 | win.mAlpha = attrs.alpha; |
| 2350 | } |
| 2351 | |
| 2352 | final boolean scaledWindow = |
| 2353 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2354 | |
| 2355 | if (scaledWindow) { |
| 2356 | // requested{Width|Height} Surface's physical size |
| 2357 | // attrs.{width|height} Size on screen |
| 2358 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2359 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2360 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2361 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2362 | } else { |
| 2363 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | boolean imMayMove = (flagChanges&( |
| 2367 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2368 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2369 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2370 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2371 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2372 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2373 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2374 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2375 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2376 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | win.mRelayoutCalled = true; |
| 2378 | final int oldVisibility = win.mViewVisibility; |
| 2379 | win.mViewVisibility = viewVisibility; |
| 2380 | if (viewVisibility == View.VISIBLE && |
| 2381 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2382 | displayed = !win.isVisibleLw(); |
| 2383 | if (win.mExiting) { |
| 2384 | win.mExiting = false; |
| 2385 | win.mAnimation = null; |
| 2386 | } |
| 2387 | if (win.mDestroying) { |
| 2388 | win.mDestroying = false; |
| 2389 | mDestroySurface.remove(win); |
| 2390 | } |
| 2391 | if (oldVisibility == View.GONE) { |
| 2392 | win.mEnterAnimationPending = true; |
| 2393 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2394 | if (displayed) { |
| 2395 | if (win.mSurface != null && !win.mDrawPending |
| 2396 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2397 | && mPolicy.isScreenOn()) { |
| 2398 | applyEnterAnimationLocked(win); |
| 2399 | } |
| 2400 | if ((win.mAttrs.flags |
| 2401 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2402 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2403 | "Relayout window turning screen on: " + win); |
| 2404 | win.mTurnOnScreen = true; |
| 2405 | } |
| 2406 | int diff = 0; |
| 2407 | if (win.mConfiguration != mCurConfiguration |
| 2408 | && (win.mConfiguration == null |
| 2409 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2410 | win.mConfiguration = mCurConfiguration; |
| 2411 | if (DEBUG_CONFIGURATION) { |
| 2412 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2413 | + win.mConfiguration + " / 0x" |
| 2414 | + Integer.toHexString(diff)); |
| 2415 | } |
| 2416 | outConfig.setTo(mCurConfiguration); |
| 2417 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2418 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2419 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2420 | // To change the format, we need to re-build the surface. |
| 2421 | win.destroySurfaceLocked(); |
| 2422 | displayed = true; |
| 2423 | } |
| 2424 | try { |
| 2425 | Surface surface = win.createSurfaceLocked(); |
| 2426 | if (surface != null) { |
| 2427 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2428 | win.mReportDestroySurface = false; |
| 2429 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2430 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2431 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2433 | // For some reason there isn't a surface. Clear the |
| 2434 | // caller's object so they see the same state. |
| 2435 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2436 | } |
| 2437 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2438 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2439 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2440 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2441 | Binder.restoreCallingIdentity(origId); |
| 2442 | return 0; |
| 2443 | } |
| 2444 | if (displayed) { |
| 2445 | focusMayChange = true; |
| 2446 | } |
| 2447 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2448 | && mInputMethodWindow == null) { |
| 2449 | mInputMethodWindow = win; |
| 2450 | imMayMove = true; |
| 2451 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2452 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2453 | && win.mAppToken != null |
| 2454 | && win.mAppToken.startingWindow != null) { |
| 2455 | // Special handling of starting window over the base |
| 2456 | // window of the app: propagate lock screen flags to it, |
| 2457 | // to provide the correct semantics while starting. |
| 2458 | final int mask = |
| 2459 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2460 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2461 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2462 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2463 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2464 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2465 | } else { |
| 2466 | win.mEnterAnimationPending = false; |
| 2467 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2468 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2469 | + ": mExiting=" + win.mExiting |
| 2470 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2471 | // If we are not currently running the exit animation, we |
| 2472 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2473 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2474 | // Try starting an animation; if there isn't one, we |
| 2475 | // can destroy the surface right away. |
| 2476 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2477 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2478 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2479 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2480 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2482 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | win.mExiting = true; |
| 2484 | mKeyWaiter.finishedKey(session, client, true, |
| 2485 | KeyWaiter.RETURN_NOTHING); |
| 2486 | } else if (win.isAnimating()) { |
| 2487 | // Currently in a hide animation... turn this into |
| 2488 | // an exit. |
| 2489 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2490 | } else if (win == mWallpaperTarget) { |
| 2491 | // If the wallpaper is currently behind this |
| 2492 | // window, we need to change both of them inside |
| 2493 | // of a transaction to avoid artifacts. |
| 2494 | win.mExiting = true; |
| 2495 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2496 | } else { |
| 2497 | if (mInputMethodWindow == win) { |
| 2498 | mInputMethodWindow = null; |
| 2499 | } |
| 2500 | win.destroySurfaceLocked(); |
| 2501 | } |
| 2502 | } |
| 2503 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2504 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2505 | if (win.mSurface == null || (win.getAttrs().flags |
| 2506 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2507 | || win.mSurfacePendingDestroy) { |
| 2508 | // We are being called from a local process, which |
| 2509 | // means outSurface holds its current surface. Ensure the |
| 2510 | // surface object is cleared, but we don't want it actually |
| 2511 | // destroyed at this point. |
| 2512 | win.mSurfacePendingDestroy = false; |
| 2513 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2514 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2515 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2516 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2517 | "Keeping surface, will report destroy: " + win); |
| 2518 | win.mReportDestroySurface = true; |
| 2519 | outSurface.copyFrom(win.mSurface); |
| 2520 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2521 | } |
| 2522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2523 | if (focusMayChange) { |
| 2524 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2525 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | imMayMove = false; |
| 2527 | } |
| 2528 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2529 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2530 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2531 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2532 | // reassign them at this point if the IM window state gets shuffled |
| 2533 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2536 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2537 | // Little hack here -- we -should- be able to rely on the |
| 2538 | // function to return true if the IME has moved and needs |
| 2539 | // its layer recomputed. However, if the IME was hidden |
| 2540 | // and isn't actually moved in the list, its layer may be |
| 2541 | // 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] | 2542 | assignLayers = true; |
| 2543 | } |
| 2544 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2545 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2546 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2547 | assignLayers = true; |
| 2548 | } |
| 2549 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2550 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | mLayoutNeeded = true; |
| 2552 | win.mGivenInsetsPending = insetsPending; |
| 2553 | if (assignLayers) { |
| 2554 | assignLayersLocked(); |
| 2555 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2556 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2558 | if (displayed && win.mIsWallpaper) { |
| 2559 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2560 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2561 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | if (win.mAppToken != null) { |
| 2563 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2564 | } |
| 2565 | outFrame.set(win.mFrame); |
| 2566 | outContentInsets.set(win.mContentInsets); |
| 2567 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2568 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2570 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | + ", requestedHeight=" + requestedHeight |
| 2572 | + ", viewVisibility=" + viewVisibility |
| 2573 | + "\nRelayout returning frame=" + outFrame |
| 2574 | + ", surface=" + outSurface); |
| 2575 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2576 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2578 | |
| 2579 | inTouchMode = mInTouchMode; |
| 2580 | } |
| 2581 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2582 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | sendNewConfiguration(); |
| 2584 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2585 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2586 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2587 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2588 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2589 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2590 | } |
| 2591 | |
| 2592 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2593 | final long origId = Binder.clearCallingIdentity(); |
| 2594 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2595 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2596 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2597 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2598 | adjustWallpaperWindowsLocked(); |
| 2599 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2600 | mLayoutNeeded = true; |
| 2601 | performLayoutAndPlaceSurfacesLocked(); |
| 2602 | } |
| 2603 | } |
| 2604 | Binder.restoreCallingIdentity(origId); |
| 2605 | } |
| 2606 | |
| 2607 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2608 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | + (lp != null ? lp.packageName : null) |
| 2610 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2611 | if (lp != null && lp.windowAnimations != 0) { |
| 2612 | // If this is a system resource, don't try to load it from the |
| 2613 | // application resources. It is nice to avoid loading application |
| 2614 | // resources if we can. |
| 2615 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2616 | int resId = lp.windowAnimations; |
| 2617 | if ((resId&0xFF000000) == 0x01000000) { |
| 2618 | packageName = "android"; |
| 2619 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2620 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2621 | + packageName); |
| 2622 | return AttributeCache.instance().get(packageName, resId, |
| 2623 | com.android.internal.R.styleable.WindowAnimation); |
| 2624 | } |
| 2625 | return null; |
| 2626 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2627 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2628 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2629 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2630 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2631 | if (packageName != null) { |
| 2632 | if ((resId&0xFF000000) == 0x01000000) { |
| 2633 | packageName = "android"; |
| 2634 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2635 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2636 | + packageName); |
| 2637 | return AttributeCache.instance().get(packageName, resId, |
| 2638 | com.android.internal.R.styleable.WindowAnimation); |
| 2639 | } |
| 2640 | return null; |
| 2641 | } |
| 2642 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | private void applyEnterAnimationLocked(WindowState win) { |
| 2644 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2645 | if (win.mEnterAnimationPending) { |
| 2646 | win.mEnterAnimationPending = false; |
| 2647 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2648 | } |
| 2649 | |
| 2650 | applyAnimationLocked(win, transit, true); |
| 2651 | } |
| 2652 | |
| 2653 | private boolean applyAnimationLocked(WindowState win, |
| 2654 | int transit, boolean isEntrance) { |
| 2655 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2656 | // If we are trying to apply an animation, but already running |
| 2657 | // an animation of the same type, then just leave that one alone. |
| 2658 | return true; |
| 2659 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2660 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | // Only apply an animation if the display isn't frozen. If it is |
| 2662 | // frozen, there is no reason to animate and it can cause strange |
| 2663 | // artifacts when we unfreeze the display if some different animation |
| 2664 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2665 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2666 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2667 | int attr = -1; |
| 2668 | Animation a = null; |
| 2669 | if (anim != 0) { |
| 2670 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2671 | } else { |
| 2672 | switch (transit) { |
| 2673 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2674 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2675 | break; |
| 2676 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2677 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2678 | break; |
| 2679 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2680 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2681 | break; |
| 2682 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2683 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2684 | break; |
| 2685 | } |
| 2686 | if (attr >= 0) { |
| 2687 | a = loadAnimation(win.mAttrs, attr); |
| 2688 | } |
| 2689 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2690 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2692 | + " mAnimation=" + win.mAnimation |
| 2693 | + " isEntrance=" + isEntrance); |
| 2694 | if (a != null) { |
| 2695 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2696 | RuntimeException e = null; |
| 2697 | if (!HIDE_STACK_CRAWLS) { |
| 2698 | e = new RuntimeException(); |
| 2699 | e.fillInStackTrace(); |
| 2700 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2701 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | } |
| 2703 | win.setAnimation(a); |
| 2704 | win.mAnimationIsEntrance = isEntrance; |
| 2705 | } |
| 2706 | } else { |
| 2707 | win.clearAnimation(); |
| 2708 | } |
| 2709 | |
| 2710 | return win.mAnimation != null; |
| 2711 | } |
| 2712 | |
| 2713 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2714 | int anim = 0; |
| 2715 | Context context = mContext; |
| 2716 | if (animAttr >= 0) { |
| 2717 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2718 | if (ent != null) { |
| 2719 | context = ent.context; |
| 2720 | anim = ent.array.getResourceId(animAttr, 0); |
| 2721 | } |
| 2722 | } |
| 2723 | if (anim != 0) { |
| 2724 | return AnimationUtils.loadAnimation(context, anim); |
| 2725 | } |
| 2726 | return null; |
| 2727 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2728 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2729 | private Animation loadAnimation(String packageName, int resId) { |
| 2730 | int anim = 0; |
| 2731 | Context context = mContext; |
| 2732 | if (resId >= 0) { |
| 2733 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2734 | if (ent != null) { |
| 2735 | context = ent.context; |
| 2736 | anim = resId; |
| 2737 | } |
| 2738 | } |
| 2739 | if (anim != 0) { |
| 2740 | return AnimationUtils.loadAnimation(context, anim); |
| 2741 | } |
| 2742 | return null; |
| 2743 | } |
| 2744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2745 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2746 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2747 | // Only apply an animation if the display isn't frozen. If it is |
| 2748 | // frozen, there is no reason to animate and it can cause strange |
| 2749 | // artifacts when we unfreeze the display if some different animation |
| 2750 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2751 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2752 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2753 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2754 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2755 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2756 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2757 | } else if (mNextAppTransitionPackage != null) { |
| 2758 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2759 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2760 | } else { |
| 2761 | int animAttr = 0; |
| 2762 | switch (transit) { |
| 2763 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2764 | animAttr = enter |
| 2765 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2766 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2767 | break; |
| 2768 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2769 | animAttr = enter |
| 2770 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2771 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2772 | break; |
| 2773 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2774 | animAttr = enter |
| 2775 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2776 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2777 | break; |
| 2778 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2779 | animAttr = enter |
| 2780 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2781 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2782 | break; |
| 2783 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2784 | animAttr = enter |
| 2785 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2786 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2787 | break; |
| 2788 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2789 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2790 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2791 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2792 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2793 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2794 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2795 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2796 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2797 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2798 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2799 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2800 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2801 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2802 | break; |
| 2803 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2804 | animAttr = enter |
| 2805 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2806 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2807 | break; |
| 2808 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2809 | animAttr = enter |
| 2810 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2811 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2812 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2813 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2814 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2815 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2816 | + " anim=" + a |
| 2817 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2818 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2820 | if (a != null) { |
| 2821 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2822 | RuntimeException e = null; |
| 2823 | if (!HIDE_STACK_CRAWLS) { |
| 2824 | e = new RuntimeException(); |
| 2825 | e.fillInStackTrace(); |
| 2826 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2827 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2828 | } |
| 2829 | wtoken.setAnimation(a); |
| 2830 | } |
| 2831 | } else { |
| 2832 | wtoken.clearAnimation(); |
| 2833 | } |
| 2834 | |
| 2835 | return wtoken.animation != null; |
| 2836 | } |
| 2837 | |
| 2838 | // ------------------------------------------------------------- |
| 2839 | // Application Window Tokens |
| 2840 | // ------------------------------------------------------------- |
| 2841 | |
| 2842 | public void validateAppTokens(List tokens) { |
| 2843 | int v = tokens.size()-1; |
| 2844 | int m = mAppTokens.size()-1; |
| 2845 | while (v >= 0 && m >= 0) { |
| 2846 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2847 | if (wtoken.removed) { |
| 2848 | m--; |
| 2849 | continue; |
| 2850 | } |
| 2851 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2852 | Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2854 | } |
| 2855 | v--; |
| 2856 | m--; |
| 2857 | } |
| 2858 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2859 | Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | v--; |
| 2861 | } |
| 2862 | while (m >= 0) { |
| 2863 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2864 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2865 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2866 | } |
| 2867 | m--; |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | boolean checkCallingPermission(String permission, String func) { |
| 2872 | // Quick check: if the calling permission is me, it's all okay. |
| 2873 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2874 | return true; |
| 2875 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2876 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2877 | if (mContext.checkCallingPermission(permission) |
| 2878 | == PackageManager.PERMISSION_GRANTED) { |
| 2879 | return true; |
| 2880 | } |
| 2881 | String msg = "Permission Denial: " + func + " from pid=" |
| 2882 | + Binder.getCallingPid() |
| 2883 | + ", uid=" + Binder.getCallingUid() |
| 2884 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2885 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2886 | return false; |
| 2887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2890 | WindowToken wtoken = mTokenMap.get(token); |
| 2891 | if (wtoken == null) { |
| 2892 | return null; |
| 2893 | } |
| 2894 | return wtoken.appWindowToken; |
| 2895 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2897 | public void addWindowToken(IBinder token, int type) { |
| 2898 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2899 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2900 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2902 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | synchronized(mWindowMap) { |
| 2904 | WindowToken wtoken = mTokenMap.get(token); |
| 2905 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2906 | Slog.w(TAG, "Attempted to add existing input method token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | return; |
| 2908 | } |
| 2909 | wtoken = new WindowToken(token, type, true); |
| 2910 | mTokenMap.put(token, wtoken); |
| 2911 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2912 | if (type == TYPE_WALLPAPER) { |
| 2913 | mWallpaperTokens.add(wtoken); |
| 2914 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | } |
| 2916 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2917 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | public void removeWindowToken(IBinder token) { |
| 2919 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2920 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2921 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | final long origId = Binder.clearCallingIdentity(); |
| 2925 | synchronized(mWindowMap) { |
| 2926 | WindowToken wtoken = mTokenMap.remove(token); |
| 2927 | mTokenList.remove(wtoken); |
| 2928 | if (wtoken != null) { |
| 2929 | boolean delayed = false; |
| 2930 | if (!wtoken.hidden) { |
| 2931 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2932 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | final int N = wtoken.windows.size(); |
| 2934 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2935 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | for (int i=0; i<N; i++) { |
| 2937 | WindowState win = wtoken.windows.get(i); |
| 2938 | |
| 2939 | if (win.isAnimating()) { |
| 2940 | delayed = true; |
| 2941 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | if (win.isVisibleNow()) { |
| 2944 | applyAnimationLocked(win, |
| 2945 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 2946 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 2947 | KeyWaiter.RETURN_NOTHING); |
| 2948 | changed = true; |
| 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | if (changed) { |
| 2953 | mLayoutNeeded = true; |
| 2954 | performLayoutAndPlaceSurfacesLocked(); |
| 2955 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2956 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2957 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | if (delayed) { |
| 2959 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2960 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2961 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | } |
| 2963 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2964 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2966 | Slog.w(TAG, "Attempted to remove non-existing token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | Binder.restoreCallingIdentity(origId); |
| 2970 | } |
| 2971 | |
| 2972 | public void addAppToken(int addPos, IApplicationToken token, |
| 2973 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2974 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2975 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2976 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2978 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | synchronized(mWindowMap) { |
| 2980 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2981 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2982 | Slog.w(TAG, "Attempted to add existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | return; |
| 2984 | } |
| 2985 | wtoken = new AppWindowToken(token); |
| 2986 | wtoken.groupId = groupId; |
| 2987 | wtoken.appFullscreen = fullscreen; |
| 2988 | wtoken.requestedOrientation = requestedOrientation; |
| 2989 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2990 | if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2991 | mTokenMap.put(token.asBinder(), wtoken); |
| 2992 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | // Application tokens start out hidden. |
| 2995 | wtoken.hidden = true; |
| 2996 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2997 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2998 | //dump(); |
| 2999 | } |
| 3000 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | public void setAppGroupId(IBinder token, int groupId) { |
| 3003 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3004 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3005 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | synchronized(mWindowMap) { |
| 3009 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3010 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3011 | Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3012 | return; |
| 3013 | } |
| 3014 | wtoken.groupId = groupId; |
| 3015 | } |
| 3016 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3018 | public int getOrientationFromWindowsLocked() { |
| 3019 | int pos = mWindows.size() - 1; |
| 3020 | while (pos >= 0) { |
| 3021 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 3022 | pos--; |
| 3023 | if (wtoken.mAppToken != null) { |
| 3024 | // We hit an application window. so the orientation will be determined by the |
| 3025 | // app window. No point in continuing further. |
| 3026 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3027 | } |
| 3028 | if (!wtoken.isVisibleLw()) { |
| 3029 | continue; |
| 3030 | } |
| 3031 | int req = wtoken.mAttrs.screenOrientation; |
| 3032 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3033 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3034 | continue; |
| 3035 | } else { |
| 3036 | return req; |
| 3037 | } |
| 3038 | } |
| 3039 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3040 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3041 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3043 | int pos = mAppTokens.size() - 1; |
| 3044 | int curGroup = 0; |
| 3045 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3046 | boolean findingBehind = false; |
| 3047 | boolean haveGroup = false; |
| 3048 | boolean lastFullscreen = false; |
| 3049 | while (pos >= 0) { |
| 3050 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3051 | pos--; |
| 3052 | // if we're about to tear down this window and not seek for |
| 3053 | // the behind activity, don't use it for orientation |
| 3054 | if (!findingBehind |
| 3055 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3056 | continue; |
| 3057 | } |
| 3058 | |
| 3059 | if (!haveGroup) { |
| 3060 | // We ignore any hidden applications on the top. |
| 3061 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3062 | continue; |
| 3063 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3064 | haveGroup = true; |
| 3065 | curGroup = wtoken.groupId; |
| 3066 | lastOrientation = wtoken.requestedOrientation; |
| 3067 | } else if (curGroup != wtoken.groupId) { |
| 3068 | // If we have hit a new application group, and the bottom |
| 3069 | // of the previous group didn't explicitly say to use |
| 3070 | // the orientation behind it, and the last app was |
| 3071 | // full screen, then we'll stick with the |
| 3072 | // user's orientation. |
| 3073 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3074 | && lastFullscreen) { |
| 3075 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3076 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3077 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3078 | int or = wtoken.requestedOrientation; |
| 3079 | // If this application is fullscreen, and didn't explicitly say |
| 3080 | // to use the orientation behind it, then just take whatever |
| 3081 | // orientation it has and ignores whatever is under it. |
| 3082 | lastFullscreen = wtoken.appFullscreen; |
| 3083 | if (lastFullscreen |
| 3084 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3085 | return or; |
| 3086 | } |
| 3087 | // If this application has requested an explicit orientation, |
| 3088 | // then use it. |
| 3089 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3090 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3091 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3092 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3093 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3094 | return or; |
| 3095 | } |
| 3096 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3097 | } |
| 3098 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3099 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3100 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3101 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3102 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3103 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3104 | "updateOrientationFromAppTokens()")) { |
| 3105 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3106 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3107 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3108 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3110 | |
| 3111 | synchronized(mWindowMap) { |
| 3112 | if (updateOrientationFromAppTokensLocked()) { |
| 3113 | if (freezeThisOneIfNeeded != null) { |
| 3114 | AppWindowToken wtoken = findAppWindowToken( |
| 3115 | freezeThisOneIfNeeded); |
| 3116 | if (wtoken != null) { |
| 3117 | startAppFreezingScreenLocked(wtoken, |
| 3118 | ActivityInfo.CONFIG_ORIENTATION); |
| 3119 | } |
| 3120 | } |
| 3121 | config = computeNewConfigurationLocked(); |
| 3122 | |
| 3123 | } else if (currentConfig != null) { |
| 3124 | // No obvious action we need to take, but if our current |
| 3125 | // state mismatches the activity maanager's, update it |
| 3126 | mTempConfiguration.setToDefaults(); |
| 3127 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3128 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3129 | mWaitingForConfig = true; |
| 3130 | mLayoutNeeded = true; |
| 3131 | startFreezingDisplayLocked(); |
| 3132 | config = new Configuration(mTempConfiguration); |
| 3133 | } |
| 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3138 | Binder.restoreCallingIdentity(ident); |
| 3139 | return config; |
| 3140 | } |
| 3141 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3143 | * Determine the new desired orientation of the display, returning |
| 3144 | * a non-null new Configuration if it has changed from the current |
| 3145 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3146 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3147 | * SCREEN. This will typically be done for you if you call |
| 3148 | * sendNewConfiguration(). |
| 3149 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | * The orientation is computed from non-application windows first. If none of |
| 3151 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3152 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3153 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3154 | * android.os.IBinder) |
| 3155 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3156 | boolean updateOrientationFromAppTokensLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3157 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3158 | long ident = Binder.clearCallingIdentity(); |
| 3159 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3160 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3161 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3163 | mForcedAppOrientation = req; |
| 3164 | //send a message to Policy indicating orientation change to take |
| 3165 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3166 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3167 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3168 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3169 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | } |
| 3171 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3172 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3173 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(ident); |
| 3176 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3177 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3178 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3179 | int computeForcedAppOrientationLocked() { |
| 3180 | int req = getOrientationFromWindowsLocked(); |
| 3181 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3182 | req = getOrientationFromAppTokensLocked(); |
| 3183 | } |
| 3184 | return req; |
| 3185 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3186 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3187 | public void setNewConfiguration(Configuration config) { |
| 3188 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3189 | "setNewConfiguration()")) { |
| 3190 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3191 | } |
| 3192 | |
| 3193 | synchronized(mWindowMap) { |
| 3194 | mCurConfiguration = new Configuration(config); |
| 3195 | mWaitingForConfig = false; |
| 3196 | performLayoutAndPlaceSurfacesLocked(); |
| 3197 | } |
| 3198 | } |
| 3199 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3200 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3201 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3202 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3203 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3204 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3205 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | synchronized(mWindowMap) { |
| 3207 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3208 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3209 | Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | return; |
| 3211 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | wtoken.requestedOrientation = requestedOrientation; |
| 3214 | } |
| 3215 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3216 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | public int getAppOrientation(IApplicationToken token) { |
| 3218 | synchronized(mWindowMap) { |
| 3219 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3220 | if (wtoken == null) { |
| 3221 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3222 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3224 | return wtoken.requestedOrientation; |
| 3225 | } |
| 3226 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3228 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3229 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3230 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3231 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | synchronized(mWindowMap) { |
| 3235 | boolean changed = false; |
| 3236 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3237 | if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | changed = mFocusedApp != null; |
| 3239 | mFocusedApp = null; |
| 3240 | mKeyWaiter.tickle(); |
| 3241 | } else { |
| 3242 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3243 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3244 | Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | return; |
| 3246 | } |
| 3247 | changed = mFocusedApp != newFocus; |
| 3248 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3249 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3250 | mKeyWaiter.tickle(); |
| 3251 | } |
| 3252 | |
| 3253 | if (moveFocusNow && changed) { |
| 3254 | final long origId = Binder.clearCallingIdentity(); |
| 3255 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3256 | Binder.restoreCallingIdentity(origId); |
| 3257 | } |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | public void prepareAppTransition(int transit) { |
| 3262 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3263 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3264 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3268 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | TAG, "Prepare app transition: transit=" + transit |
| 3270 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3271 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3272 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3273 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3275 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3276 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3277 | // Opening a new task always supersedes a close for the anim. |
| 3278 | mNextAppTransition = transit; |
| 3279 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3280 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3281 | // Opening a new activity always supersedes a close for the anim. |
| 3282 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3283 | } |
| 3284 | mAppTransitionReady = false; |
| 3285 | mAppTransitionTimeout = false; |
| 3286 | mStartingIconInTransition = false; |
| 3287 | mSkipAppTransitionAnimation = false; |
| 3288 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3289 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3290 | 5000); |
| 3291 | } |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | public int getPendingAppTransition() { |
| 3296 | return mNextAppTransition; |
| 3297 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3298 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3299 | public void overridePendingAppTransition(String packageName, |
| 3300 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3301 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3302 | mNextAppTransitionPackage = packageName; |
| 3303 | mNextAppTransitionEnter = enterAnim; |
| 3304 | mNextAppTransitionExit = exitAnim; |
| 3305 | } |
| 3306 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | public void executeAppTransition() { |
| 3309 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3310 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3311 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3313 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3314 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3315 | if (DEBUG_APP_TRANSITIONS) { |
| 3316 | RuntimeException e = new RuntimeException("here"); |
| 3317 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3318 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3319 | + mNextAppTransition, e); |
| 3320 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3321 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | mAppTransitionReady = true; |
| 3323 | final long origId = Binder.clearCallingIdentity(); |
| 3324 | performLayoutAndPlaceSurfacesLocked(); |
| 3325 | Binder.restoreCallingIdentity(origId); |
| 3326 | } |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3331 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3332 | IBinder transferFrom, boolean createIfNeeded) { |
| 3333 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3334 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3335 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3339 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3341 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3342 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3344 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3345 | Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3346 | return; |
| 3347 | } |
| 3348 | |
| 3349 | // If the display is frozen, we won't do anything until the |
| 3350 | // actual window is displayed so there is no reason to put in |
| 3351 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3352 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | return; |
| 3354 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | if (wtoken.startingData != null) { |
| 3357 | return; |
| 3358 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3359 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | if (transferFrom != null) { |
| 3361 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3362 | if (ttoken != null) { |
| 3363 | WindowState startingWindow = ttoken.startingWindow; |
| 3364 | if (startingWindow != null) { |
| 3365 | if (mStartingIconInTransition) { |
| 3366 | // In this case, the starting icon has already |
| 3367 | // been displayed, so start letting windows get |
| 3368 | // shown immediately without any more transitions. |
| 3369 | mSkipAppTransitionAnimation = true; |
| 3370 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3371 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | "Moving existing starting from " + ttoken |
| 3373 | + " to " + wtoken); |
| 3374 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | // Transfer the starting window over to the new |
| 3377 | // token. |
| 3378 | wtoken.startingData = ttoken.startingData; |
| 3379 | wtoken.startingView = ttoken.startingView; |
| 3380 | wtoken.startingWindow = startingWindow; |
| 3381 | ttoken.startingData = null; |
| 3382 | ttoken.startingView = null; |
| 3383 | ttoken.startingWindow = null; |
| 3384 | ttoken.startingMoved = true; |
| 3385 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3386 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3387 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3388 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3389 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | mWindows.remove(startingWindow); |
| 3391 | ttoken.windows.remove(startingWindow); |
| 3392 | ttoken.allAppWindows.remove(startingWindow); |
| 3393 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3394 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3395 | // Propagate other interesting state between the |
| 3396 | // tokens. If the old token is displayed, we should |
| 3397 | // immediately force the new one to be displayed. If |
| 3398 | // it is animating, we need to move that animation to |
| 3399 | // the new one. |
| 3400 | if (ttoken.allDrawn) { |
| 3401 | wtoken.allDrawn = true; |
| 3402 | } |
| 3403 | if (ttoken.firstWindowDrawn) { |
| 3404 | wtoken.firstWindowDrawn = true; |
| 3405 | } |
| 3406 | if (!ttoken.hidden) { |
| 3407 | wtoken.hidden = false; |
| 3408 | wtoken.hiddenRequested = false; |
| 3409 | wtoken.willBeHidden = false; |
| 3410 | } |
| 3411 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3412 | wtoken.clientHidden = ttoken.clientHidden; |
| 3413 | wtoken.sendAppVisibilityToClients(); |
| 3414 | } |
| 3415 | if (ttoken.animation != null) { |
| 3416 | wtoken.animation = ttoken.animation; |
| 3417 | wtoken.animating = ttoken.animating; |
| 3418 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3419 | ttoken.animation = null; |
| 3420 | ttoken.animLayerAdjustment = 0; |
| 3421 | wtoken.updateLayers(); |
| 3422 | ttoken.updateLayers(); |
| 3423 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3424 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3426 | mLayoutNeeded = true; |
| 3427 | performLayoutAndPlaceSurfacesLocked(); |
| 3428 | Binder.restoreCallingIdentity(origId); |
| 3429 | return; |
| 3430 | } else if (ttoken.startingData != null) { |
| 3431 | // The previous app was getting ready to show a |
| 3432 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3433 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3434 | "Moving pending starting from " + ttoken |
| 3435 | + " to " + wtoken); |
| 3436 | wtoken.startingData = ttoken.startingData; |
| 3437 | ttoken.startingData = null; |
| 3438 | ttoken.startingMoved = true; |
| 3439 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3440 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3441 | // want to process the message ASAP, before any other queued |
| 3442 | // messages. |
| 3443 | mH.sendMessageAtFrontOfQueue(m); |
| 3444 | return; |
| 3445 | } |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | // There is no existing starting window, and the caller doesn't |
| 3450 | // want us to create one, so that's it! |
| 3451 | if (!createIfNeeded) { |
| 3452 | return; |
| 3453 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3454 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3455 | // If this is a translucent or wallpaper window, then don't |
| 3456 | // show a starting window -- the current effect (a full-screen |
| 3457 | // opaque starting window that fades away to the real contents |
| 3458 | // when it is ready) does not work for this. |
| 3459 | if (theme != 0) { |
| 3460 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3461 | com.android.internal.R.styleable.Window); |
| 3462 | if (ent.array.getBoolean( |
| 3463 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3464 | return; |
| 3465 | } |
| 3466 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3467 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3468 | return; |
| 3469 | } |
| 3470 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3471 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3472 | return; |
| 3473 | } |
| 3474 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3475 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | mStartingIconInTransition = true; |
| 3477 | wtoken.startingData = new StartingData( |
| 3478 | pkg, theme, nonLocalizedLabel, |
| 3479 | labelRes, icon); |
| 3480 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3481 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3482 | // want to process the message ASAP, before any other queued |
| 3483 | // messages. |
| 3484 | mH.sendMessageAtFrontOfQueue(m); |
| 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | public void setAppWillBeHidden(IBinder token) { |
| 3489 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3490 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3491 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | AppWindowToken wtoken; |
| 3495 | |
| 3496 | synchronized(mWindowMap) { |
| 3497 | wtoken = findAppWindowToken(token); |
| 3498 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3499 | Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | return; |
| 3501 | } |
| 3502 | wtoken.willBeHidden = true; |
| 3503 | } |
| 3504 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3507 | boolean visible, int transit, boolean performLayout) { |
| 3508 | boolean delayed = false; |
| 3509 | |
| 3510 | if (wtoken.clientHidden == visible) { |
| 3511 | wtoken.clientHidden = !visible; |
| 3512 | wtoken.sendAppVisibilityToClients(); |
| 3513 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3514 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3515 | wtoken.willBeHidden = false; |
| 3516 | if (wtoken.hidden == visible) { |
| 3517 | final int N = wtoken.allAppWindows.size(); |
| 3518 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3519 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3521 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3523 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3524 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3525 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | if (wtoken.animation == sDummyAnimation) { |
| 3527 | wtoken.animation = null; |
| 3528 | } |
| 3529 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3530 | changed = true; |
| 3531 | if (wtoken.animation != null) { |
| 3532 | delayed = runningAppAnimation = true; |
| 3533 | } |
| 3534 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3536 | for (int i=0; i<N; i++) { |
| 3537 | WindowState win = wtoken.allAppWindows.get(i); |
| 3538 | if (win == wtoken.startingWindow) { |
| 3539 | continue; |
| 3540 | } |
| 3541 | |
| 3542 | if (win.isAnimating()) { |
| 3543 | delayed = true; |
| 3544 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3545 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3546 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | //win.dump(" "); |
| 3548 | if (visible) { |
| 3549 | if (!win.isVisibleNow()) { |
| 3550 | if (!runningAppAnimation) { |
| 3551 | applyAnimationLocked(win, |
| 3552 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3553 | } |
| 3554 | changed = true; |
| 3555 | } |
| 3556 | } else if (win.isVisibleNow()) { |
| 3557 | if (!runningAppAnimation) { |
| 3558 | applyAnimationLocked(win, |
| 3559 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3560 | } |
| 3561 | mKeyWaiter.finishedKey(win.mSession, win.mClient, true, |
| 3562 | KeyWaiter.RETURN_NOTHING); |
| 3563 | changed = true; |
| 3564 | } |
| 3565 | } |
| 3566 | |
| 3567 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3568 | if (!visible) { |
| 3569 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3570 | } else { |
| 3571 | // If we are being set visible, and the starting window is |
| 3572 | // not yet displayed, then make sure it doesn't get displayed. |
| 3573 | WindowState swin = wtoken.startingWindow; |
| 3574 | if (swin != null && (swin.mDrawPending |
| 3575 | || swin.mCommitDrawPending)) { |
| 3576 | swin.mPolicyVisibility = false; |
| 3577 | swin.mPolicyVisibilityAfterAnim = false; |
| 3578 | } |
| 3579 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3580 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3581 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3583 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3584 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3585 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3587 | if (performLayout) { |
| 3588 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3589 | performLayoutAndPlaceSurfacesLocked(); |
| 3590 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | } |
| 3592 | } |
| 3593 | |
| 3594 | if (wtoken.animation != null) { |
| 3595 | delayed = true; |
| 3596 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | return delayed; |
| 3599 | } |
| 3600 | |
| 3601 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3602 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3603 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3604 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | AppWindowToken wtoken; |
| 3608 | |
| 3609 | synchronized(mWindowMap) { |
| 3610 | wtoken = findAppWindowToken(token); |
| 3611 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3612 | Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | return; |
| 3614 | } |
| 3615 | |
| 3616 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3617 | RuntimeException e = null; |
| 3618 | if (!HIDE_STACK_CRAWLS) { |
| 3619 | e = new RuntimeException(); |
| 3620 | e.fillInStackTrace(); |
| 3621 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3622 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | + "): mNextAppTransition=" + mNextAppTransition |
| 3624 | + " hidden=" + wtoken.hidden |
| 3625 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3626 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3627 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3628 | // If we are preparing an app transition, then delay changing |
| 3629 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3630 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3631 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | // Already in requested state, don't do anything more. |
| 3633 | if (wtoken.hiddenRequested != visible) { |
| 3634 | return; |
| 3635 | } |
| 3636 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3637 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3638 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | TAG, "Setting dummy animation on: " + wtoken); |
| 3640 | wtoken.setDummyAnimation(); |
| 3641 | mOpeningApps.remove(wtoken); |
| 3642 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3643 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3644 | wtoken.inPendingTransaction = true; |
| 3645 | if (visible) { |
| 3646 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | wtoken.startingDisplayed = false; |
| 3648 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3649 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3650 | // If the token is currently hidden (should be the |
| 3651 | // common case), then we need to set up to wait for |
| 3652 | // its windows to be ready. |
| 3653 | if (wtoken.hidden) { |
| 3654 | wtoken.allDrawn = false; |
| 3655 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3656 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3657 | if (wtoken.clientHidden) { |
| 3658 | // In the case where we are making an app visible |
| 3659 | // but holding off for a transition, we still need |
| 3660 | // to tell the client to make its windows visible so |
| 3661 | // they get drawn. Otherwise, we will wait on |
| 3662 | // performing the transition until all windows have |
| 3663 | // been drawn, they never will be, and we are sad. |
| 3664 | wtoken.clientHidden = false; |
| 3665 | wtoken.sendAppVisibilityToClients(); |
| 3666 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | } |
| 3668 | } else { |
| 3669 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3670 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3671 | // If the token is currently visible (should be the |
| 3672 | // common case), then set up to wait for it to be hidden. |
| 3673 | if (!wtoken.hidden) { |
| 3674 | wtoken.waitingToHide = true; |
| 3675 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | } |
| 3677 | return; |
| 3678 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3681 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | wtoken.updateReportedVisibilityLocked(); |
| 3683 | Binder.restoreCallingIdentity(origId); |
| 3684 | } |
| 3685 | } |
| 3686 | |
| 3687 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3688 | boolean unfreezeSurfaceNow, boolean force) { |
| 3689 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3690 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | + " force=" + force); |
| 3692 | final int N = wtoken.allAppWindows.size(); |
| 3693 | boolean unfrozeWindows = false; |
| 3694 | for (int i=0; i<N; i++) { |
| 3695 | WindowState w = wtoken.allAppWindows.get(i); |
| 3696 | if (w.mAppFreezing) { |
| 3697 | w.mAppFreezing = false; |
| 3698 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3699 | w.mOrientationChanging = true; |
| 3700 | } |
| 3701 | unfrozeWindows = true; |
| 3702 | } |
| 3703 | } |
| 3704 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3705 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | wtoken.freezingScreen = false; |
| 3707 | mAppsFreezingScreen--; |
| 3708 | } |
| 3709 | if (unfreezeSurfaceNow) { |
| 3710 | if (unfrozeWindows) { |
| 3711 | mLayoutNeeded = true; |
| 3712 | performLayoutAndPlaceSurfacesLocked(); |
| 3713 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3714 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3718 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3720 | int configChanges) { |
| 3721 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3722 | RuntimeException e = null; |
| 3723 | if (!HIDE_STACK_CRAWLS) { |
| 3724 | e = new RuntimeException(); |
| 3725 | e.fillInStackTrace(); |
| 3726 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3727 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3729 | + wtoken.freezingScreen, e); |
| 3730 | } |
| 3731 | if (!wtoken.hiddenRequested) { |
| 3732 | if (!wtoken.freezingScreen) { |
| 3733 | wtoken.freezingScreen = true; |
| 3734 | mAppsFreezingScreen++; |
| 3735 | if (mAppsFreezingScreen == 1) { |
| 3736 | startFreezingDisplayLocked(); |
| 3737 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3738 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3739 | 5000); |
| 3740 | } |
| 3741 | } |
| 3742 | final int N = wtoken.allAppWindows.size(); |
| 3743 | for (int i=0; i<N; i++) { |
| 3744 | WindowState w = wtoken.allAppWindows.get(i); |
| 3745 | w.mAppFreezing = true; |
| 3746 | } |
| 3747 | } |
| 3748 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3750 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3751 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3752 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3753 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3757 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3758 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3759 | return; |
| 3760 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3763 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3764 | Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3765 | return; |
| 3766 | } |
| 3767 | final long origId = Binder.clearCallingIdentity(); |
| 3768 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3769 | Binder.restoreCallingIdentity(origId); |
| 3770 | } |
| 3771 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3772 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3773 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3774 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3775 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3776 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | synchronized(mWindowMap) { |
| 3780 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3781 | if (wtoken == null || wtoken.appToken == null) { |
| 3782 | return; |
| 3783 | } |
| 3784 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3785 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3787 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3788 | Binder.restoreCallingIdentity(origId); |
| 3789 | } |
| 3790 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3791 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3792 | public void removeAppToken(IBinder token) { |
| 3793 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3794 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3795 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | AppWindowToken wtoken = null; |
| 3799 | AppWindowToken startingToken = null; |
| 3800 | boolean delayed = false; |
| 3801 | |
| 3802 | final long origId = Binder.clearCallingIdentity(); |
| 3803 | synchronized(mWindowMap) { |
| 3804 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3805 | mTokenList.remove(basewtoken); |
| 3806 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3807 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3808 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | wtoken.inPendingTransaction = false; |
| 3810 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3811 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3812 | if (mClosingApps.contains(wtoken)) { |
| 3813 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3814 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3816 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3817 | delayed = true; |
| 3818 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3819 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3820 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3821 | + " animation=" + wtoken.animation |
| 3822 | + " animating=" + wtoken.animating); |
| 3823 | if (delayed) { |
| 3824 | // set the token aside because it has an active animation to be finished |
| 3825 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3826 | } else { |
| 3827 | // Make sure there is no animation running on this token, |
| 3828 | // so any windows associated with it will be removed as |
| 3829 | // soon as their animations are complete |
| 3830 | wtoken.animation = null; |
| 3831 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | } |
| 3833 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3834 | if (mLastEnterAnimToken == wtoken) { |
| 3835 | mLastEnterAnimToken = null; |
| 3836 | mLastEnterAnimParams = null; |
| 3837 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3838 | wtoken.removed = true; |
| 3839 | if (wtoken.startingData != null) { |
| 3840 | startingToken = wtoken; |
| 3841 | } |
| 3842 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3843 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3844 | if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3845 | mFocusedApp = null; |
| 3846 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3847 | mKeyWaiter.tickle(); |
| 3848 | } |
| 3849 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3850 | Slog.w(TAG, "Attempted to remove non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3852 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3853 | if (!delayed && wtoken != null) { |
| 3854 | wtoken.updateReportedVisibilityLocked(); |
| 3855 | } |
| 3856 | } |
| 3857 | Binder.restoreCallingIdentity(origId); |
| 3858 | |
| 3859 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3860 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3861 | + startingToken + ": app token removed"); |
| 3862 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3863 | mH.sendMessage(m); |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3868 | final int NW = token.windows.size(); |
| 3869 | for (int i=0; i<NW; i++) { |
| 3870 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3871 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | mWindows.remove(win); |
| 3873 | int j = win.mChildWindows.size(); |
| 3874 | while (j > 0) { |
| 3875 | j--; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3876 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3877 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3878 | "Tmp removing child window " + cwin); |
| 3879 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | return NW > 0; |
| 3883 | } |
| 3884 | |
| 3885 | void dumpAppTokensLocked() { |
| 3886 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3887 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3888 | } |
| 3889 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3890 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3891 | void dumpWindowsLocked() { |
| 3892 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3893 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | } |
| 3895 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3897 | private int findWindowOffsetLocked(int tokenPos) { |
| 3898 | final int NW = mWindows.size(); |
| 3899 | |
| 3900 | if (tokenPos >= mAppTokens.size()) { |
| 3901 | int i = NW; |
| 3902 | while (i > 0) { |
| 3903 | i--; |
| 3904 | WindowState win = (WindowState)mWindows.get(i); |
| 3905 | if (win.getAppToken() != null) { |
| 3906 | return i+1; |
| 3907 | } |
| 3908 | } |
| 3909 | } |
| 3910 | |
| 3911 | while (tokenPos > 0) { |
| 3912 | // Find the first app token below the new position that has |
| 3913 | // a window displayed. |
| 3914 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3915 | if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3917 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3918 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3919 | "Skipping token -- currently sending to bottom"); |
| 3920 | tokenPos--; |
| 3921 | continue; |
| 3922 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3923 | int i = wtoken.windows.size(); |
| 3924 | while (i > 0) { |
| 3925 | i--; |
| 3926 | WindowState win = wtoken.windows.get(i); |
| 3927 | int j = win.mChildWindows.size(); |
| 3928 | while (j > 0) { |
| 3929 | j--; |
| 3930 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3931 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | for (int pos=NW-1; pos>=0; pos--) { |
| 3933 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3934 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3935 | "Found child win @" + (pos+1)); |
| 3936 | return pos+1; |
| 3937 | } |
| 3938 | } |
| 3939 | } |
| 3940 | } |
| 3941 | for (int pos=NW-1; pos>=0; pos--) { |
| 3942 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3943 | if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3944 | return pos+1; |
| 3945 | } |
| 3946 | } |
| 3947 | } |
| 3948 | tokenPos--; |
| 3949 | } |
| 3950 | |
| 3951 | return 0; |
| 3952 | } |
| 3953 | |
| 3954 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3955 | final int NCW = win.mChildWindows.size(); |
| 3956 | boolean added = false; |
| 3957 | for (int j=0; j<NCW; j++) { |
| 3958 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3959 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3960 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3961 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3962 | mWindows.add(index, win); |
| 3963 | index++; |
| 3964 | added = true; |
| 3965 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3966 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3967 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3968 | mWindows.add(index, cwin); |
| 3969 | index++; |
| 3970 | } |
| 3971 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3972 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3973 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3974 | mWindows.add(index, win); |
| 3975 | index++; |
| 3976 | } |
| 3977 | return index; |
| 3978 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3981 | final int NW = token.windows.size(); |
| 3982 | for (int i=0; i<NW; i++) { |
| 3983 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3984 | } |
| 3985 | return index; |
| 3986 | } |
| 3987 | |
| 3988 | public void moveAppToken(int index, IBinder token) { |
| 3989 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3990 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3991 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | } |
| 3993 | |
| 3994 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3995 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3997 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3998 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3999 | Slog.w(TAG, "Attempting to reorder token that doesn't exist: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4000 | + token + " (" + wtoken + ")"); |
| 4001 | return; |
| 4002 | } |
| 4003 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4004 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4006 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4007 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4008 | if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4010 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4011 | if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4013 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4014 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4015 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4016 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4017 | mLayoutNeeded = true; |
| 4018 | performLayoutAndPlaceSurfacesLocked(); |
| 4019 | } |
| 4020 | Binder.restoreCallingIdentity(origId); |
| 4021 | } |
| 4022 | } |
| 4023 | |
| 4024 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4025 | // XXX This should be done more efficiently! |
| 4026 | // (take advantage of the fact that both lists should be |
| 4027 | // ordered in the same way.) |
| 4028 | int N = tokens.size(); |
| 4029 | for (int i=0; i<N; i++) { |
| 4030 | IBinder token = tokens.get(i); |
| 4031 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4032 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4033 | Slog.w(TAG, "Attempting to reorder token that doesn't exist: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | + token + " (" + wtoken + ")"); |
| 4035 | i--; |
| 4036 | N--; |
| 4037 | } |
| 4038 | } |
| 4039 | } |
| 4040 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4041 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4042 | boolean updateFocusAndLayout) { |
| 4043 | // First remove all of the windows from the list. |
| 4044 | tmpRemoveAppWindowsLocked(wtoken); |
| 4045 | |
| 4046 | // Where to start adding? |
| 4047 | int pos = findWindowOffsetLocked(tokenPos); |
| 4048 | |
| 4049 | // And now add them back at the correct place. |
| 4050 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4051 | |
| 4052 | if (updateFocusAndLayout) { |
| 4053 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4054 | assignLayersLocked(); |
| 4055 | } |
| 4056 | mLayoutNeeded = true; |
| 4057 | performLayoutAndPlaceSurfacesLocked(); |
| 4058 | } |
| 4059 | } |
| 4060 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4061 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4062 | // First remove all of the windows from the list. |
| 4063 | final int N = tokens.size(); |
| 4064 | int i; |
| 4065 | for (i=0; i<N; i++) { |
| 4066 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4067 | if (token != null) { |
| 4068 | tmpRemoveAppWindowsLocked(token); |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | // Where to start adding? |
| 4073 | int pos = findWindowOffsetLocked(tokenPos); |
| 4074 | |
| 4075 | // And now add them back at the correct place. |
| 4076 | for (i=0; i<N; i++) { |
| 4077 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4078 | if (token != null) { |
| 4079 | pos = reAddAppWindowsLocked(pos, token); |
| 4080 | } |
| 4081 | } |
| 4082 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4083 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4084 | assignLayersLocked(); |
| 4085 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4086 | mLayoutNeeded = true; |
| 4087 | performLayoutAndPlaceSurfacesLocked(); |
| 4088 | |
| 4089 | //dump(); |
| 4090 | } |
| 4091 | |
| 4092 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4093 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4094 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4095 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | final long origId = Binder.clearCallingIdentity(); |
| 4099 | synchronized(mWindowMap) { |
| 4100 | removeAppTokensLocked(tokens); |
| 4101 | final int N = tokens.size(); |
| 4102 | for (int i=0; i<N; i++) { |
| 4103 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4104 | if (wt != null) { |
| 4105 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4106 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4107 | mToTopApps.remove(wt); |
| 4108 | mToBottomApps.remove(wt); |
| 4109 | mToTopApps.add(wt); |
| 4110 | wt.sendingToBottom = false; |
| 4111 | wt.sendingToTop = true; |
| 4112 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | } |
| 4114 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4115 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4116 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4117 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4118 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | } |
| 4120 | Binder.restoreCallingIdentity(origId); |
| 4121 | } |
| 4122 | |
| 4123 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4124 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4125 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4126 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | final long origId = Binder.clearCallingIdentity(); |
| 4130 | synchronized(mWindowMap) { |
| 4131 | removeAppTokensLocked(tokens); |
| 4132 | final int N = tokens.size(); |
| 4133 | int pos = 0; |
| 4134 | for (int i=0; i<N; i++) { |
| 4135 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4136 | if (wt != null) { |
| 4137 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4138 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4139 | mToTopApps.remove(wt); |
| 4140 | mToBottomApps.remove(wt); |
| 4141 | mToBottomApps.add(i, wt); |
| 4142 | wt.sendingToTop = false; |
| 4143 | wt.sendingToBottom = true; |
| 4144 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4145 | pos++; |
| 4146 | } |
| 4147 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4148 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4149 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4150 | moveAppWindowsLocked(tokens, 0); |
| 4151 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | } |
| 4153 | Binder.restoreCallingIdentity(origId); |
| 4154 | } |
| 4155 | |
| 4156 | // ------------------------------------------------------------- |
| 4157 | // Misc IWindowSession methods |
| 4158 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4160 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4161 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4162 | != PackageManager.PERMISSION_GRANTED) { |
| 4163 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4164 | } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4165 | synchronized (mKeyguardTokenWatcher) { |
| 4166 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4167 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4171 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | != PackageManager.PERMISSION_GRANTED) { |
| 4173 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4174 | } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4175 | synchronized (mKeyguardTokenWatcher) { |
| 4176 | mKeyguardTokenWatcher.release(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4178 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4179 | // If we are the last one to reenable the keyguard wait until |
| 4180 | // we have actaully finished reenabling until returning. |
| 4181 | // It is possible that reenableKeyguard() can be called before |
| 4182 | // the previous disableKeyguard() is handled, in which case |
| 4183 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4184 | // be called. In that case mKeyguardDisabled will be false here |
| 4185 | // and we have nothing to wait for. |
| 4186 | while (mKeyguardDisabled) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4187 | try { |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 4188 | mKeyguardTokenWatcher.wait(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | } catch (InterruptedException e) { |
| 4190 | Thread.currentThread().interrupt(); |
| 4191 | } |
| 4192 | } |
| 4193 | } |
| 4194 | } |
| 4195 | } |
| 4196 | |
| 4197 | /** |
| 4198 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4199 | */ |
| 4200 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4201 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | != PackageManager.PERMISSION_GRANTED) { |
| 4203 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4204 | } |
| 4205 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4206 | public void onKeyguardExitResult(boolean success) { |
| 4207 | try { |
| 4208 | callback.onKeyguardExitResult(success); |
| 4209 | } catch (RemoteException e) { |
| 4210 | // Client has died, we don't care. |
| 4211 | } |
| 4212 | } |
| 4213 | }); |
| 4214 | } |
| 4215 | |
| 4216 | public boolean inKeyguardRestrictedInputMode() { |
| 4217 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4218 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4219 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4220 | public void closeSystemDialogs(String reason) { |
| 4221 | synchronized(mWindowMap) { |
| 4222 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4223 | WindowState w = (WindowState)mWindows.get(i); |
| 4224 | if (w.mSurface != null) { |
| 4225 | try { |
| 4226 | w.mClient.closeSystemDialogs(reason); |
| 4227 | } catch (RemoteException e) { |
| 4228 | } |
| 4229 | } |
| 4230 | } |
| 4231 | } |
| 4232 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4233 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | static float fixScale(float scale) { |
| 4235 | if (scale < 0) scale = 0; |
| 4236 | else if (scale > 20) scale = 20; |
| 4237 | return Math.abs(scale); |
| 4238 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4239 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | public void setAnimationScale(int which, float scale) { |
| 4241 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4242 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4243 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | if (scale < 0) scale = 0; |
| 4247 | else if (scale > 20) scale = 20; |
| 4248 | scale = Math.abs(scale); |
| 4249 | switch (which) { |
| 4250 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4251 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4252 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | // Persist setting |
| 4255 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4256 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | public void setAnimationScales(float[] scales) { |
| 4259 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4260 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4261 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | if (scales != null) { |
| 4265 | if (scales.length >= 1) { |
| 4266 | mWindowAnimationScale = fixScale(scales[0]); |
| 4267 | } |
| 4268 | if (scales.length >= 2) { |
| 4269 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4270 | } |
| 4271 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4273 | // Persist setting |
| 4274 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4275 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4276 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4277 | public float getAnimationScale(int which) { |
| 4278 | switch (which) { |
| 4279 | case 0: return mWindowAnimationScale; |
| 4280 | case 1: return mTransitionAnimationScale; |
| 4281 | } |
| 4282 | return 0; |
| 4283 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | public float[] getAnimationScales() { |
| 4286 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4287 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4289 | public int getSwitchState(int sw) { |
| 4290 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4291 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4292 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4293 | } |
| 4294 | return KeyInputQueue.getSwitchState(sw); |
| 4295 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4296 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4297 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4298 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4299 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4300 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4301 | } |
| 4302 | return KeyInputQueue.getSwitchState(devid, sw); |
| 4303 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4304 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4305 | public int getScancodeState(int sw) { |
| 4306 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4307 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4308 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4310 | return mQueue.getScancodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4314 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4315 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4316 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4318 | return mQueue.getScancodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4320 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4321 | public int getTrackballScancodeState(int sw) { |
| 4322 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4323 | "getTrackballScancodeState()")) { |
| 4324 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4325 | } |
| 4326 | return mQueue.getTrackballScancodeState(sw); |
| 4327 | } |
| 4328 | |
| 4329 | public int getDPadScancodeState(int sw) { |
| 4330 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4331 | "getDPadScancodeState()")) { |
| 4332 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4333 | } |
| 4334 | return mQueue.getDPadScancodeState(sw); |
| 4335 | } |
| 4336 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4337 | public int getKeycodeState(int sw) { |
| 4338 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4339 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4340 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4341 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4342 | return mQueue.getKeycodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4343 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4344 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4345 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4346 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4347 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4348 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | } |
| Dianne Hackborn | 6af0d50 | 2009-09-28 13:25:46 -0700 | [diff] [blame] | 4350 | return mQueue.getKeycodeState(devid, sw); |
| 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 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4353 | public int getTrackballKeycodeState(int sw) { |
| 4354 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4355 | "getTrackballKeycodeState()")) { |
| 4356 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4357 | } |
| 4358 | return mQueue.getTrackballKeycodeState(sw); |
| 4359 | } |
| 4360 | |
| 4361 | public int getDPadKeycodeState(int sw) { |
| 4362 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4363 | "getDPadKeycodeState()")) { |
| 4364 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4365 | } |
| 4366 | return mQueue.getDPadKeycodeState(sw); |
| 4367 | } |
| 4368 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| 4370 | return KeyInputQueue.hasKeys(keycodes, keyExists); |
| 4371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4373 | public void enableScreenAfterBoot() { |
| 4374 | synchronized(mWindowMap) { |
| 4375 | if (mSystemBooted) { |
| 4376 | return; |
| 4377 | } |
| 4378 | mSystemBooted = true; |
| 4379 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4381 | performEnableScreen(); |
| 4382 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | public void enableScreenIfNeededLocked() { |
| 4385 | if (mDisplayEnabled) { |
| 4386 | return; |
| 4387 | } |
| 4388 | if (!mSystemBooted) { |
| 4389 | return; |
| 4390 | } |
| 4391 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4392 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4393 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | public void performEnableScreen() { |
| 4395 | synchronized(mWindowMap) { |
| 4396 | if (mDisplayEnabled) { |
| 4397 | return; |
| 4398 | } |
| 4399 | if (!mSystemBooted) { |
| 4400 | return; |
| 4401 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | // Don't enable the screen until all existing windows |
| 4404 | // have been drawn. |
| 4405 | final int N = mWindows.size(); |
| 4406 | for (int i=0; i<N; i++) { |
| 4407 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4408 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4409 | return; |
| 4410 | } |
| 4411 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4412 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4413 | mDisplayEnabled = true; |
| 4414 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4415 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | StringWriter sw = new StringWriter(); |
| 4417 | PrintWriter pw = new PrintWriter(sw); |
| 4418 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4419 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4420 | } |
| 4421 | try { |
| 4422 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4423 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4424 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | Parcel data = Parcel.obtain(); |
| 4426 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4427 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4428 | data, null, 0); |
| 4429 | data.recycle(); |
| 4430 | } |
| 4431 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4432 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | } |
| 4434 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4439 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4440 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4441 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | public void setInTouchMode(boolean mode) { |
| 4444 | synchronized(mWindowMap) { |
| 4445 | mInTouchMode = mode; |
| 4446 | } |
| 4447 | } |
| 4448 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4449 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4450 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4452 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4453 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4454 | } |
| 4455 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4456 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4457 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4458 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4459 | public void setRotationUnchecked(int rotation, |
| 4460 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4461 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| 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 | long origId = Binder.clearCallingIdentity(); |
| 4465 | boolean changed; |
| 4466 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4467 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4468 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4469 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4470 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | sendNewConfiguration(); |
| 4472 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | Binder.restoreCallingIdentity(origId); |
| 4475 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4476 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4477 | /** |
| 4478 | * Apply a new rotation to the screen, respecting the requests of |
| 4479 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4480 | * re-evaluate the desired rotation. |
| 4481 | * |
| 4482 | * Returns null if the rotation has been changed. In this case YOU |
| 4483 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4484 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4485 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4486 | boolean changed; |
| 4487 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4488 | rotation = mRequestedRotation; |
| 4489 | } else { |
| 4490 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4491 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4492 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4493 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 4494 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4495 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4496 | if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4497 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4498 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4499 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4500 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4501 | "Rotation changed to " + rotation |
| 4502 | + " from " + mRotation |
| 4503 | + " (forceApp=" + mForcedAppOrientation |
| 4504 | + ", req=" + mRequestedRotation + ")"); |
| 4505 | mRotation = rotation; |
| 4506 | mWindowsFreezingScreen = true; |
| 4507 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4508 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4509 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4510 | mWaitingForConfig = true; |
| 4511 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4512 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4513 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4514 | mQueue.setOrientation(rotation); |
| 4515 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4516 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | } |
| 4518 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4519 | WindowState w = (WindowState)mWindows.get(i); |
| 4520 | if (w.mSurface != null) { |
| 4521 | w.mOrientationChanging = true; |
| 4522 | } |
| 4523 | } |
| 4524 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4525 | try { |
| 4526 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4527 | } catch (RemoteException e) { |
| 4528 | } |
| 4529 | } |
| 4530 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4532 | return changed; |
| 4533 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | public int getRotation() { |
| 4536 | return mRotation; |
| 4537 | } |
| 4538 | |
| 4539 | public int watchRotation(IRotationWatcher watcher) { |
| 4540 | final IBinder watcherBinder = watcher.asBinder(); |
| 4541 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4542 | public void binderDied() { |
| 4543 | synchronized (mWindowMap) { |
| 4544 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4545 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4546 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4547 | if (removed != null) { |
| 4548 | removed.asBinder().unlinkToDeath(this, 0); |
| 4549 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4550 | i--; |
| 4551 | } |
| 4552 | } |
| 4553 | } |
| 4554 | } |
| 4555 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4557 | synchronized (mWindowMap) { |
| 4558 | try { |
| 4559 | watcher.asBinder().linkToDeath(dr, 0); |
| 4560 | mRotationWatchers.add(watcher); |
| 4561 | } catch (RemoteException e) { |
| 4562 | // Client died, no cleanup needed. |
| 4563 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4564 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4565 | return mRotation; |
| 4566 | } |
| 4567 | } |
| 4568 | |
| 4569 | /** |
| 4570 | * Starts the view server on the specified port. |
| 4571 | * |
| 4572 | * @param port The port to listener to. |
| 4573 | * |
| 4574 | * @return True if the server was successfully started, false otherwise. |
| 4575 | * |
| 4576 | * @see com.android.server.ViewServer |
| 4577 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4578 | */ |
| 4579 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4580 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | return false; |
| 4582 | } |
| 4583 | |
| 4584 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4585 | return false; |
| 4586 | } |
| 4587 | |
| 4588 | if (port < 1024) { |
| 4589 | return false; |
| 4590 | } |
| 4591 | |
| 4592 | if (mViewServer != null) { |
| 4593 | if (!mViewServer.isRunning()) { |
| 4594 | try { |
| 4595 | return mViewServer.start(); |
| 4596 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4597 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | } |
| 4599 | } |
| 4600 | return false; |
| 4601 | } |
| 4602 | |
| 4603 | try { |
| 4604 | mViewServer = new ViewServer(this, port); |
| 4605 | return mViewServer.start(); |
| 4606 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4607 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4608 | } |
| 4609 | return false; |
| 4610 | } |
| 4611 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4612 | private boolean isSystemSecure() { |
| 4613 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4614 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4615 | } |
| 4616 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4617 | /** |
| 4618 | * Stops the view server if it exists. |
| 4619 | * |
| 4620 | * @return True if the server stopped, false if it wasn't started or |
| 4621 | * couldn't be stopped. |
| 4622 | * |
| 4623 | * @see com.android.server.ViewServer |
| 4624 | */ |
| 4625 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4626 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | return false; |
| 4628 | } |
| 4629 | |
| 4630 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4631 | return false; |
| 4632 | } |
| 4633 | |
| 4634 | if (mViewServer != null) { |
| 4635 | return mViewServer.stop(); |
| 4636 | } |
| 4637 | return false; |
| 4638 | } |
| 4639 | |
| 4640 | /** |
| 4641 | * Indicates whether the view server is running. |
| 4642 | * |
| 4643 | * @return True if the server is running, false otherwise. |
| 4644 | * |
| 4645 | * @see com.android.server.ViewServer |
| 4646 | */ |
| 4647 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4648 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4649 | return false; |
| 4650 | } |
| 4651 | |
| 4652 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4653 | return false; |
| 4654 | } |
| 4655 | |
| 4656 | return mViewServer != null && mViewServer.isRunning(); |
| 4657 | } |
| 4658 | |
| 4659 | /** |
| 4660 | * Lists all availble windows in the system. The listing is written in the |
| 4661 | * specified Socket's output stream with the following syntax: |
| 4662 | * windowHashCodeInHexadecimal windowName |
| 4663 | * Each line of the ouput represents a different window. |
| 4664 | * |
| 4665 | * @param client The remote client to send the listing to. |
| 4666 | * @return False if an error occured, true otherwise. |
| 4667 | */ |
| 4668 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4669 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | return false; |
| 4671 | } |
| 4672 | |
| 4673 | boolean result = true; |
| 4674 | |
| 4675 | Object[] windows; |
| 4676 | synchronized (mWindowMap) { |
| 4677 | windows = new Object[mWindows.size()]; |
| 4678 | //noinspection unchecked |
| 4679 | windows = mWindows.toArray(windows); |
| 4680 | } |
| 4681 | |
| 4682 | BufferedWriter out = null; |
| 4683 | |
| 4684 | // Any uncaught exception will crash the system process |
| 4685 | try { |
| 4686 | OutputStream clientStream = client.getOutputStream(); |
| 4687 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4688 | |
| 4689 | final int count = windows.length; |
| 4690 | for (int i = 0; i < count; i++) { |
| 4691 | final WindowState w = (WindowState) windows[i]; |
| 4692 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4693 | out.write(' '); |
| 4694 | out.append(w.mAttrs.getTitle()); |
| 4695 | out.write('\n'); |
| 4696 | } |
| 4697 | |
| 4698 | out.write("DONE.\n"); |
| 4699 | out.flush(); |
| 4700 | } catch (Exception e) { |
| 4701 | result = false; |
| 4702 | } finally { |
| 4703 | if (out != null) { |
| 4704 | try { |
| 4705 | out.close(); |
| 4706 | } catch (IOException e) { |
| 4707 | result = false; |
| 4708 | } |
| 4709 | } |
| 4710 | } |
| 4711 | |
| 4712 | return result; |
| 4713 | } |
| 4714 | |
| 4715 | /** |
| 4716 | * Sends a command to a target window. The result of the command, if any, will be |
| 4717 | * written in the output stream of the specified socket. |
| 4718 | * |
| 4719 | * The parameters must follow this syntax: |
| 4720 | * windowHashcode extra |
| 4721 | * |
| 4722 | * Where XX is the length in characeters of the windowTitle. |
| 4723 | * |
| 4724 | * The first parameter is the target window. The window with the specified hashcode |
| 4725 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4726 | * will be delivered to the target window and as parameters to the command itself. |
| 4727 | * |
| 4728 | * @param client The remote client to sent the result, if any, to. |
| 4729 | * @param command The command to execute. |
| 4730 | * @param parameters The command parameters. |
| 4731 | * |
| 4732 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4733 | * not indicate whether the command itself was successful. |
| 4734 | */ |
| 4735 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4736 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | return false; |
| 4738 | } |
| 4739 | |
| 4740 | boolean success = true; |
| 4741 | Parcel data = null; |
| 4742 | Parcel reply = null; |
| 4743 | |
| 4744 | // Any uncaught exception will crash the system process |
| 4745 | try { |
| 4746 | // Find the hashcode of the window |
| 4747 | int index = parameters.indexOf(' '); |
| 4748 | if (index == -1) { |
| 4749 | index = parameters.length(); |
| 4750 | } |
| 4751 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4752 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4753 | |
| 4754 | // Extract the command's parameter after the window description |
| 4755 | if (index < parameters.length()) { |
| 4756 | parameters = parameters.substring(index + 1); |
| 4757 | } else { |
| 4758 | parameters = ""; |
| 4759 | } |
| 4760 | |
| 4761 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4762 | if (window == null) { |
| 4763 | return false; |
| 4764 | } |
| 4765 | |
| 4766 | data = Parcel.obtain(); |
| 4767 | data.writeInterfaceToken("android.view.IWindow"); |
| 4768 | data.writeString(command); |
| 4769 | data.writeString(parameters); |
| 4770 | data.writeInt(1); |
| 4771 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4772 | |
| 4773 | reply = Parcel.obtain(); |
| 4774 | |
| 4775 | final IBinder binder = window.mClient.asBinder(); |
| 4776 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4777 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4778 | |
| 4779 | reply.readException(); |
| 4780 | |
| 4781 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4782 | Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | success = false; |
| 4784 | } finally { |
| 4785 | if (data != null) { |
| 4786 | data.recycle(); |
| 4787 | } |
| 4788 | if (reply != null) { |
| 4789 | reply.recycle(); |
| 4790 | } |
| 4791 | } |
| 4792 | |
| 4793 | return success; |
| 4794 | } |
| 4795 | |
| 4796 | private WindowState findWindow(int hashCode) { |
| 4797 | if (hashCode == -1) { |
| 4798 | return getFocusedWindow(); |
| 4799 | } |
| 4800 | |
| 4801 | synchronized (mWindowMap) { |
| 4802 | final ArrayList windows = mWindows; |
| 4803 | final int count = windows.size(); |
| 4804 | |
| 4805 | for (int i = 0; i < count; i++) { |
| 4806 | WindowState w = (WindowState) windows.get(i); |
| 4807 | if (System.identityHashCode(w) == hashCode) { |
| 4808 | return w; |
| 4809 | } |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | return null; |
| 4814 | } |
| 4815 | |
| 4816 | /* |
| 4817 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4818 | * that to config-changed listeners if appropriate. |
| 4819 | */ |
| 4820 | void sendNewConfiguration() { |
| 4821 | try { |
| 4822 | mActivityManager.updateConfiguration(null); |
| 4823 | } catch (RemoteException e) { |
| 4824 | } |
| 4825 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4826 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4827 | public Configuration computeNewConfiguration() { |
| 4828 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4829 | return computeNewConfigurationLocked(); |
| 4830 | } |
| 4831 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4832 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4833 | Configuration computeNewConfigurationLocked() { |
| 4834 | Configuration config = new Configuration(); |
| 4835 | if (!computeNewConfigurationLocked(config)) { |
| 4836 | return null; |
| 4837 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4838 | return config; |
| 4839 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4840 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4841 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4842 | if (mDisplay == null) { |
| 4843 | return false; |
| 4844 | } |
| 4845 | mQueue.getInputConfiguration(config); |
| 4846 | final int dw = mDisplay.getWidth(); |
| 4847 | final int dh = mDisplay.getHeight(); |
| 4848 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4849 | if (dw < dh) { |
| 4850 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4851 | } else if (dw > dh) { |
| 4852 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4853 | } |
| 4854 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4855 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4856 | DisplayMetrics dm = new DisplayMetrics(); |
| 4857 | mDisplay.getMetrics(dm); |
| 4858 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4859 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4860 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4861 | // Note we only do this once because at this point we don't |
| 4862 | // expect the screen to change in this way at runtime, and want |
| 4863 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4864 | int longSize = dw; |
| 4865 | int shortSize = dh; |
| 4866 | if (longSize < shortSize) { |
| 4867 | int tmp = longSize; |
| 4868 | longSize = shortSize; |
| 4869 | shortSize = tmp; |
| 4870 | } |
| 4871 | longSize = (int)(longSize/dm.density); |
| 4872 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4873 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4874 | // These semi-magic numbers define our compatibility modes for |
| 4875 | // applications with different screens. Don't change unless you |
| 4876 | // make sure to test lots and lots of apps! |
| 4877 | if (longSize < 470) { |
| 4878 | // This is shorter than an HVGA normal density screen (which |
| 4879 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4880 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4881 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4882 | } else { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4883 | // Is this a large screen? |
| 4884 | if (longSize > 640 && shortSize >= 480) { |
| 4885 | // VGA or larger screens at medium density are the point |
| 4886 | // at which we consider it to be a large screen. |
| 4887 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4888 | } else { |
| 4889 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4890 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4891 | // If this screen is wider than normal HVGA, or taller |
| 4892 | // than FWVGA, then for old apps we want to run in size |
| 4893 | // compatibility mode. |
| 4894 | if (shortSize > 321 || longSize > 570) { |
| 4895 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4896 | } |
| 4897 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4898 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4899 | // Is this a long screen? |
| 4900 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4901 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4902 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4903 | } else { |
| 4904 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4905 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4906 | } |
| 4907 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4908 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4909 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4910 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4911 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4912 | mPolicy.adjustConfigurationLw(config); |
| 4913 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4914 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4916 | // ------------------------------------------------------------- |
| 4917 | // Input Events and Focus Management |
| 4918 | // ------------------------------------------------------------- |
| 4919 | |
| 4920 | private final void wakeupIfNeeded(WindowState targetWin, int eventType) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4921 | long curTime = SystemClock.uptimeMillis(); |
| 4922 | |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 4923 | if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 4924 | if (mLastTouchEventType == eventType && |
| 4925 | (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 4926 | return; |
| 4927 | } |
| 4928 | mLastUserActivityCallTime = curTime; |
| 4929 | mLastTouchEventType = eventType; |
| 4930 | } |
| 4931 | |
| 4932 | if (targetWin == null |
| 4933 | || targetWin.mAttrs.type != WindowManager.LayoutParams.TYPE_KEYGUARD) { |
| 4934 | mPowerManager.userActivity(curTime, false, eventType, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4935 | } |
| 4936 | } |
| 4937 | |
| 4938 | // tells if it's a cheek event or not -- this function is stateful |
| 4939 | private static final int EVENT_NONE = 0; |
| 4940 | private static final int EVENT_UNKNOWN = 0; |
| 4941 | private static final int EVENT_CHEEK = 0; |
| 4942 | private static final int EVENT_IGNORE_DURATION = 300; // ms |
| 4943 | private static final float CHEEK_THRESHOLD = 0.6f; |
| 4944 | private int mEventState = EVENT_NONE; |
| 4945 | private float mEventSize; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | private int eventType(MotionEvent ev) { |
| 4948 | float size = ev.getSize(); |
| 4949 | switch (ev.getAction()) { |
| 4950 | case MotionEvent.ACTION_DOWN: |
| 4951 | mEventSize = size; |
| 4952 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_EVENT; |
| 4953 | case MotionEvent.ACTION_UP: |
| 4954 | if (size > mEventSize) mEventSize = size; |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4955 | return (mEventSize > CHEEK_THRESHOLD) ? CHEEK_EVENT : TOUCH_UP_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4956 | case MotionEvent.ACTION_MOVE: |
| 4957 | final int N = ev.getHistorySize(); |
| 4958 | if (size > mEventSize) mEventSize = size; |
| 4959 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4960 | for (int i=0; i<N; i++) { |
| 4961 | size = ev.getHistoricalSize(i); |
| 4962 | if (size > mEventSize) mEventSize = size; |
| 4963 | if (mEventSize > CHEEK_THRESHOLD) return CHEEK_EVENT; |
| 4964 | } |
| 4965 | if (ev.getEventTime() < ev.getDownTime() + EVENT_IGNORE_DURATION) { |
| 4966 | return TOUCH_EVENT; |
| 4967 | } else { |
| Joe Onorato | e68ffcb | 2009-03-24 19:11:13 -0700 | [diff] [blame] | 4968 | return LONG_TOUCH_EVENT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4969 | } |
| 4970 | default: |
| 4971 | // not good |
| 4972 | return OTHER_EVENT; |
| 4973 | } |
| 4974 | } |
| 4975 | |
| 4976 | /** |
| 4977 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 4978 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4979 | private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4980 | if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4981 | "dispatchPointer " + ev); |
| 4982 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4983 | if (MEASURE_LATENCY) { |
| 4984 | lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); |
| 4985 | } |
| 4986 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4987 | Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 4988 | ev, true, false, pid, uid); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4989 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 4990 | if (MEASURE_LATENCY) { |
| 4991 | lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); |
| 4992 | } |
| 4993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4994 | int action = ev.getAction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4995 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4996 | if (action == MotionEvent.ACTION_UP) { |
| 4997 | // let go of our target |
| 4998 | mKeyWaiter.mMotionTarget = null; |
| 4999 | mPowerManager.logPointerUpEvent(); |
| 5000 | } else if (action == MotionEvent.ACTION_DOWN) { |
| 5001 | mPowerManager.logPointerDownEvent(); |
| 5002 | } |
| 5003 | |
| 5004 | if (targetObj == null) { |
| 5005 | // In this case we are either dropping the event, or have received |
| 5006 | // a move or up without a down. It is common to receive move |
| 5007 | // events in such a way, since this means the user is moving the |
| 5008 | // pointer without actually pressing down. All other cases should |
| 5009 | // be atypical, so let's log them. |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5010 | if (action != MotionEvent.ACTION_MOVE) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5011 | Slog.w(TAG, "No window to dispatch pointer action " + ev.getAction()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5012 | } |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5013 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5014 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5015 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5016 | if (qev != null) { |
| 5017 | mQueue.recycleEvent(qev); |
| 5018 | } |
| 5019 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5020 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5021 | } |
| 5022 | if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5023 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5024 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), true); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5025 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5026 | if (qev != null) { |
| 5027 | mQueue.recycleEvent(qev); |
| 5028 | } |
| 5029 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5030 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5031 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5032 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | WindowState target = (WindowState)targetObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5034 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5035 | final long eventTime = ev.getEventTime(); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5036 | final long eventTimeNano = ev.getEventTimeNano(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5037 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5038 | //Slog.i(TAG, "Sending " + ev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5039 | |
| 5040 | if (uid != 0 && uid != target.mSession.mUid) { |
| 5041 | if (mContext.checkPermission( |
| 5042 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5043 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5044 | Slog.w(TAG, "Permission denied: injecting pointer event from pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5045 | + pid + " uid " + uid + " to window " + target |
| 5046 | + " owned by uid " + target.mSession.mUid); |
| 5047 | if (qev != null) { |
| 5048 | mQueue.recycleEvent(qev); |
| 5049 | } |
| 5050 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5051 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5052 | } |
| 5053 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5054 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5055 | if (MEASURE_LATENCY) { |
| 5056 | lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5057 | } |
| 5058 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5059 | if ((target.mAttrs.flags & |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5060 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { |
| 5061 | //target wants to ignore fat touch events |
| 5062 | boolean cheekPress = mPolicy.isCheekPressedAgainstScreen(ev); |
| 5063 | //explicit flag to return without processing event further |
| 5064 | boolean returnFlag = false; |
| 5065 | if((action == MotionEvent.ACTION_DOWN)) { |
| 5066 | mFatTouch = false; |
| 5067 | if(cheekPress) { |
| 5068 | mFatTouch = true; |
| 5069 | returnFlag = true; |
| 5070 | } |
| 5071 | } else { |
| 5072 | if(action == MotionEvent.ACTION_UP) { |
| 5073 | if(mFatTouch) { |
| 5074 | //earlier even was invalid doesnt matter if current up is cheekpress or not |
| 5075 | mFatTouch = false; |
| 5076 | returnFlag = true; |
| 5077 | } else if(cheekPress) { |
| 5078 | //cancel the earlier event |
| 5079 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5080 | action = MotionEvent.ACTION_CANCEL; |
| 5081 | } |
| 5082 | } else if(action == MotionEvent.ACTION_MOVE) { |
| 5083 | if(mFatTouch) { |
| 5084 | //two cases here |
| 5085 | //an invalid down followed by 0 or moves(valid or invalid) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5086 | //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] | 5087 | returnFlag = true; |
| 5088 | } else if(cheekPress) { |
| 5089 | //valid down followed by invalid moves |
| 5090 | //an invalid move have to cancel earlier action |
| 5091 | ev.setAction(MotionEvent.ACTION_CANCEL); |
| 5092 | action = MotionEvent.ACTION_CANCEL; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5093 | if (DEBUG_INPUT) Slog.v(TAG, "Sending cancel for invalid ACTION_MOVE"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5094 | //note that the subsequent invalid moves will not get here |
| 5095 | mFatTouch = true; |
| 5096 | } |
| 5097 | } |
| 5098 | } //else if action |
| 5099 | if(returnFlag) { |
| 5100 | //recycle que, ev |
| 5101 | if (qev != null) { |
| 5102 | mQueue.recycleEvent(qev); |
| 5103 | } |
| 5104 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5105 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5106 | } |
| 5107 | } //end if target |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5108 | |
| Michael Chan | 9f028e6 | 2009-08-04 17:37:46 -0700 | [diff] [blame] | 5109 | // Enable this for testing the "right" value |
| 5110 | if (false && action == MotionEvent.ACTION_DOWN) { |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 5111 | int max_events_per_sec = 35; |
| 5112 | try { |
| 5113 | max_events_per_sec = Integer.parseInt(SystemProperties |
| 5114 | .get("windowsmgr.max_events_per_sec")); |
| 5115 | if (max_events_per_sec < 1) { |
| 5116 | max_events_per_sec = 35; |
| 5117 | } |
| 5118 | } catch (NumberFormatException e) { |
| 5119 | } |
| 5120 | mMinWaitTimeBetweenTouchEvents = 1000 / max_events_per_sec; |
| 5121 | } |
| 5122 | |
| 5123 | /* |
| 5124 | * Throttle events to minimize CPU usage when there's a flood of events |
| 5125 | * e.g. constant contact with the screen |
| 5126 | */ |
| 5127 | if (action == MotionEvent.ACTION_MOVE) { |
| 5128 | long nextEventTime = mLastTouchEventTime + mMinWaitTimeBetweenTouchEvents; |
| 5129 | long now = SystemClock.uptimeMillis(); |
| 5130 | if (now < nextEventTime) { |
| 5131 | try { |
| 5132 | Thread.sleep(nextEventTime - now); |
| 5133 | } catch (InterruptedException e) { |
| 5134 | } |
| 5135 | mLastTouchEventTime = nextEventTime; |
| 5136 | } else { |
| 5137 | mLastTouchEventTime = now; |
| 5138 | } |
| 5139 | } |
| 5140 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5141 | if (MEASURE_LATENCY) { |
| 5142 | lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); |
| 5143 | } |
| 5144 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5145 | synchronized(mWindowMap) { |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5146 | if (!target.isVisibleLw()) { |
| 5147 | // During this motion dispatch, the target window has become |
| 5148 | // invisible. |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5149 | dispatchPointerElsewhereLocked(null, null, ev, ev.getEventTime(), false); |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5150 | if (qev != null) { |
| 5151 | mQueue.recycleEvent(qev); |
| 5152 | } |
| 5153 | ev.recycle(); |
| 5154 | return INJECT_SUCCEEDED; |
| 5155 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5156 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5157 | if (qev != null && action == MotionEvent.ACTION_MOVE) { |
| 5158 | mKeyWaiter.bindTargetWindowLocked(target, |
| 5159 | KeyWaiter.RETURN_PENDING_POINTER, qev); |
| 5160 | ev = null; |
| 5161 | } else { |
| 5162 | if (action == MotionEvent.ACTION_DOWN) { |
| 5163 | WindowState out = mKeyWaiter.mOutsideTouchTargets; |
| 5164 | if (out != null) { |
| 5165 | MotionEvent oev = MotionEvent.obtain(ev); |
| 5166 | oev.setAction(MotionEvent.ACTION_OUTSIDE); |
| 5167 | do { |
| 5168 | final Rect frame = out.mFrame; |
| 5169 | oev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5170 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5171 | out.mClient.dispatchPointer(oev, eventTime, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5172 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5173 | Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5174 | } |
| 5175 | oev.offsetLocation((float)frame.left, (float)frame.top); |
| 5176 | out = out.mNextOutsideTouch; |
| 5177 | } while (out != null); |
| 5178 | mKeyWaiter.mOutsideTouchTargets = null; |
| 5179 | } |
| 5180 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5181 | |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 5182 | dispatchPointerElsewhereLocked(target, null, ev, ev.getEventTime(), false); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5183 | |
| Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 5184 | final Rect frame = target.mFrame; |
| 5185 | ev.offsetLocation(-(float)frame.left, -(float)frame.top); |
| 5186 | mKeyWaiter.bindTargetWindowLocked(target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5187 | } |
| 5188 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5190 | // finally offset the event to the target's coordinate system and |
| 5191 | // dispatch the event. |
| 5192 | try { |
| 5193 | if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5194 | Slog.v(TAG, "Delivering pointer " + qev + " to " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5195 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5196 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5197 | if (MEASURE_LATENCY) { |
| 5198 | lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5199 | } |
| 5200 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5201 | target.mClient.dispatchPointer(ev, eventTime, true); |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 5202 | |
| 5203 | if (MEASURE_LATENCY) { |
| 5204 | lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); |
| 5205 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5206 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5207 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5208 | Slog.i(TAG, "WINDOW DIED during motion dispatch: " + target); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5209 | mKeyWaiter.mMotionTarget = null; |
| 5210 | try { |
| 5211 | removeWindow(target.mSession, target.mClient); |
| 5212 | } catch (java.util.NoSuchElementException ex) { |
| 5213 | // This will happen if the window has already been |
| 5214 | // removed. |
| 5215 | } |
| 5216 | } |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5217 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5219 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5220 | /** |
| 5221 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5222 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5223 | private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5224 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5225 | TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5226 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5227 | Object focusObj = mKeyWaiter.waitForNextEventTarget(null, qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5228 | ev, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5230 | Slog.w(TAG, "No focus window, dropping trackball: " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5231 | if (qev != null) { |
| 5232 | mQueue.recycleEvent(qev); |
| 5233 | } |
| 5234 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5235 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5236 | } |
| 5237 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| 5238 | if (qev != null) { |
| 5239 | mQueue.recycleEvent(qev); |
| 5240 | } |
| 5241 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5242 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5243 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5245 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5247 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5248 | if (mContext.checkPermission( |
| 5249 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5250 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5251 | Slog.w(TAG, "Permission denied: injecting key event from pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5252 | + pid + " uid " + uid + " to window " + focus |
| 5253 | + " owned by uid " + focus.mSession.mUid); |
| 5254 | if (qev != null) { |
| 5255 | mQueue.recycleEvent(qev); |
| 5256 | } |
| 5257 | ev.recycle(); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5258 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5259 | } |
| 5260 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | final long eventTime = ev.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5263 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5264 | synchronized(mWindowMap) { |
| 5265 | if (qev != null && ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 5266 | mKeyWaiter.bindTargetWindowLocked(focus, |
| 5267 | KeyWaiter.RETURN_PENDING_TRACKBALL, qev); |
| 5268 | // We don't deliver movement events to the client, we hold |
| 5269 | // them and wait for them to call back. |
| 5270 | ev = null; |
| 5271 | } else { |
| 5272 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5273 | } |
| 5274 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5276 | try { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 5277 | focus.mClient.dispatchTrackball(ev, eventTime, true); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5278 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5280 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | try { |
| 5282 | removeWindow(focus.mSession, focus.mClient); |
| 5283 | } catch (java.util.NoSuchElementException ex) { |
| 5284 | // This will happen if the window has already been |
| 5285 | // removed. |
| 5286 | } |
| 5287 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5288 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5289 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5290 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5292 | /** |
| 5293 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5294 | */ |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5295 | private int dispatchKey(KeyEvent event, int pid, int uid) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5296 | if (DEBUG_INPUT) Slog.v(TAG, "Dispatch key: " + event); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5297 | |
| 5298 | Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5299 | null, false, false, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5300 | if (focusObj == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5301 | Slog.w(TAG, "No focus window, dropping: " + event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5302 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5303 | } |
| 5304 | if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5305 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5306 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5307 | |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5308 | // Okay we have finished waiting for the last event to be processed. |
| 5309 | // First off, if this is a repeat event, check to see if there is |
| 5310 | // a corresponding up event in the queue. If there is, we will |
| 5311 | // just drop the repeat, because it makes no sense to repeat after |
| 5312 | // the user has released a key. (This is especially important for |
| 5313 | // long presses.) |
| 5314 | if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) { |
| 5315 | return INJECT_SUCCEEDED; |
| 5316 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5318 | WindowState focus = (WindowState)focusObj; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5319 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5320 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5321 | TAG, "Dispatching to " + focus + ": " + event); |
| 5322 | |
| 5323 | if (uid != 0 && uid != focus.mSession.mUid) { |
| 5324 | if (mContext.checkPermission( |
| 5325 | android.Manifest.permission.INJECT_EVENTS, pid, uid) |
| 5326 | != PackageManager.PERMISSION_GRANTED) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5327 | Slog.w(TAG, "Permission denied: injecting key event from pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5328 | + pid + " uid " + uid + " to window " + focus |
| 5329 | + " owned by uid " + focus.mSession.mUid); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5330 | return INJECT_NO_PERMISSION; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | } |
| 5332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5334 | synchronized(mWindowMap) { |
| 5335 | mKeyWaiter.bindTargetWindowLocked(focus); |
| 5336 | } |
| 5337 | |
| 5338 | // NOSHIP extra state logging |
| 5339 | mKeyWaiter.recordDispatchState(event, focus); |
| 5340 | // END NOSHIP |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | try { |
| 5343 | if (DEBUG_INPUT || DEBUG_FOCUS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5344 | Slog.v(TAG, "Delivering key " + event.getKeyCode() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5345 | + " to " + focus); |
| 5346 | } |
| 5347 | focus.mClient.dispatchKey(event); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5348 | return INJECT_SUCCEEDED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5349 | } catch (android.os.RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5350 | Slog.i(TAG, "WINDOW DIED during key dispatch: " + focus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | try { |
| 5352 | removeWindow(focus.mSession, focus.mClient); |
| 5353 | } catch (java.util.NoSuchElementException ex) { |
| 5354 | // This will happen if the window has already been |
| 5355 | // removed. |
| 5356 | } |
| 5357 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5358 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5359 | return INJECT_FAILED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5360 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5361 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5362 | public void pauseKeyDispatching(IBinder _token) { |
| 5363 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5364 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5365 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | synchronized (mWindowMap) { |
| 5369 | WindowToken token = mTokenMap.get(_token); |
| 5370 | if (token != null) { |
| 5371 | mKeyWaiter.pauseDispatchingLocked(token); |
| 5372 | } |
| 5373 | } |
| 5374 | } |
| 5375 | |
| 5376 | public void resumeKeyDispatching(IBinder _token) { |
| 5377 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5378 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5379 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | synchronized (mWindowMap) { |
| 5383 | WindowToken token = mTokenMap.get(_token); |
| 5384 | if (token != null) { |
| 5385 | mKeyWaiter.resumeDispatchingLocked(token); |
| 5386 | } |
| 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | public void setEventDispatching(boolean enabled) { |
| 5391 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5392 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5393 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | synchronized (mWindowMap) { |
| 5397 | mKeyWaiter.setEventDispatchingLocked(enabled); |
| 5398 | } |
| 5399 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5401 | /** |
| 5402 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5403 | * |
| 5404 | * @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] | 5405 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5406 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5407 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5408 | */ |
| 5409 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5410 | long downTime = ev.getDownTime(); |
| 5411 | long eventTime = ev.getEventTime(); |
| 5412 | |
| 5413 | int action = ev.getAction(); |
| 5414 | int code = ev.getKeyCode(); |
| 5415 | int repeatCount = ev.getRepeatCount(); |
| 5416 | int metaState = ev.getMetaState(); |
| 5417 | int deviceId = ev.getDeviceId(); |
| 5418 | int scancode = ev.getScanCode(); |
| 5419 | |
| 5420 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5421 | if (downTime == 0) downTime = eventTime; |
| 5422 | |
| 5423 | 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] | 5424 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5425 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5426 | final int pid = Binder.getCallingPid(); |
| 5427 | final int uid = Binder.getCallingUid(); |
| 5428 | final long ident = Binder.clearCallingIdentity(); |
| 5429 | final int result = dispatchKey(newEvent, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5430 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5431 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5433 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5434 | switch (result) { |
| 5435 | case INJECT_NO_PERMISSION: |
| 5436 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5437 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5438 | case INJECT_SUCCEEDED: |
| 5439 | return true; |
| 5440 | } |
| 5441 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | /** |
| 5445 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5446 | * |
| 5447 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5448 | * {@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] | 5449 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5450 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5451 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5452 | */ |
| 5453 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5454 | final int pid = Binder.getCallingPid(); |
| 5455 | final int uid = Binder.getCallingUid(); |
| 5456 | final long ident = Binder.clearCallingIdentity(); |
| 5457 | final int result = dispatchPointer(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5458 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5459 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5460 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5461 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5462 | switch (result) { |
| 5463 | case INJECT_NO_PERMISSION: |
| 5464 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5465 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5466 | case INJECT_SUCCEEDED: |
| 5467 | return true; |
| 5468 | } |
| 5469 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5470 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5472 | /** |
| 5473 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5474 | * |
| 5475 | * @param ev A motion event describing the trackball action. (As noted in |
| 5476 | * {@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] | 5477 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5478 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5479 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5480 | */ |
| 5481 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5482 | final int pid = Binder.getCallingPid(); |
| 5483 | final int uid = Binder.getCallingUid(); |
| 5484 | final long ident = Binder.clearCallingIdentity(); |
| 5485 | final int result = dispatchTrackball(null, ev, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5486 | if (sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5487 | mKeyWaiter.waitForNextEventTarget(null, null, null, false, true, pid, uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5488 | } |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5489 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5490 | switch (result) { |
| 5491 | case INJECT_NO_PERMISSION: |
| 5492 | throw new SecurityException( |
| Chander S Pechetty | 27f3de6 | 2010-02-10 22:14:00 +0530 | [diff] [blame] | 5493 | "Injecting to another application requires INJECT_EVENTS permission"); |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5494 | case INJECT_SUCCEEDED: |
| 5495 | return true; |
| 5496 | } |
| 5497 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5498 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5499 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5500 | private WindowState getFocusedWindow() { |
| 5501 | synchronized (mWindowMap) { |
| 5502 | return getFocusedWindowLocked(); |
| 5503 | } |
| 5504 | } |
| 5505 | |
| 5506 | private WindowState getFocusedWindowLocked() { |
| 5507 | return mCurrentFocus; |
| 5508 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5510 | /** |
| 5511 | * This class holds the state for dispatching key events. This state |
| 5512 | * is protected by the KeyWaiter instance, NOT by the window lock. You |
| 5513 | * can be holding the main window lock while acquire the KeyWaiter lock, |
| 5514 | * but not the other way around. |
| 5515 | */ |
| 5516 | final class KeyWaiter { |
| 5517 | // NOSHIP debugging |
| 5518 | public class DispatchState { |
| 5519 | private KeyEvent event; |
| 5520 | private WindowState focus; |
| 5521 | private long time; |
| 5522 | private WindowState lastWin; |
| 5523 | private IBinder lastBinder; |
| 5524 | private boolean finished; |
| 5525 | private boolean gotFirstWindow; |
| 5526 | private boolean eventDispatching; |
| 5527 | private long timeToSwitch; |
| 5528 | private boolean wasFrozen; |
| 5529 | private boolean focusPaused; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5530 | private WindowState curFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | DispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5533 | focus = theFocus; |
| 5534 | event = theEvent; |
| 5535 | time = System.currentTimeMillis(); |
| 5536 | // snapshot KeyWaiter state |
| 5537 | lastWin = mLastWin; |
| 5538 | lastBinder = mLastBinder; |
| 5539 | finished = mFinished; |
| 5540 | gotFirstWindow = mGotFirstWindow; |
| 5541 | eventDispatching = mEventDispatching; |
| 5542 | timeToSwitch = mTimeToSwitch; |
| 5543 | wasFrozen = mWasFrozen; |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5544 | curFocus = mCurrentFocus; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | // cache the paused state at ctor time as well |
| 5546 | if (theFocus == null || theFocus.mToken == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5547 | focusPaused = false; |
| 5548 | } else { |
| 5549 | focusPaused = theFocus.mToken.paused; |
| 5550 | } |
| 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 | public String toString() { |
| 5554 | return "{{" + event + " to " + focus + " @ " + time |
| 5555 | + " lw=" + lastWin + " lb=" + lastBinder |
| 5556 | + " fin=" + finished + " gfw=" + gotFirstWindow |
| 5557 | + " ed=" + eventDispatching + " tts=" + timeToSwitch |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5558 | + " wf=" + wasFrozen + " fp=" + focusPaused |
| Christopher Tate | 46d4525 | 2010-02-09 15:48:57 -0800 | [diff] [blame] | 5559 | + " mcf=" + curFocus + "}}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5560 | } |
| 5561 | }; |
| 5562 | private DispatchState mDispatchState = null; |
| 5563 | public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) { |
| 5564 | mDispatchState = new DispatchState(theEvent, theFocus); |
| 5565 | } |
| 5566 | // END NOSHIP |
| 5567 | |
| 5568 | public static final int RETURN_NOTHING = 0; |
| 5569 | public static final int RETURN_PENDING_POINTER = 1; |
| 5570 | public static final int RETURN_PENDING_TRACKBALL = 2; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5572 | final Object SKIP_TARGET_TOKEN = new Object(); |
| 5573 | final Object CONSUMED_EVENT_TOKEN = new Object(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | private WindowState mLastWin = null; |
| 5576 | private IBinder mLastBinder = null; |
| 5577 | private boolean mFinished = true; |
| 5578 | private boolean mGotFirstWindow = false; |
| 5579 | private boolean mEventDispatching = true; |
| 5580 | private long mTimeToSwitch = 0; |
| 5581 | /* package */ boolean mWasFrozen = false; |
| 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 | // Target of Motion events |
| 5584 | WindowState mMotionTarget; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5585 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5586 | // Windows above the target who would like to receive an "outside" |
| 5587 | // touch event for any down events outside of them. |
| 5588 | WindowState mOutsideTouchTargets; |
| 5589 | |
| 5590 | /** |
| 5591 | * Wait for the last event dispatch to complete, then find the next |
| 5592 | * target that should receive the given event and wait for that one |
| 5593 | * to be ready to receive it. |
| 5594 | */ |
| 5595 | Object waitForNextEventTarget(KeyEvent nextKey, QueuedEvent qev, |
| 5596 | MotionEvent nextMotion, boolean isPointerEvent, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5597 | boolean failIfTimeout, int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5598 | long startTime = SystemClock.uptimeMillis(); |
| 5599 | long keyDispatchingTimeout = 5 * 1000; |
| 5600 | long waitedFor = 0; |
| 5601 | |
| 5602 | while (true) { |
| 5603 | // Figure out which window we care about. It is either the |
| 5604 | // last window we are waiting to have process the event or, |
| 5605 | // if none, then the next window we think the event should go |
| 5606 | // to. Note: we retrieve mLastWin outside of the lock, so |
| 5607 | // it may change before we lock. Thus we must check it again. |
| 5608 | WindowState targetWin = mLastWin; |
| 5609 | boolean targetIsNew = targetWin == null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5610 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5611 | TAG, "waitForLastKey: mFinished=" + mFinished + |
| 5612 | ", mLastWin=" + mLastWin); |
| 5613 | if (targetIsNew) { |
| 5614 | Object target = findTargetWindow(nextKey, qev, nextMotion, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5615 | isPointerEvent, callingPid, callingUid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5616 | if (target == SKIP_TARGET_TOKEN) { |
| 5617 | // The user has pressed a special key, and we are |
| 5618 | // dropping all pending events before it. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5619 | if (DEBUG_INPUT) Slog.v(TAG, "Skipping: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5620 | + " " + nextMotion); |
| 5621 | return null; |
| 5622 | } |
| 5623 | if (target == CONSUMED_EVENT_TOKEN) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5624 | if (DEBUG_INPUT) Slog.v(TAG, "Consumed: " + nextKey |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5625 | + " " + nextMotion); |
| 5626 | return target; |
| 5627 | } |
| 5628 | targetWin = (WindowState)target; |
| 5629 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5630 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | AppWindowToken targetApp = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | // Now: is it okay to send the next event to this window? |
| 5634 | synchronized (this) { |
| 5635 | // First: did we come here based on the last window not |
| 5636 | // being null, but it changed by the time we got here? |
| 5637 | // If so, try again. |
| 5638 | if (!targetIsNew && mLastWin == null) { |
| 5639 | continue; |
| 5640 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5641 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5642 | // We never dispatch events if not finished with the |
| 5643 | // last one, or the display is frozen. |
| 5644 | if (mFinished && !mDisplayFrozen) { |
| 5645 | // If event dispatching is disabled, then we |
| 5646 | // just consume the events. |
| 5647 | if (!mEventDispatching) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5648 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | "Skipping event; dispatching disabled: " |
| 5650 | + nextKey + " " + nextMotion); |
| 5651 | return null; |
| 5652 | } |
| 5653 | if (targetWin != null) { |
| 5654 | // If this is a new target, and that target is not |
| 5655 | // paused or unresponsive, then all looks good to |
| 5656 | // handle the event. |
| 5657 | if (targetIsNew && !targetWin.mToken.paused) { |
| 5658 | return targetWin; |
| 5659 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5660 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | // If we didn't find a target window, and there is no |
| 5662 | // focused app window, then just eat the events. |
| 5663 | } else if (mFocusedApp == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5664 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | "Skipping event; no focused app: " |
| 5666 | + nextKey + " " + nextMotion); |
| 5667 | return null; |
| 5668 | } |
| 5669 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5670 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5671 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5672 | TAG, "Waiting for last key in " + mLastBinder |
| 5673 | + " target=" + targetWin |
| 5674 | + " mFinished=" + mFinished |
| 5675 | + " mDisplayFrozen=" + mDisplayFrozen |
| 5676 | + " targetIsNew=" + targetIsNew |
| 5677 | + " paused=" |
| 5678 | + (targetWin != null ? targetWin.mToken.paused : false) |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5679 | + " mFocusedApp=" + mFocusedApp |
| 5680 | + " mCurrentFocus=" + mCurrentFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5681 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5682 | targetApp = targetWin != null |
| 5683 | ? targetWin.mAppToken : mFocusedApp; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | long curTimeout = keyDispatchingTimeout; |
| 5686 | if (mTimeToSwitch != 0) { |
| 5687 | long now = SystemClock.uptimeMillis(); |
| 5688 | if (mTimeToSwitch <= now) { |
| 5689 | // If an app switch key has been pressed, and we have |
| 5690 | // waited too long for the current app to finish |
| 5691 | // processing keys, then wait no more! |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 5692 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5693 | continue; |
| 5694 | } |
| 5695 | long switchTimeout = mTimeToSwitch - now; |
| 5696 | if (curTimeout > switchTimeout) { |
| 5697 | curTimeout = switchTimeout; |
| 5698 | } |
| 5699 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5700 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5701 | try { |
| 5702 | // after that continue |
| 5703 | // processing keys, so we don't get stuck. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5704 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5705 | TAG, "Waiting for key dispatch: " + curTimeout); |
| 5706 | wait(curTimeout); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5707 | if (DEBUG_INPUT) Slog.v(TAG, "Finished waiting @" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5708 | + SystemClock.uptimeMillis() + " startTime=" |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 5709 | + startTime + " switchTime=" + mTimeToSwitch |
| 5710 | + " target=" + targetWin + " mLW=" + mLastWin |
| 5711 | + " mLB=" + mLastBinder + " fin=" + mFinished |
| 5712 | + " mCurrentFocus=" + mCurrentFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5713 | } catch (InterruptedException e) { |
| 5714 | } |
| 5715 | } |
| 5716 | |
| 5717 | // If we were frozen during configuration change, restart the |
| 5718 | // timeout checks from now; otherwise look at whether we timed |
| 5719 | // out before awakening. |
| 5720 | if (mWasFrozen) { |
| 5721 | waitedFor = 0; |
| 5722 | mWasFrozen = false; |
| 5723 | } else { |
| 5724 | waitedFor = SystemClock.uptimeMillis() - startTime; |
| 5725 | } |
| 5726 | |
| 5727 | if (waitedFor >= keyDispatchingTimeout && mTimeToSwitch == 0) { |
| 5728 | IApplicationToken at = null; |
| 5729 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5730 | Slog.w(TAG, "Key dispatching timed out sending to " + |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5731 | (targetWin != null ? targetWin.mAttrs.getTitle() |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 5732 | : "<null>: no window ready for key dispatch")); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5733 | // NOSHIP debugging |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5734 | Slog.w(TAG, "Previous dispatch state: " + mDispatchState); |
| 5735 | Slog.w(TAG, "Current dispatch state: " + |
| Ken Shirriff | 8200b20 | 2010-02-04 13:34:37 -0800 | [diff] [blame] | 5736 | new DispatchState(nextKey, targetWin)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5737 | // END NOSHIP |
| 5738 | //dump(); |
| 5739 | if (targetWin != null) { |
| 5740 | at = targetWin.getAppToken(); |
| 5741 | } else if (targetApp != null) { |
| 5742 | at = targetApp.appToken; |
| 5743 | } |
| 5744 | } |
| 5745 | |
| 5746 | boolean abort = true; |
| 5747 | if (at != null) { |
| 5748 | try { |
| 5749 | long timeout = at.getKeyDispatchingTimeout(); |
| 5750 | if (timeout > waitedFor) { |
| 5751 | // we did not wait the proper amount of time for this application. |
| 5752 | // set the timeout to be the real timeout and wait again. |
| 5753 | keyDispatchingTimeout = timeout - waitedFor; |
| 5754 | continue; |
| 5755 | } else { |
| 5756 | abort = at.keyDispatchingTimedOut(); |
| 5757 | } |
| 5758 | } catch (RemoteException ex) { |
| 5759 | } |
| 5760 | } |
| 5761 | |
| 5762 | synchronized (this) { |
| 5763 | if (abort && (mLastWin == targetWin || targetWin == null)) { |
| 5764 | mFinished = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5765 | if (mLastWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5766 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5767 | "Window " + mLastWin + |
| 5768 | " timed out on key input"); |
| 5769 | if (mLastWin.mToken.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5770 | Slog.w(TAG, "Un-pausing dispatching to this window"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | mLastWin.mToken.paused = false; |
| 5772 | } |
| 5773 | } |
| 5774 | if (mMotionTarget == targetWin) { |
| 5775 | mMotionTarget = null; |
| 5776 | } |
| 5777 | mLastWin = null; |
| 5778 | mLastBinder = null; |
| 5779 | if (failIfTimeout || targetWin == null) { |
| 5780 | return null; |
| 5781 | } |
| 5782 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5783 | Slog.w(TAG, "Continuing to wait for key to be dispatched"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5784 | startTime = SystemClock.uptimeMillis(); |
| 5785 | } |
| 5786 | } |
| 5787 | } |
| 5788 | } |
| 5789 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5790 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | Object findTargetWindow(KeyEvent nextKey, QueuedEvent qev, |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5792 | MotionEvent nextMotion, boolean isPointerEvent, |
| 5793 | int callingPid, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | mOutsideTouchTargets = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5795 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5796 | if (nextKey != null) { |
| 5797 | // Find the target window for a normal key event. |
| 5798 | final int keycode = nextKey.getKeyCode(); |
| 5799 | final int repeatCount = nextKey.getRepeatCount(); |
| 5800 | final boolean down = nextKey.getAction() != KeyEvent.ACTION_UP; |
| 5801 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(keycode); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5802 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | if (!dispatch) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5804 | if (callingUid == 0 || |
| 5805 | mContext.checkPermission( |
| 5806 | android.Manifest.permission.INJECT_EVENTS, |
| 5807 | callingPid, callingUid) |
| 5808 | == PackageManager.PERMISSION_GRANTED) { |
| 5809 | mPolicy.interceptKeyTi(null, keycode, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5810 | nextKey.getMetaState(), down, repeatCount, |
| 5811 | nextKey.getFlags()); |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5812 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5813 | Slog.w(TAG, "Event timeout during app switch: dropping " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5814 | + nextKey); |
| 5815 | return SKIP_TARGET_TOKEN; |
| 5816 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | // System.out.println("##### [" + SystemClock.uptimeMillis() + "] WindowManagerService.dispatchKey(" + keycode + ", " + down + ", " + repeatCount + ")"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5819 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | WindowState focus = null; |
| 5821 | synchronized(mWindowMap) { |
| 5822 | focus = getFocusedWindowLocked(); |
| 5823 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5824 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5826 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5827 | if (callingUid == 0 || |
| 5828 | (focus != null && callingUid == focus.mSession.mUid) || |
| 5829 | mContext.checkPermission( |
| 5830 | android.Manifest.permission.INJECT_EVENTS, |
| 5831 | callingPid, callingUid) |
| 5832 | == PackageManager.PERMISSION_GRANTED) { |
| 5833 | if (mPolicy.interceptKeyTi(focus, |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5834 | keycode, nextKey.getMetaState(), down, repeatCount, |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 5835 | nextKey.getFlags())) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5836 | return CONSUMED_EVENT_TOKEN; |
| 5837 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5838 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5840 | return focus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5841 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5842 | } else if (!isPointerEvent) { |
| 5843 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey(-1); |
| 5844 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5845 | Slog.w(TAG, "Event timeout during app switch: dropping trackball " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5846 | + nextMotion); |
| 5847 | return SKIP_TARGET_TOKEN; |
| 5848 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5850 | WindowState focus = null; |
| 5851 | synchronized(mWindowMap) { |
| 5852 | focus = getFocusedWindowLocked(); |
| 5853 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5854 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | wakeupIfNeeded(focus, LocalPowerManager.BUTTON_EVENT); |
| 5856 | return focus; |
| 5857 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5859 | if (nextMotion == null) { |
| 5860 | return SKIP_TARGET_TOKEN; |
| 5861 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5862 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5863 | boolean dispatch = mKeyWaiter.checkShouldDispatchKey( |
| 5864 | KeyEvent.KEYCODE_UNKNOWN); |
| 5865 | if (!dispatch) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5866 | Slog.w(TAG, "Event timeout during app switch: dropping pointer " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5867 | + nextMotion); |
| 5868 | return SKIP_TARGET_TOKEN; |
| 5869 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5870 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5871 | // Find the target window for a pointer event. |
| 5872 | int action = nextMotion.getAction(); |
| 5873 | final float xf = nextMotion.getX(); |
| 5874 | final float yf = nextMotion.getY(); |
| 5875 | final long eventTime = nextMotion.getEventTime(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5876 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5877 | final boolean screenWasOff = qev != null |
| 5878 | && (qev.flags&WindowManagerPolicy.FLAG_BRIGHT_HERE) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5879 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5880 | WindowState target = null; |
| 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 | synchronized(mWindowMap) { |
| 5883 | synchronized (this) { |
| 5884 | if (action == MotionEvent.ACTION_DOWN) { |
| 5885 | if (mMotionTarget != null) { |
| 5886 | // this is weird, we got a pen down, but we thought it was |
| 5887 | // already down! |
| 5888 | // XXX: We should probably send an ACTION_UP to the current |
| 5889 | // target. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5890 | Slog.w(TAG, "Pointer down received while already down in: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5891 | + mMotionTarget); |
| 5892 | mMotionTarget = null; |
| 5893 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5894 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5895 | // ACTION_DOWN is special, because we need to lock next events to |
| 5896 | // the window we'll land onto. |
| 5897 | final int x = (int)xf; |
| 5898 | final int y = (int)yf; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5900 | final ArrayList windows = mWindows; |
| 5901 | final int N = windows.size(); |
| 5902 | WindowState topErrWindow = null; |
| 5903 | final Rect tmpRect = mTempRect; |
| 5904 | for (int i=N-1; i>=0; i--) { |
| 5905 | WindowState child = (WindowState)windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5906 | //Slog.i(TAG, "Checking dispatch to: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5907 | final int flags = child.mAttrs.flags; |
| 5908 | if ((flags & WindowManager.LayoutParams.FLAG_SYSTEM_ERROR) != 0) { |
| 5909 | if (topErrWindow == null) { |
| 5910 | topErrWindow = child; |
| 5911 | } |
| 5912 | } |
| 5913 | if (!child.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5914 | //Slog.i(TAG, "Not visible!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5915 | continue; |
| 5916 | } |
| 5917 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5918 | //Slog.i(TAG, "Not touchable!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5919 | if ((flags & WindowManager.LayoutParams |
| 5920 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5921 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5922 | mOutsideTouchTargets = child; |
| 5923 | } |
| 5924 | continue; |
| 5925 | } |
| 5926 | tmpRect.set(child.mFrame); |
| 5927 | if (child.mTouchableInsets == ViewTreeObserver |
| 5928 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 5929 | // The touch is inside of the window if it is |
| 5930 | // inside the frame, AND the content part of that |
| 5931 | // frame that was given by the application. |
| 5932 | tmpRect.left += child.mGivenContentInsets.left; |
| 5933 | tmpRect.top += child.mGivenContentInsets.top; |
| 5934 | tmpRect.right -= child.mGivenContentInsets.right; |
| 5935 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 5936 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 5937 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 5938 | // The touch is inside of the window if it is |
| 5939 | // inside the frame, AND the visible part of that |
| 5940 | // frame that was given by the application. |
| 5941 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 5942 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 5943 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 5944 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 5945 | } |
| 5946 | final int touchFlags = flags & |
| 5947 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 5948 | |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 5949 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5950 | //Slog.i(TAG, "Using this target!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | if (!screenWasOff || (flags & |
| 5952 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING) != 0) { |
| 5953 | mMotionTarget = child; |
| 5954 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5955 | //Slog.i(TAG, "Waking, skip!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5956 | mMotionTarget = null; |
| 5957 | } |
| 5958 | break; |
| 5959 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5960 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5961 | if ((flags & WindowManager.LayoutParams |
| 5962 | .FLAG_WATCH_OUTSIDE_TOUCH) != 0) { |
| 5963 | child.mNextOutsideTouch = mOutsideTouchTargets; |
| 5964 | mOutsideTouchTargets = child; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5965 | //Slog.i(TAG, "Adding to outside target list: " + child); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5966 | } |
| 5967 | } |
| 5968 | |
| 5969 | // if there's an error window but it's not accepting |
| 5970 | // focus (typically because it is not yet visible) just |
| 5971 | // wait for it -- any other focused window may in fact |
| 5972 | // be in ANR state. |
| 5973 | if (topErrWindow != null && mMotionTarget != topErrWindow) { |
| 5974 | mMotionTarget = null; |
| 5975 | } |
| 5976 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5978 | target = mMotionTarget; |
| 5979 | } |
| 5980 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5981 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5982 | wakeupIfNeeded(target, eventType(nextMotion)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5983 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5984 | // Pointer events are a little different -- if there isn't a |
| 5985 | // target found for any event, then just drop it. |
| 5986 | return target != null ? target : SKIP_TARGET_TOKEN; |
| 5987 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5988 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5989 | boolean checkShouldDispatchKey(int keycode) { |
| 5990 | synchronized (this) { |
| 5991 | if (mPolicy.isAppSwitchKeyTqTiLwLi(keycode)) { |
| 5992 | mTimeToSwitch = 0; |
| 5993 | return true; |
| 5994 | } |
| 5995 | if (mTimeToSwitch != 0 |
| 5996 | && mTimeToSwitch < SystemClock.uptimeMillis()) { |
| 5997 | return false; |
| 5998 | } |
| 5999 | return true; |
| 6000 | } |
| 6001 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6002 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | void bindTargetWindowLocked(WindowState win, |
| 6004 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6005 | synchronized (this) { |
| 6006 | bindTargetWindowLockedLocked(win, pendingWhat, pendingMotion); |
| 6007 | } |
| 6008 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6009 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6010 | void bindTargetWindowLocked(WindowState win) { |
| 6011 | synchronized (this) { |
| 6012 | bindTargetWindowLockedLocked(win, RETURN_NOTHING, null); |
| 6013 | } |
| 6014 | } |
| 6015 | |
| 6016 | void bindTargetWindowLockedLocked(WindowState win, |
| 6017 | int pendingWhat, QueuedEvent pendingMotion) { |
| 6018 | mLastWin = win; |
| 6019 | mLastBinder = win.mClient.asBinder(); |
| 6020 | mFinished = false; |
| 6021 | if (pendingMotion != null) { |
| 6022 | final Session s = win.mSession; |
| 6023 | if (pendingWhat == RETURN_PENDING_POINTER) { |
| 6024 | releasePendingPointerLocked(s); |
| 6025 | s.mPendingPointerMove = pendingMotion; |
| 6026 | s.mPendingPointerWindow = win; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6027 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | "bindTargetToWindow " + s.mPendingPointerMove); |
| 6029 | } else if (pendingWhat == RETURN_PENDING_TRACKBALL) { |
| 6030 | releasePendingTrackballLocked(s); |
| 6031 | s.mPendingTrackballMove = pendingMotion; |
| 6032 | s.mPendingTrackballWindow = win; |
| 6033 | } |
| 6034 | } |
| 6035 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6037 | void releasePendingPointerLocked(Session s) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6038 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | "releasePendingPointer " + s.mPendingPointerMove); |
| 6040 | if (s.mPendingPointerMove != null) { |
| 6041 | mQueue.recycleEvent(s.mPendingPointerMove); |
| 6042 | s.mPendingPointerMove = null; |
| 6043 | } |
| 6044 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6046 | void releasePendingTrackballLocked(Session s) { |
| 6047 | if (s.mPendingTrackballMove != null) { |
| 6048 | mQueue.recycleEvent(s.mPendingTrackballMove); |
| 6049 | s.mPendingTrackballMove = null; |
| 6050 | } |
| 6051 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6052 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6053 | MotionEvent finishedKey(Session session, IWindow client, boolean force, |
| 6054 | int returnWhat) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6055 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6056 | TAG, "finishedKey: client=" + client + ", force=" + force); |
| 6057 | |
| 6058 | if (client == null) { |
| 6059 | return null; |
| 6060 | } |
| 6061 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6062 | MotionEvent res = null; |
| 6063 | QueuedEvent qev = null; |
| 6064 | WindowState win = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6065 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6067 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6068 | TAG, "finishedKey: client=" + client.asBinder() |
| 6069 | + ", force=" + force + ", last=" + mLastBinder |
| 6070 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) + ")"); |
| 6071 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6072 | if (returnWhat == RETURN_PENDING_POINTER) { |
| 6073 | qev = session.mPendingPointerMove; |
| 6074 | win = session.mPendingPointerWindow; |
| 6075 | session.mPendingPointerMove = null; |
| 6076 | session.mPendingPointerWindow = null; |
| 6077 | } else if (returnWhat == RETURN_PENDING_TRACKBALL) { |
| 6078 | qev = session.mPendingTrackballMove; |
| 6079 | win = session.mPendingTrackballWindow; |
| 6080 | session.mPendingTrackballMove = null; |
| 6081 | session.mPendingTrackballWindow = null; |
| 6082 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6083 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6084 | if (mLastBinder == client.asBinder()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6085 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6086 | TAG, "finishedKey: last paused=" |
| 6087 | + ((mLastWin != null) ? mLastWin.mToken.paused : "null")); |
| 6088 | if (mLastWin != null && (!mLastWin.mToken.paused || force |
| 6089 | || !mEventDispatching)) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6090 | doFinishedKeyLocked(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6091 | } else { |
| 6092 | // Make sure to wake up anyone currently waiting to |
| 6093 | // dispatch a key, so they can re-evaluate their |
| 6094 | // current situation. |
| 6095 | mFinished = true; |
| 6096 | notifyAll(); |
| 6097 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6098 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6099 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | if (qev != null) { |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6101 | res = (MotionEvent)qev.event; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6102 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6103 | "Returning pending motion: " + res); |
| 6104 | mQueue.recycleEvent(qev); |
| 6105 | if (win != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6106 | res.offsetLocation(-win.mFrame.left, -win.mFrame.top); |
| 6107 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6108 | } |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6109 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6110 | |
| Christopher Tate | 2624fbc | 2009-12-11 12:11:31 -0800 | [diff] [blame] | 6111 | if (res != null && returnWhat == RETURN_PENDING_POINTER) { |
| 6112 | synchronized (mWindowMap) { |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 6113 | dispatchPointerElsewhereLocked(win, win, res, res.getEventTime(), false); |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6114 | } |
| 6115 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6116 | |
| Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 6117 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6118 | } |
| 6119 | |
| 6120 | void tickle() { |
| 6121 | synchronized (this) { |
| 6122 | notifyAll(); |
| 6123 | } |
| 6124 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6125 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6126 | void handleNewWindowLocked(WindowState newWindow) { |
| 6127 | if (!newWindow.canReceiveKeys()) { |
| 6128 | return; |
| 6129 | } |
| 6130 | synchronized (this) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6131 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6132 | TAG, "New key dispatch window: win=" |
| 6133 | + newWindow.mClient.asBinder() |
| 6134 | + ", last=" + mLastBinder |
| 6135 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6136 | + "), finished=" + mFinished + ", paused=" |
| 6137 | + newWindow.mToken.paused); |
| 6138 | |
| 6139 | // Displaying a window implicitly causes dispatching to |
| 6140 | // be unpaused. (This is to protect against bugs if someone |
| 6141 | // pauses dispatching but forgets to resume.) |
| 6142 | newWindow.mToken.paused = false; |
| 6143 | |
| 6144 | mGotFirstWindow = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6145 | |
| 6146 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6147 | if (DEBUG_INPUT) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6148 | "New SYSTEM_ERROR window; resetting state"); |
| 6149 | mLastWin = null; |
| 6150 | mLastBinder = null; |
| 6151 | mMotionTarget = null; |
| 6152 | mFinished = true; |
| 6153 | } else if (mLastWin != null) { |
| 6154 | // If the new window is above the window we are |
| 6155 | // waiting on, then stop waiting and let key dispatching |
| 6156 | // start on the new guy. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6157 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6158 | TAG, "Last win layer=" + mLastWin.mLayer |
| 6159 | + ", new win layer=" + newWindow.mLayer); |
| 6160 | if (newWindow.mLayer >= mLastWin.mLayer) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6161 | // The new window is above the old; finish pending input to the last |
| 6162 | // window and start directing it to the new one. |
| 6163 | mLastWin.mToken.paused = false; |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6164 | doFinishedKeyLocked(false); // does a notifyAll() |
| 6165 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6166 | } |
| 6167 | } |
| 6168 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 6169 | // Now that we've put a new window state in place, make the event waiter |
| 6170 | // take notice and retarget its attentions. |
| 6171 | notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6172 | } |
| 6173 | } |
| 6174 | |
| 6175 | void pauseDispatchingLocked(WindowToken token) { |
| 6176 | synchronized (this) |
| 6177 | { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6178 | if (DEBUG_INPUT) Slog.v(TAG, "Pausing WindowToken " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6179 | token.paused = true; |
| 6180 | |
| 6181 | /* |
| 6182 | if (mLastWin != null && !mFinished && mLastWin.mBaseLayer <= layer) { |
| 6183 | mPaused = true; |
| 6184 | } else { |
| 6185 | if (mLastWin == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6186 | Slog.i(TAG, "Key dispatching not paused: no last window."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6187 | } else if (mFinished) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6188 | Slog.i(TAG, "Key dispatching not paused: finished last key."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6189 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6190 | Slog.i(TAG, "Key dispatching not paused: window in higher layer."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6191 | } |
| 6192 | } |
| 6193 | */ |
| 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | void resumeDispatchingLocked(WindowToken token) { |
| 6198 | synchronized (this) { |
| 6199 | if (token.paused) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6200 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6201 | TAG, "Resuming WindowToken " + token |
| 6202 | + ", last=" + mLastBinder |
| 6203 | + " (token=" + (mLastWin != null ? mLastWin.mToken : null) |
| 6204 | + "), finished=" + mFinished + ", paused=" |
| 6205 | + token.paused); |
| 6206 | token.paused = false; |
| 6207 | if (mLastWin != null && mLastWin.mToken == token && mFinished) { |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6208 | doFinishedKeyLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | } else { |
| 6210 | notifyAll(); |
| 6211 | } |
| 6212 | } |
| 6213 | } |
| 6214 | } |
| 6215 | |
| 6216 | void setEventDispatchingLocked(boolean enabled) { |
| 6217 | synchronized (this) { |
| 6218 | mEventDispatching = enabled; |
| 6219 | notifyAll(); |
| 6220 | } |
| 6221 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6222 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6223 | void appSwitchComing() { |
| 6224 | synchronized (this) { |
| 6225 | // Don't wait for more than .5 seconds for app to finish |
| 6226 | // processing the pending events. |
| 6227 | long now = SystemClock.uptimeMillis() + 500; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6228 | if (DEBUG_INPUT) Slog.v(TAG, "appSwitchComing: " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | if (mTimeToSwitch == 0 || now < mTimeToSwitch) { |
| 6230 | mTimeToSwitch = now; |
| 6231 | } |
| 6232 | notifyAll(); |
| 6233 | } |
| 6234 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6235 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6236 | private final void doFinishedKeyLocked(boolean force) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6237 | if (mLastWin != null) { |
| 6238 | releasePendingPointerLocked(mLastWin.mSession); |
| 6239 | releasePendingTrackballLocked(mLastWin.mSession); |
| 6240 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6241 | |
| Christopher Tate | 136b1f9 | 2010-02-11 17:51:24 -0800 | [diff] [blame] | 6242 | if (force || mLastWin == null || !mLastWin.mToken.paused |
| 6243 | || !mLastWin.isVisibleLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6244 | // If the current window has been paused, we aren't -really- |
| 6245 | // finished... so let the waiters still wait. |
| 6246 | mLastWin = null; |
| 6247 | mLastBinder = null; |
| 6248 | } |
| 6249 | mFinished = true; |
| 6250 | notifyAll(); |
| 6251 | } |
| 6252 | } |
| 6253 | |
| 6254 | private class KeyQ extends KeyInputQueue |
| 6255 | implements KeyInputQueue.FilterCallback { |
| 6256 | PowerManager.WakeLock mHoldingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | KeyQ() { |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 6259 | super(mContext, WindowManagerService.this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6260 | PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); |
| 6261 | mHoldingScreen = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 6262 | "KEEP_SCREEN_ON_FLAG"); |
| 6263 | mHoldingScreen.setReferenceCounted(false); |
| 6264 | } |
| 6265 | |
| 6266 | @Override |
| 6267 | boolean preprocessEvent(InputDevice device, RawInputEvent event) { |
| 6268 | if (mPolicy.preprocessInputEventTq(event)) { |
| 6269 | return true; |
| 6270 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6271 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6272 | switch (event.type) { |
| 6273 | case RawInputEvent.EV_KEY: { |
| 6274 | // XXX begin hack |
| 6275 | if (DEBUG) { |
| 6276 | if (event.keycode == KeyEvent.KEYCODE_G) { |
| 6277 | if (event.value != 0) { |
| 6278 | // G down |
| 6279 | mPolicy.screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 6280 | } |
| 6281 | return false; |
| 6282 | } |
| 6283 | if (event.keycode == KeyEvent.KEYCODE_D) { |
| 6284 | if (event.value != 0) { |
| 6285 | //dump(); |
| 6286 | } |
| 6287 | return false; |
| 6288 | } |
| 6289 | } |
| 6290 | // XXX end hack |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6291 | |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6292 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6293 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6294 | int actions = mPolicy.interceptKeyTq(event, !screenIsOff); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6295 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6296 | if ((actions & WindowManagerPolicy.ACTION_GO_TO_SLEEP) != 0) { |
| 6297 | mPowerManager.goToSleep(event.when); |
| 6298 | } |
| 6299 | |
| 6300 | if (screenIsOff) { |
| 6301 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6302 | } |
| 6303 | if (screenIsDim) { |
| 6304 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6305 | } |
| 6306 | if ((actions & WindowManagerPolicy.ACTION_POKE_USER_ACTIVITY) != 0) { |
| 6307 | mPowerManager.userActivity(event.when, false, |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6308 | LocalPowerManager.BUTTON_EVENT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6309 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6310 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | if ((actions & WindowManagerPolicy.ACTION_PASS_TO_USER) != 0) { |
| 6312 | if (event.value != 0 && mPolicy.isAppSwitchKeyTqTiLwLi(event.keycode)) { |
| 6313 | filterQueue(this); |
| 6314 | mKeyWaiter.appSwitchComing(); |
| 6315 | } |
| 6316 | return true; |
| 6317 | } else { |
| 6318 | return false; |
| 6319 | } |
| 6320 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6321 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6322 | case RawInputEvent.EV_REL: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6323 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6324 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6325 | if (screenIsOff) { |
| 6326 | if (!mPolicy.isWakeRelMovementTq(event.deviceId, |
| 6327 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6328 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | return false; |
| 6330 | } |
| 6331 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6332 | } |
| 6333 | if (screenIsDim) { |
| 6334 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6335 | } |
| 6336 | return true; |
| 6337 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6339 | case RawInputEvent.EV_ABS: { |
| Charles Mendis | 322591c | 2009-10-29 11:06:59 -0700 | [diff] [blame] | 6340 | boolean screenIsOff = !mPowerManager.isScreenOn(); |
| 6341 | boolean screenIsDim = !mPowerManager.isScreenBright(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6342 | if (screenIsOff) { |
| 6343 | if (!mPolicy.isWakeAbsMovementTq(event.deviceId, |
| 6344 | device.classes, event)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6345 | //Slog.i(TAG, "dropping because screenIsOff and !isWakeKey"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6346 | return false; |
| 6347 | } |
| 6348 | event.flags |= WindowManagerPolicy.FLAG_WOKE_HERE; |
| 6349 | } |
| 6350 | if (screenIsDim) { |
| 6351 | event.flags |= WindowManagerPolicy.FLAG_BRIGHT_HERE; |
| 6352 | } |
| 6353 | return true; |
| 6354 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | default: |
| 6357 | return true; |
| 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | public int filterEvent(QueuedEvent ev) { |
| 6362 | switch (ev.classType) { |
| 6363 | case RawInputEvent.CLASS_KEYBOARD: |
| 6364 | KeyEvent ke = (KeyEvent)ev.event; |
| 6365 | if (mPolicy.isMovementKeyTi(ke.getKeyCode())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6366 | Slog.w(TAG, "Dropping movement key during app switch: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | + ke.getKeyCode() + ", action=" + ke.getAction()); |
| 6368 | return FILTER_REMOVE; |
| 6369 | } |
| 6370 | return FILTER_ABORT; |
| 6371 | default: |
| 6372 | return FILTER_KEEP; |
| 6373 | } |
| 6374 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | /** |
| 6377 | * Must be called with the main window manager lock held. |
| 6378 | */ |
| 6379 | void setHoldScreenLocked(boolean holding) { |
| 6380 | boolean state = mHoldingScreen.isHeld(); |
| 6381 | if (holding != state) { |
| 6382 | if (holding) { |
| 6383 | mHoldingScreen.acquire(); |
| 6384 | } else { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6385 | mPolicy.screenOnStoppedLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6386 | mHoldingScreen.release(); |
| 6387 | } |
| 6388 | } |
| 6389 | } |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6390 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | |
| 6392 | public boolean detectSafeMode() { |
| 6393 | mSafeMode = mPolicy.detectSafeMode(); |
| 6394 | return mSafeMode; |
| 6395 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6396 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6397 | public void systemReady() { |
| 6398 | mPolicy.systemReady(); |
| 6399 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | private final class InputDispatcherThread extends Thread { |
| 6402 | // Time to wait when there is nothing to do: 9999 seconds. |
| 6403 | static final int LONG_WAIT=9999*1000; |
| 6404 | |
| 6405 | public InputDispatcherThread() { |
| 6406 | super("InputDispatcher"); |
| 6407 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6408 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6409 | @Override |
| 6410 | public void run() { |
| 6411 | while (true) { |
| 6412 | try { |
| 6413 | process(); |
| 6414 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6415 | Slog.e(TAG, "Exception in input dispatcher", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6416 | } |
| 6417 | } |
| 6418 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | private void process() { |
| 6421 | android.os.Process.setThreadPriority( |
| 6422 | android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6423 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6424 | // The last key event we saw |
| 6425 | KeyEvent lastKey = null; |
| 6426 | |
| 6427 | // Last keydown time for auto-repeating keys |
| 6428 | long lastKeyTime = SystemClock.uptimeMillis(); |
| 6429 | long nextKeyTime = lastKeyTime+LONG_WAIT; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6430 | long downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6431 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6432 | // How many successive repeats we generated |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6433 | int keyRepeatCount = 0; |
| 6434 | |
| 6435 | // Need to report that configuration has changed? |
| 6436 | boolean configChanged = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6438 | while (true) { |
| 6439 | long curTime = SystemClock.uptimeMillis(); |
| 6440 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6441 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6442 | TAG, "Waiting for next key: now=" + curTime |
| 6443 | + ", repeat @ " + nextKeyTime); |
| 6444 | |
| 6445 | // Retrieve next event, waiting only as long as the next |
| 6446 | // repeat timeout. If the configuration has changed, then |
| 6447 | // don't wait at all -- we'll report the change as soon as |
| 6448 | // we have processed all events. |
| 6449 | QueuedEvent ev = mQueue.getEvent( |
| 6450 | (int)((!configChanged && curTime < nextKeyTime) |
| 6451 | ? (nextKeyTime-curTime) : 0)); |
| 6452 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6453 | if (DEBUG_INPUT && ev != null) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6454 | TAG, "Event: type=" + ev.classType + " data=" + ev.event); |
| 6455 | |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6456 | if (MEASURE_LATENCY) { |
| 6457 | lt.sample("2 got event ", System.nanoTime() - ev.whenNano); |
| 6458 | } |
| 6459 | |
| Mike Lockwood | 3d0ea72 | 2009-10-21 22:58:29 -0400 | [diff] [blame] | 6460 | if (lastKey != null && !mPolicy.allowKeyRepeat()) { |
| 6461 | // cancel key repeat at the request of the policy. |
| 6462 | lastKey = null; |
| 6463 | downTime = 0; |
| 6464 | lastKeyTime = curTime; |
| 6465 | nextKeyTime = curTime + LONG_WAIT; |
| 6466 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6467 | try { |
| 6468 | if (ev != null) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6469 | curTime = SystemClock.uptimeMillis(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | int eventType; |
| 6471 | if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { |
| 6472 | eventType = eventType((MotionEvent)ev.event); |
| 6473 | } else if (ev.classType == RawInputEvent.CLASS_KEYBOARD || |
| 6474 | ev.classType == RawInputEvent.CLASS_TRACKBALL) { |
| 6475 | eventType = LocalPowerManager.BUTTON_EVENT; |
| 6476 | } else { |
| 6477 | eventType = LocalPowerManager.OTHER_EVENT; |
| 6478 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6479 | try { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6480 | if ((curTime - mLastBatteryStatsCallTime) |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6481 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 6482 | mLastBatteryStatsCallTime = curTime; |
| Michael Chan | e96440f | 2009-05-06 10:27:36 -0700 | [diff] [blame] | 6483 | mBatteryStats.noteInputEvent(); |
| 6484 | } |
| Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6485 | } catch (RemoteException e) { |
| 6486 | // Ignore |
| 6487 | } |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6488 | |
| Mike Lockwood | 5db4240 | 2009-11-30 14:51:51 -0500 | [diff] [blame] | 6489 | if (ev.classType == RawInputEvent.CLASS_CONFIGURATION_CHANGED) { |
| 6490 | // do not wake screen in this case |
| 6491 | } else if (eventType != TOUCH_EVENT |
| Michael Chan | e10de97 | 2009-05-18 11:24:50 -0700 | [diff] [blame] | 6492 | && eventType != LONG_TOUCH_EVENT |
| 6493 | && eventType != CHEEK_EVENT) { |
| 6494 | mPowerManager.userActivity(curTime, false, |
| 6495 | eventType, false); |
| 6496 | } else if (mLastTouchEventType != eventType |
| 6497 | || (curTime - mLastUserActivityCallTime) |
| 6498 | >= MIN_TIME_BETWEEN_USERACTIVITIES) { |
| 6499 | mLastUserActivityCallTime = curTime; |
| 6500 | mLastTouchEventType = eventType; |
| 6501 | mPowerManager.userActivity(curTime, false, |
| 6502 | eventType, false); |
| 6503 | } |
| 6504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | switch (ev.classType) { |
| 6506 | case RawInputEvent.CLASS_KEYBOARD: |
| 6507 | KeyEvent ke = (KeyEvent)ev.event; |
| 6508 | if (ke.isDown()) { |
| 6509 | lastKey = ke; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6510 | downTime = curTime; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6511 | keyRepeatCount = 0; |
| 6512 | lastKeyTime = curTime; |
| 6513 | nextKeyTime = lastKeyTime |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6514 | + ViewConfiguration.getLongPressTimeout(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6515 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6516 | TAG, "Received key down: first repeat @ " |
| 6517 | + nextKeyTime); |
| 6518 | } else { |
| 6519 | lastKey = null; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6520 | downTime = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | // Arbitrary long timeout. |
| 6522 | lastKeyTime = curTime; |
| 6523 | nextKeyTime = curTime + LONG_WAIT; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6524 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | TAG, "Received key up: ignore repeat @ " |
| 6526 | + nextKeyTime); |
| 6527 | } |
| 6528 | dispatchKey((KeyEvent)ev.event, 0, 0); |
| 6529 | mQueue.recycleEvent(ev); |
| 6530 | break; |
| 6531 | case RawInputEvent.CLASS_TOUCHSCREEN: |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6532 | //Slog.i(TAG, "Read next event " + ev); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); |
| 6534 | break; |
| 6535 | case RawInputEvent.CLASS_TRACKBALL: |
| 6536 | dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0); |
| 6537 | break; |
| 6538 | case RawInputEvent.CLASS_CONFIGURATION_CHANGED: |
| 6539 | configChanged = true; |
| 6540 | break; |
| 6541 | default: |
| 6542 | mQueue.recycleEvent(ev); |
| 6543 | break; |
| 6544 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6545 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6546 | } else if (configChanged) { |
| 6547 | configChanged = false; |
| 6548 | sendNewConfiguration(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6550 | } else if (lastKey != null) { |
| 6551 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6552 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6553 | // Timeout occurred while key was down. If it is at or |
| 6554 | // past the key repeat time, dispatch the repeat. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6555 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6556 | TAG, "Key timeout: repeat=" + nextKeyTime |
| 6557 | + ", now=" + curTime); |
| 6558 | if (curTime < nextKeyTime) { |
| 6559 | continue; |
| 6560 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6561 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6562 | lastKeyTime = nextKeyTime; |
| 6563 | nextKeyTime = nextKeyTime + KEY_REPEAT_DELAY; |
| 6564 | keyRepeatCount++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6565 | if (DEBUG_INPUT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6566 | TAG, "Key repeat: count=" + keyRepeatCount |
| 6567 | + ", next @ " + nextKeyTime); |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6568 | KeyEvent newEvent; |
| 6569 | if (downTime != 0 && (downTime |
| 6570 | + ViewConfiguration.getLongPressTimeout()) |
| 6571 | <= curTime) { |
| 6572 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6573 | curTime, keyRepeatCount, |
| 6574 | lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 6575 | downTime = 0; |
| 6576 | } else { |
| 6577 | newEvent = KeyEvent.changeTimeRepeat(lastKey, |
| 6578 | curTime, keyRepeatCount); |
| 6579 | } |
| 6580 | dispatchKey(newEvent, 0, 0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6581 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6582 | } else { |
| 6583 | curTime = SystemClock.uptimeMillis(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6584 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6585 | lastKeyTime = curTime; |
| 6586 | nextKeyTime = curTime + LONG_WAIT; |
| 6587 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6589 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6590 | Slog.e(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6591 | "Input thread received uncaught exception: " + e, e); |
| 6592 | } |
| 6593 | } |
| 6594 | } |
| 6595 | } |
| 6596 | |
| 6597 | // ------------------------------------------------------------- |
| 6598 | // Client Session State |
| 6599 | // ------------------------------------------------------------- |
| 6600 | |
| 6601 | private final class Session extends IWindowSession.Stub |
| 6602 | implements IBinder.DeathRecipient { |
| 6603 | final IInputMethodClient mClient; |
| 6604 | final IInputContext mInputContext; |
| 6605 | final int mUid; |
| 6606 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6607 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6608 | SurfaceSession mSurfaceSession; |
| 6609 | int mNumWindow = 0; |
| 6610 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6612 | /** |
| 6613 | * Current pointer move event being dispatched to client window... must |
| 6614 | * hold key lock to access. |
| 6615 | */ |
| 6616 | QueuedEvent mPendingPointerMove; |
| 6617 | WindowState mPendingPointerWindow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6618 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | /** |
| 6620 | * Current trackball move event being dispatched to client window... must |
| 6621 | * hold key lock to access. |
| 6622 | */ |
| 6623 | QueuedEvent mPendingTrackballMove; |
| 6624 | WindowState mPendingTrackballWindow; |
| 6625 | |
| 6626 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6627 | mClient = client; |
| 6628 | mInputContext = inputContext; |
| 6629 | mUid = Binder.getCallingUid(); |
| 6630 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6631 | StringBuilder sb = new StringBuilder(); |
| 6632 | sb.append("Session{"); |
| 6633 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6634 | sb.append(" uid "); |
| 6635 | sb.append(mUid); |
| 6636 | sb.append("}"); |
| 6637 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6638 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6639 | synchronized (mWindowMap) { |
| 6640 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6641 | IBinder b = ServiceManager.getService( |
| 6642 | Context.INPUT_METHOD_SERVICE); |
| 6643 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6644 | } |
| 6645 | } |
| 6646 | long ident = Binder.clearCallingIdentity(); |
| 6647 | try { |
| 6648 | // Note: it is safe to call in to the input method manager |
| 6649 | // here because we are not holding our lock. |
| 6650 | if (mInputMethodManager != null) { |
| 6651 | mInputMethodManager.addClient(client, inputContext, |
| 6652 | mUid, mPid); |
| 6653 | } else { |
| 6654 | client.setUsingInputMethod(false); |
| 6655 | } |
| 6656 | client.asBinder().linkToDeath(this, 0); |
| 6657 | } catch (RemoteException e) { |
| 6658 | // The caller has died, so we can just forget about this. |
| 6659 | try { |
| 6660 | if (mInputMethodManager != null) { |
| 6661 | mInputMethodManager.removeClient(client); |
| 6662 | } |
| 6663 | } catch (RemoteException ee) { |
| 6664 | } |
| 6665 | } finally { |
| 6666 | Binder.restoreCallingIdentity(ident); |
| 6667 | } |
| 6668 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6669 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6670 | @Override |
| 6671 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6672 | throws RemoteException { |
| 6673 | try { |
| 6674 | return super.onTransact(code, data, reply, flags); |
| 6675 | } catch (RuntimeException e) { |
| 6676 | // Log all 'real' exceptions thrown to the caller |
| 6677 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6678 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | } |
| 6680 | throw e; |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | public void binderDied() { |
| 6685 | // Note: it is safe to call in to the input method manager |
| 6686 | // here because we are not holding our lock. |
| 6687 | try { |
| 6688 | if (mInputMethodManager != null) { |
| 6689 | mInputMethodManager.removeClient(mClient); |
| 6690 | } |
| 6691 | } catch (RemoteException e) { |
| 6692 | } |
| 6693 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6694 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6695 | mClientDead = true; |
| 6696 | killSessionLocked(); |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| 6701 | int viewVisibility, Rect outContentInsets) { |
| 6702 | return addWindow(this, window, attrs, viewVisibility, outContentInsets); |
| 6703 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6704 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6705 | public void remove(IWindow window) { |
| 6706 | removeWindow(this, window); |
| 6707 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6709 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6710 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6711 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6712 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6713 | return relayoutWindow(this, window, attrs, |
| 6714 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6715 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6716 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6717 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6718 | public void setTransparentRegion(IWindow window, Region region) { |
| 6719 | setTransparentRegionWindow(this, window, region); |
| 6720 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6721 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6722 | public void setInsets(IWindow window, int touchableInsets, |
| 6723 | Rect contentInsets, Rect visibleInsets) { |
| 6724 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6725 | visibleInsets); |
| 6726 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6727 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6728 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6729 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6730 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6731 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6732 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6733 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | TAG, "IWindow finishDrawing called for " + window); |
| 6735 | finishDrawingWindow(this, window); |
| 6736 | } |
| 6737 | |
| 6738 | public void finishKey(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6739 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6740 | TAG, "IWindow finishKey called for " + window); |
| 6741 | mKeyWaiter.finishedKey(this, window, false, |
| 6742 | KeyWaiter.RETURN_NOTHING); |
| 6743 | } |
| 6744 | |
| 6745 | public MotionEvent getPendingPointerMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6746 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6748 | return mKeyWaiter.finishedKey(this, window, false, |
| 6749 | KeyWaiter.RETURN_PENDING_POINTER); |
| 6750 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6751 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6752 | public MotionEvent getPendingTrackballMove(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6753 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6754 | TAG, "IWindow getPendingMotionEvent called for " + window); |
| 6755 | return mKeyWaiter.finishedKey(this, window, false, |
| 6756 | KeyWaiter.RETURN_PENDING_TRACKBALL); |
| 6757 | } |
| 6758 | |
| 6759 | public void setInTouchMode(boolean mode) { |
| 6760 | synchronized(mWindowMap) { |
| 6761 | mInTouchMode = mode; |
| 6762 | } |
| 6763 | } |
| 6764 | |
| 6765 | public boolean getInTouchMode() { |
| 6766 | synchronized(mWindowMap) { |
| 6767 | return mInTouchMode; |
| 6768 | } |
| 6769 | } |
| 6770 | |
| 6771 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6772 | boolean always) { |
| 6773 | synchronized(mWindowMap) { |
| 6774 | long ident = Binder.clearCallingIdentity(); |
| 6775 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6776 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6777 | windowForClientLocked(this, window, true), |
| 6778 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6779 | } finally { |
| 6780 | Binder.restoreCallingIdentity(ident); |
| 6781 | } |
| 6782 | } |
| 6783 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6784 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6785 | 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] | 6786 | synchronized(mWindowMap) { |
| 6787 | long ident = Binder.clearCallingIdentity(); |
| 6788 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6789 | setWindowWallpaperPositionLocked( |
| 6790 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6791 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(ident); |
| 6794 | } |
| 6795 | } |
| 6796 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6797 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6798 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6799 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6800 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6801 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6802 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6803 | int z, Bundle extras, boolean sync) { |
| 6804 | synchronized(mWindowMap) { |
| 6805 | long ident = Binder.clearCallingIdentity(); |
| 6806 | try { |
| 6807 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6808 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6809 | action, x, y, z, extras, sync); |
| 6810 | } finally { |
| 6811 | Binder.restoreCallingIdentity(ident); |
| 6812 | } |
| 6813 | } |
| 6814 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6815 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6816 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6817 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6818 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6819 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6820 | void windowAddedLocked() { |
| 6821 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6822 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6823 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6824 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6825 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6826 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | mSessions.add(this); |
| 6828 | } |
| 6829 | mNumWindow++; |
| 6830 | } |
| 6831 | |
| 6832 | void windowRemovedLocked() { |
| 6833 | mNumWindow--; |
| 6834 | killSessionLocked(); |
| 6835 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6836 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6837 | void killSessionLocked() { |
| 6838 | if (mNumWindow <= 0 && mClientDead) { |
| 6839 | mSessions.remove(this); |
| 6840 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6841 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6842 | TAG, "Last window removed from " + this |
| 6843 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6844 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6845 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6846 | try { |
| 6847 | mSurfaceSession.kill(); |
| 6848 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6849 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | + mSurfaceSession + " in session " + this |
| 6851 | + ": " + e.toString()); |
| 6852 | } |
| 6853 | mSurfaceSession = null; |
| 6854 | } |
| 6855 | } |
| 6856 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6857 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6858 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6859 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6860 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6861 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 6862 | if (mPendingPointerWindow != null || mPendingPointerMove != null) { |
| 6863 | pw.print(prefix); |
| 6864 | pw.print("mPendingPointerWindow="); pw.print(mPendingPointerWindow); |
| 6865 | pw.print(" mPendingPointerMove="); pw.println(mPendingPointerMove); |
| 6866 | } |
| 6867 | if (mPendingTrackballWindow != null || mPendingTrackballMove != null) { |
| 6868 | pw.print(prefix); |
| 6869 | pw.print("mPendingTrackballWindow="); pw.print(mPendingTrackballWindow); |
| 6870 | pw.print(" mPendingTrackballMove="); pw.println(mPendingTrackballMove); |
| 6871 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6872 | } |
| 6873 | |
| 6874 | @Override |
| 6875 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6876 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | // ------------------------------------------------------------- |
| 6881 | // Client Window State |
| 6882 | // ------------------------------------------------------------- |
| 6883 | |
| 6884 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6885 | final Session mSession; |
| 6886 | final IWindow mClient; |
| 6887 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6888 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6889 | AppWindowToken mAppToken; |
| 6890 | AppWindowToken mTargetAppToken; |
| 6891 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6892 | final DeathRecipient mDeathRecipient; |
| 6893 | final WindowState mAttachedWindow; |
| 6894 | final ArrayList mChildWindows = new ArrayList(); |
| 6895 | final int mBaseLayer; |
| 6896 | final int mSubLayer; |
| 6897 | final boolean mLayoutAttached; |
| 6898 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6899 | final boolean mIsWallpaper; |
| 6900 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | int mViewVisibility; |
| 6902 | boolean mPolicyVisibility = true; |
| 6903 | boolean mPolicyVisibilityAfterAnim = true; |
| 6904 | boolean mAppFreezing; |
| 6905 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6906 | boolean mReportDestroySurface; |
| 6907 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6908 | boolean mAttachedHidden; // is our parent window hidden? |
| 6909 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6910 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6911 | int mRequestedWidth; |
| 6912 | int mRequestedHeight; |
| 6913 | int mLastRequestedWidth; |
| 6914 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6915 | int mLayer; |
| 6916 | int mAnimLayer; |
| 6917 | int mLastLayer; |
| 6918 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6919 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6920 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6921 | |
| 6922 | WindowState mNextOutsideTouch; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6923 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6924 | int mLayoutSeq = -1; |
| 6925 | |
| 6926 | Configuration mConfiguration = null; |
| 6927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6928 | // Actual frame shown on-screen (may be modified by animation) |
| 6929 | final Rect mShownFrame = new Rect(); |
| 6930 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6932 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6933 | * Set when we have changed the size of the surface, to know that |
| 6934 | * we must tell them application to resize (and thus redraw itself). |
| 6935 | */ |
| 6936 | boolean mSurfaceResized; |
| 6937 | |
| 6938 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | * Insets that determine the actually visible area |
| 6940 | */ |
| 6941 | final Rect mVisibleInsets = new Rect(); |
| 6942 | final Rect mLastVisibleInsets = new Rect(); |
| 6943 | boolean mVisibleInsetsChanged; |
| 6944 | |
| 6945 | /** |
| 6946 | * Insets that are covered by system windows |
| 6947 | */ |
| 6948 | final Rect mContentInsets = new Rect(); |
| 6949 | final Rect mLastContentInsets = new Rect(); |
| 6950 | boolean mContentInsetsChanged; |
| 6951 | |
| 6952 | /** |
| 6953 | * Set to true if we are waiting for this window to receive its |
| 6954 | * given internal insets before laying out other windows based on it. |
| 6955 | */ |
| 6956 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6957 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6958 | /** |
| 6959 | * These are the content insets that were given during layout for |
| 6960 | * this window, to be applied to windows behind it. |
| 6961 | */ |
| 6962 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6963 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | /** |
| 6965 | * These are the visible insets that were given during layout for |
| 6966 | * this window, to be applied to windows behind it. |
| 6967 | */ |
| 6968 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6969 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | /** |
| 6971 | * Flag indicating whether the touchable region should be adjusted by |
| 6972 | * the visible insets; if false the area outside the visible insets is |
| 6973 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6974 | * tests. |
| 6975 | */ |
| 6976 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | // Current transformation being applied. |
| 6979 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6980 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6981 | float mHScale=1, mVScale=1; |
| 6982 | float mLastHScale=1, mLastVScale=1; |
| 6983 | final Matrix mTmpMatrix = new Matrix(); |
| 6984 | |
| 6985 | // "Real" frame that the application sees. |
| 6986 | final Rect mFrame = new Rect(); |
| 6987 | final Rect mLastFrame = new Rect(); |
| 6988 | |
| 6989 | final Rect mContainingFrame = new Rect(); |
| 6990 | final Rect mDisplayFrame = new Rect(); |
| 6991 | final Rect mContentFrame = new Rect(); |
| 6992 | final Rect mVisibleFrame = new Rect(); |
| 6993 | |
| 6994 | float mShownAlpha = 1; |
| 6995 | float mAlpha = 1; |
| 6996 | float mLastAlpha = 1; |
| 6997 | |
| 6998 | // Set to true if, when the window gets displayed, it should perform |
| 6999 | // an enter animation. |
| 7000 | boolean mEnterAnimationPending; |
| 7001 | |
| 7002 | // Currently running animation. |
| 7003 | boolean mAnimating; |
| 7004 | boolean mLocalAnimating; |
| 7005 | Animation mAnimation; |
| 7006 | boolean mAnimationIsEntrance; |
| 7007 | boolean mHasTransformation; |
| 7008 | boolean mHasLocalTransformation; |
| 7009 | final Transformation mTransformation = new Transformation(); |
| 7010 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7011 | // If a window showing a wallpaper: the requested offset for the |
| 7012 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 7013 | float mWallpaperX = -1; |
| 7014 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7015 | |
| 7016 | // If a window showing a wallpaper: what fraction of the offset |
| 7017 | // range corresponds to a full virtual screen. |
| 7018 | float mWallpaperXStep = -1; |
| 7019 | float mWallpaperYStep = -1; |
| 7020 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7021 | // Wallpaper windows: pixels offset based on above variables. |
| 7022 | int mXOffset; |
| 7023 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7024 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7025 | // This is set after IWindowSession.relayout() has been called at |
| 7026 | // least once for the window. It allows us to detect the situation |
| 7027 | // where we don't yet have a surface, but should have one soon, so |
| 7028 | // we can give the window focus before waiting for the relayout. |
| 7029 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7030 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7031 | // This is set after the Surface has been created but before the |
| 7032 | // window has been drawn. During this time the surface is hidden. |
| 7033 | boolean mDrawPending; |
| 7034 | |
| 7035 | // This is set after the window has finished drawing for the first |
| 7036 | // time but before its surface is shown. The surface will be |
| 7037 | // displayed when the next layout is run. |
| 7038 | boolean mCommitDrawPending; |
| 7039 | |
| 7040 | // This is set during the time after the window's drawing has been |
| 7041 | // committed, and before its surface is actually shown. It is used |
| 7042 | // to delay showing the surface until all windows in a token are ready |
| 7043 | // to be shown. |
| 7044 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7046 | // Set when the window has been shown in the screen the first time. |
| 7047 | boolean mHasDrawn; |
| 7048 | |
| 7049 | // Currently running an exit animation? |
| 7050 | boolean mExiting; |
| 7051 | |
| 7052 | // Currently on the mDestroySurface list? |
| 7053 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7054 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7055 | // Completely remove from window manager after exit animation? |
| 7056 | boolean mRemoveOnExit; |
| 7057 | |
| 7058 | // Set when the orientation is changing and this window has not yet |
| 7059 | // been updated for the new orientation. |
| 7060 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7061 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7062 | // Is this window now (or just being) removed? |
| 7063 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7064 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7065 | // For debugging, this is the last information given to the surface flinger. |
| 7066 | boolean mSurfaceShown; |
| 7067 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 7068 | int mSurfaceLayer; |
| 7069 | float mSurfaceAlpha; |
| 7070 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7071 | WindowState(Session s, IWindow c, WindowToken token, |
| 7072 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 7073 | int viewVisibility) { |
| 7074 | mSession = s; |
| 7075 | mClient = c; |
| 7076 | mToken = token; |
| 7077 | mAttrs.copyFrom(a); |
| 7078 | mViewVisibility = viewVisibility; |
| 7079 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 7080 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7081 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | TAG, "Window " + this + " client=" + c.asBinder() |
| 7083 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 7084 | try { |
| 7085 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 7086 | } catch (RemoteException e) { |
| 7087 | mDeathRecipient = null; |
| 7088 | mAttachedWindow = null; |
| 7089 | mLayoutAttached = false; |
| 7090 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7091 | mIsWallpaper = false; |
| 7092 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7093 | mBaseLayer = 0; |
| 7094 | mSubLayer = 0; |
| 7095 | return; |
| 7096 | } |
| 7097 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7098 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7099 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7100 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7101 | // The multiplier here is to reserve space for multiple |
| 7102 | // windows in the same type layer. |
| 7103 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7104 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7105 | + TYPE_LAYER_OFFSET; |
| 7106 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7107 | mAttachedWindow = attachedWindow; |
| 7108 | mAttachedWindow.mChildWindows.add(this); |
| 7109 | mLayoutAttached = mAttrs.type != |
| 7110 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7111 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7112 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7113 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7114 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7115 | } else { |
| 7116 | // The multiplier here is to reserve space for multiple |
| 7117 | // windows in the same type layer. |
| 7118 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7119 | * TYPE_LAYER_MULTIPLIER |
| 7120 | + TYPE_LAYER_OFFSET; |
| 7121 | mSubLayer = 0; |
| 7122 | mAttachedWindow = null; |
| 7123 | mLayoutAttached = false; |
| 7124 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7125 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7126 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7127 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | WindowState appWin = this; |
| 7131 | while (appWin.mAttachedWindow != null) { |
| 7132 | appWin = mAttachedWindow; |
| 7133 | } |
| 7134 | WindowToken appToken = appWin.mToken; |
| 7135 | while (appToken.appWindowToken == null) { |
| 7136 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7137 | if (parent == null || appToken == parent) { |
| 7138 | break; |
| 7139 | } |
| 7140 | appToken = parent; |
| 7141 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7142 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7143 | mAppToken = appToken.appWindowToken; |
| 7144 | |
| 7145 | mSurface = null; |
| 7146 | mRequestedWidth = 0; |
| 7147 | mRequestedHeight = 0; |
| 7148 | mLastRequestedWidth = 0; |
| 7149 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7150 | mXOffset = 0; |
| 7151 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7152 | mLayer = 0; |
| 7153 | mAnimLayer = 0; |
| 7154 | mLastLayer = 0; |
| 7155 | } |
| 7156 | |
| 7157 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7158 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7159 | TAG, "Attaching " + this + " token=" + mToken |
| 7160 | + ", list=" + mToken.windows); |
| 7161 | mSession.windowAddedLocked(); |
| 7162 | } |
| 7163 | |
| 7164 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7165 | mHaveFrame = true; |
| 7166 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7167 | final Rect container = mContainingFrame; |
| 7168 | container.set(pf); |
| 7169 | |
| 7170 | final Rect display = mDisplayFrame; |
| 7171 | display.set(df); |
| 7172 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7173 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7174 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7175 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7176 | display.intersect(mCompatibleScreenFrame); |
| 7177 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7178 | } |
| 7179 | |
| 7180 | final int pw = container.right - container.left; |
| 7181 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7182 | |
| 7183 | int w,h; |
| 7184 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7185 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7186 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7187 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7188 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7189 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7190 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7192 | final Rect content = mContentFrame; |
| 7193 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7194 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | final Rect visible = mVisibleFrame; |
| 7196 | visible.set(vf); |
| 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 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7199 | final int fw = frame.width(); |
| 7200 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7201 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7202 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7203 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7204 | |
| 7205 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7206 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7207 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7208 | |
| 7209 | //System.out.println("Out: " + mFrame); |
| 7210 | |
| 7211 | // Now make sure the window fits in the overall display. |
| 7212 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7213 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | // Make sure the content and visible frames are inside of the |
| 7215 | // final window frame. |
| 7216 | if (content.left < frame.left) content.left = frame.left; |
| 7217 | if (content.top < frame.top) content.top = frame.top; |
| 7218 | if (content.right > frame.right) content.right = frame.right; |
| 7219 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7220 | if (visible.left < frame.left) visible.left = frame.left; |
| 7221 | if (visible.top < frame.top) visible.top = frame.top; |
| 7222 | if (visible.right > frame.right) visible.right = frame.right; |
| 7223 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7224 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7225 | final Rect contentInsets = mContentInsets; |
| 7226 | contentInsets.left = content.left-frame.left; |
| 7227 | contentInsets.top = content.top-frame.top; |
| 7228 | contentInsets.right = frame.right-content.right; |
| 7229 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7230 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7231 | final Rect visibleInsets = mVisibleInsets; |
| 7232 | visibleInsets.left = visible.left-frame.left; |
| 7233 | visibleInsets.top = visible.top-frame.top; |
| 7234 | visibleInsets.right = frame.right-visible.right; |
| 7235 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7236 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7237 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7238 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7239 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7240 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7242 | if (localLOGV) { |
| 7243 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7244 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7245 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7246 | + mRequestedWidth + ", mRequestedheight=" |
| 7247 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7248 | + "): frame=" + mFrame.toShortString() |
| 7249 | + " ci=" + contentInsets.toShortString() |
| 7250 | + " vi=" + visibleInsets.toShortString()); |
| 7251 | //} |
| 7252 | } |
| 7253 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7254 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7255 | public Rect getFrameLw() { |
| 7256 | return mFrame; |
| 7257 | } |
| 7258 | |
| 7259 | public Rect getShownFrameLw() { |
| 7260 | return mShownFrame; |
| 7261 | } |
| 7262 | |
| 7263 | public Rect getDisplayFrameLw() { |
| 7264 | return mDisplayFrame; |
| 7265 | } |
| 7266 | |
| 7267 | public Rect getContentFrameLw() { |
| 7268 | return mContentFrame; |
| 7269 | } |
| 7270 | |
| 7271 | public Rect getVisibleFrameLw() { |
| 7272 | return mVisibleFrame; |
| 7273 | } |
| 7274 | |
| 7275 | public boolean getGivenInsetsPendingLw() { |
| 7276 | return mGivenInsetsPending; |
| 7277 | } |
| 7278 | |
| 7279 | public Rect getGivenContentInsetsLw() { |
| 7280 | return mGivenContentInsets; |
| 7281 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7283 | public Rect getGivenVisibleInsetsLw() { |
| 7284 | return mGivenVisibleInsets; |
| 7285 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7286 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7287 | public WindowManager.LayoutParams getAttrs() { |
| 7288 | return mAttrs; |
| 7289 | } |
| 7290 | |
| 7291 | public int getSurfaceLayer() { |
| 7292 | return mLayer; |
| 7293 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7294 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7295 | public IApplicationToken getAppToken() { |
| 7296 | return mAppToken != null ? mAppToken.appToken : null; |
| 7297 | } |
| 7298 | |
| 7299 | public boolean hasAppShownWindows() { |
| 7300 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7301 | } |
| 7302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7303 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7304 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7305 | TAG, "Setting animation in " + this + ": " + anim); |
| 7306 | mAnimating = false; |
| 7307 | mLocalAnimating = false; |
| 7308 | mAnimation = anim; |
| 7309 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7310 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7311 | } |
| 7312 | |
| 7313 | public void clearAnimation() { |
| 7314 | if (mAnimation != null) { |
| 7315 | mAnimating = true; |
| 7316 | mLocalAnimating = false; |
| 7317 | mAnimation = null; |
| 7318 | } |
| 7319 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7321 | Surface createSurfaceLocked() { |
| 7322 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7323 | mReportDestroySurface = false; |
| 7324 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | mDrawPending = true; |
| 7326 | mCommitDrawPending = false; |
| 7327 | mReadyToShow = false; |
| 7328 | if (mAppToken != null) { |
| 7329 | mAppToken.allDrawn = false; |
| 7330 | } |
| 7331 | |
| 7332 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 7333 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | flags |= Surface.PUSH_BUFFERS; |
| 7335 | } |
| 7336 | |
| 7337 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7338 | flags |= Surface.SECURE; |
| 7339 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7340 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7341 | TAG, "Creating surface in session " |
| 7342 | + mSession.mSurfaceSession + " window " + this |
| 7343 | + " w=" + mFrame.width() |
| 7344 | + " h=" + mFrame.height() + " format=" |
| 7345 | + mAttrs.format + " flags=" + flags); |
| 7346 | |
| 7347 | int w = mFrame.width(); |
| 7348 | int h = mFrame.height(); |
| 7349 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7350 | // for a scaled surface, we always want the requested |
| 7351 | // size. |
| 7352 | w = mRequestedWidth; |
| 7353 | h = mRequestedHeight; |
| 7354 | } |
| 7355 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7356 | // Something is wrong and SurfaceFlinger will not like this, |
| 7357 | // try to revert to sane values |
| 7358 | if (w <= 0) w = 1; |
| 7359 | if (h <= 0) h = 1; |
| 7360 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7361 | mSurfaceShown = false; |
| 7362 | mSurfaceLayer = 0; |
| 7363 | mSurfaceAlpha = 1; |
| 7364 | mSurfaceX = 0; |
| 7365 | mSurfaceY = 0; |
| 7366 | mSurfaceW = w; |
| 7367 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7368 | try { |
| 7369 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7370 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7371 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7372 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7373 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7374 | + mSurface + " IN SESSION " |
| 7375 | + mSession.mSurfaceSession |
| 7376 | + ": pid=" + mSession.mPid + " format=" |
| 7377 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7378 | + Integer.toHexString(flags) |
| 7379 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7380 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7381 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7382 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7383 | return null; |
| 7384 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7385 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7386 | return null; |
| 7387 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7388 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7389 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7390 | TAG, "Got surface: " + mSurface |
| 7391 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7392 | + ", animLayer=" + mAnimLayer); |
| 7393 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7394 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7395 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 7396 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 7397 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7398 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7399 | } |
| 7400 | Surface.openTransaction(); |
| 7401 | try { |
| 7402 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7403 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7404 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7405 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7406 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7407 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7408 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7409 | mSurface.hide(); |
| 7410 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7411 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7412 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7413 | Surface.SURFACE_DITHER); |
| 7414 | } |
| 7415 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7416 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7417 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7418 | } |
| 7419 | mLastHidden = true; |
| 7420 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7421 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7422 | Surface.closeTransaction(); |
| 7423 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7424 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7425 | TAG, "Created surface " + this); |
| 7426 | } |
| 7427 | return mSurface; |
| 7428 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7429 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7430 | void destroySurfaceLocked() { |
| 7431 | // Window is no longer on-screen, so can no longer receive |
| 7432 | // key events... if we were waiting for it to finish |
| 7433 | // handling a key event, the wait is over! |
| 7434 | mKeyWaiter.finishedKey(mSession, mClient, true, |
| 7435 | KeyWaiter.RETURN_NOTHING); |
| 7436 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7437 | mKeyWaiter.releasePendingTrackballLocked(mSession); |
| 7438 | |
| 7439 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7440 | mAppToken.startingDisplayed = false; |
| 7441 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7443 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7444 | mDrawPending = false; |
| 7445 | mCommitDrawPending = false; |
| 7446 | mReadyToShow = false; |
| 7447 | |
| 7448 | int i = mChildWindows.size(); |
| 7449 | while (i > 0) { |
| 7450 | i--; |
| 7451 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7452 | c.mAttachedHidden = true; |
| 7453 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7454 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7455 | if (mReportDestroySurface) { |
| 7456 | mReportDestroySurface = false; |
| 7457 | mSurfacePendingDestroy = true; |
| 7458 | try { |
| 7459 | mClient.dispatchGetNewSurface(); |
| 7460 | // We'll really destroy on the next time around. |
| 7461 | return; |
| 7462 | } catch (RemoteException e) { |
| 7463 | } |
| 7464 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7466 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7467 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7468 | RuntimeException e = null; |
| 7469 | if (!HIDE_STACK_CRAWLS) { |
| 7470 | e = new RuntimeException(); |
| 7471 | e.fillInStackTrace(); |
| 7472 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7473 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7474 | + mSurface + ", session " + mSession, e); |
| 7475 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7476 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7477 | RuntimeException e = null; |
| 7478 | if (!HIDE_STACK_CRAWLS) { |
| 7479 | e = new RuntimeException(); |
| 7480 | e.fillInStackTrace(); |
| 7481 | } |
| 7482 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7484 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7485 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7486 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7487 | + " surface " + mSurface + " session " + mSession |
| 7488 | + ": " + e.toString()); |
| 7489 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7490 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7491 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7492 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7493 | } |
| 7494 | } |
| 7495 | |
| 7496 | boolean finishDrawingLocked() { |
| 7497 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7498 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7499 | TAG, "finishDrawingLocked: " + mSurface); |
| 7500 | mCommitDrawPending = true; |
| 7501 | mDrawPending = false; |
| 7502 | return true; |
| 7503 | } |
| 7504 | return false; |
| 7505 | } |
| 7506 | |
| 7507 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7508 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7509 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7511 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7512 | } |
| 7513 | mCommitDrawPending = false; |
| 7514 | mReadyToShow = true; |
| 7515 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7516 | final AppWindowToken atoken = mAppToken; |
| 7517 | if (atoken == null || atoken.allDrawn || starting) { |
| 7518 | performShowLocked(); |
| 7519 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7520 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7521 | } |
| 7522 | |
| 7523 | // This must be called while inside a transaction. |
| 7524 | boolean performShowLocked() { |
| 7525 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7526 | RuntimeException e = null; |
| 7527 | if (!HIDE_STACK_CRAWLS) { |
| 7528 | e = new RuntimeException(); |
| 7529 | e.fillInStackTrace(); |
| 7530 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7531 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7532 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7533 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7534 | } |
| 7535 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7536 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7537 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7538 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7539 | + " during animation: policyVis=" + mPolicyVisibility |
| 7540 | + " attHidden=" + mAttachedHidden |
| 7541 | + " tok.hiddenRequested=" |
| 7542 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7543 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7544 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7545 | + " animating=" + mAnimating |
| 7546 | + " tok animating=" |
| 7547 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7548 | if (!showSurfaceRobustlyLocked(this)) { |
| 7549 | return false; |
| 7550 | } |
| 7551 | mLastAlpha = -1; |
| 7552 | mHasDrawn = true; |
| 7553 | mLastHidden = false; |
| 7554 | mReadyToShow = false; |
| 7555 | enableScreenIfNeededLocked(); |
| 7556 | |
| 7557 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7558 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7559 | int i = mChildWindows.size(); |
| 7560 | while (i > 0) { |
| 7561 | i--; |
| 7562 | WindowState c = (WindowState)mChildWindows.get(i); |
| 7563 | if (c.mSurface != null && c.mAttachedHidden) { |
| 7564 | c.mAttachedHidden = false; |
| 7565 | c.performShowLocked(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7566 | // It hadn't been shown, which means layout not |
| 7567 | // performed on it, so now we want to make sure to |
| 7568 | // do a layout. If called from within the transaction |
| 7569 | // loop, this will cause it to restart with a new |
| 7570 | // layout. |
| 7571 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7572 | } |
| 7573 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7575 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7576 | && mAppToken != null) { |
| 7577 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7578 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7579 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7580 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7581 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7583 | // If this initial window is animating, stop it -- we |
| 7584 | // will do an animation to reveal it from behind the |
| 7585 | // starting window, so there is no need for it to also |
| 7586 | // be doing its own stuff. |
| 7587 | if (mAnimation != null) { |
| 7588 | mAnimation = null; |
| 7589 | // Make sure we clean up the animation. |
| 7590 | mAnimating = true; |
| 7591 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7592 | mFinishedStarting.add(mAppToken); |
| 7593 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7594 | } |
| 7595 | mAppToken.updateReportedVisibilityLocked(); |
| 7596 | } |
| 7597 | } |
| 7598 | return true; |
| 7599 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7600 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7601 | // This must be called while inside a transaction. Returns true if |
| 7602 | // there is more animation to run. |
| 7603 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7604 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7605 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7607 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7608 | mHasTransformation = true; |
| 7609 | mHasLocalTransformation = true; |
| 7610 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7611 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7612 | TAG, "Starting animation in " + this + |
| 7613 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7614 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7615 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7616 | mAnimation.setStartTime(currentTime); |
| 7617 | mLocalAnimating = true; |
| 7618 | mAnimating = true; |
| 7619 | } |
| 7620 | mTransformation.clear(); |
| 7621 | final boolean more = mAnimation.getTransformation( |
| 7622 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7623 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7624 | TAG, "Stepped animation in " + this + |
| 7625 | ": more=" + more + ", xform=" + mTransformation); |
| 7626 | if (more) { |
| 7627 | // we're not done! |
| 7628 | return true; |
| 7629 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7630 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7631 | TAG, "Finished animation in " + this + |
| 7632 | " @ " + currentTime); |
| 7633 | mAnimation = null; |
| 7634 | //WindowManagerService.this.dump(); |
| 7635 | } |
| 7636 | mHasLocalTransformation = false; |
| 7637 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7638 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7639 | // When our app token is animating, we kind-of pretend like |
| 7640 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7641 | // part of this check means that we will only do this if |
| 7642 | // our window is not currently exiting, or it is not |
| 7643 | // locally animating itself. The idea being that one that |
| 7644 | // is exiting and doing a local animation should be removed |
| 7645 | // once that animation is done. |
| 7646 | mAnimating = true; |
| 7647 | mHasTransformation = true; |
| 7648 | mTransformation.clear(); |
| 7649 | return false; |
| 7650 | } else if (mHasTransformation) { |
| 7651 | // Little trick to get through the path below to act like |
| 7652 | // we have finished an animation. |
| 7653 | mAnimating = true; |
| 7654 | } else if (isAnimating()) { |
| 7655 | mAnimating = true; |
| 7656 | } |
| 7657 | } else if (mAnimation != null) { |
| 7658 | // If the display is frozen, and there is a pending animation, |
| 7659 | // clear it and make sure we run the cleanup code. |
| 7660 | mAnimating = true; |
| 7661 | mLocalAnimating = true; |
| 7662 | mAnimation = null; |
| 7663 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7664 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7665 | if (!mAnimating && !mLocalAnimating) { |
| 7666 | return false; |
| 7667 | } |
| 7668 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7669 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7670 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7671 | + ", reportedVisible=" |
| 7672 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7674 | mAnimating = false; |
| 7675 | mLocalAnimating = false; |
| 7676 | mAnimation = null; |
| 7677 | mAnimLayer = mLayer; |
| 7678 | if (mIsImWindow) { |
| 7679 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7680 | } else if (mIsWallpaper) { |
| 7681 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7682 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7683 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7684 | + " anim layer: " + mAnimLayer); |
| 7685 | mHasTransformation = false; |
| 7686 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7687 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7688 | if (DEBUG_VISIBILITY) { |
| 7689 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7690 | + mPolicyVisibilityAfterAnim); |
| 7691 | } |
| 7692 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7693 | if (!mPolicyVisibility) { |
| 7694 | if (mCurrentFocus == this) { |
| 7695 | mFocusMayChange = true; |
| 7696 | } |
| 7697 | // Window is no longer visible -- make sure if we were waiting |
| 7698 | // for it to be displayed before enabling the display, that |
| 7699 | // we allow the display to be enabled now. |
| 7700 | enableScreenIfNeededLocked(); |
| 7701 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7702 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | mTransformation.clear(); |
| 7704 | if (mHasDrawn |
| 7705 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7706 | && mAppToken != null |
| 7707 | && mAppToken.firstWindowDrawn |
| 7708 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7709 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7710 | + mToken + ": first real window done animating"); |
| 7711 | mFinishedStarting.add(mAppToken); |
| 7712 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7713 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | finishExit(); |
| 7716 | |
| 7717 | if (mAppToken != null) { |
| 7718 | mAppToken.updateReportedVisibilityLocked(); |
| 7719 | } |
| 7720 | |
| 7721 | return false; |
| 7722 | } |
| 7723 | |
| 7724 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7725 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7726 | TAG, "finishExit in " + this |
| 7727 | + ": exiting=" + mExiting |
| 7728 | + " remove=" + mRemoveOnExit |
| 7729 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7730 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7731 | final int N = mChildWindows.size(); |
| 7732 | for (int i=0; i<N; i++) { |
| 7733 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 7734 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7735 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7736 | if (!mExiting) { |
| 7737 | return; |
| 7738 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7740 | if (isWindowAnimating()) { |
| 7741 | return; |
| 7742 | } |
| 7743 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7744 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7745 | TAG, "Exit animation finished in " + this |
| 7746 | + ": remove=" + mRemoveOnExit); |
| 7747 | if (mSurface != null) { |
| 7748 | mDestroySurface.add(this); |
| 7749 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7750 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7751 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7752 | try { |
| 7753 | mSurface.hide(); |
| 7754 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7755 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7756 | } |
| 7757 | mLastHidden = true; |
| 7758 | mKeyWaiter.releasePendingPointerLocked(mSession); |
| 7759 | } |
| 7760 | mExiting = false; |
| 7761 | if (mRemoveOnExit) { |
| 7762 | mPendingRemove.add(this); |
| 7763 | mRemoveOnExit = false; |
| 7764 | } |
| 7765 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7767 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7768 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7769 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7770 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7771 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7772 | return true; |
| 7773 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7774 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7775 | void computeShownFrameLocked() { |
| 7776 | final boolean selfTransformation = mHasLocalTransformation; |
| 7777 | Transformation attachedTransformation = |
| 7778 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7779 | ? mAttachedWindow.mTransformation : null; |
| 7780 | Transformation appTransformation = |
| 7781 | (mAppToken != null && mAppToken.hasTransformation) |
| 7782 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7783 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7784 | // Wallpapers are animated based on the "real" window they |
| 7785 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7786 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7787 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7788 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7789 | mWallpaperTarget.mAnimation != null && |
| 7790 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7791 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7792 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7793 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7794 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7795 | } |
| 7796 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7797 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7798 | mWallpaperTarget.mAppToken.animation != null && |
| 7799 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7800 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7801 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7802 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7803 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7804 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7805 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7806 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | if (selfTransformation || attachedTransformation != null |
| 7808 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7809 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7810 | final Rect frame = mFrame; |
| 7811 | final float tmpFloats[] = mTmpFloats; |
| 7812 | final Matrix tmpMatrix = mTmpMatrix; |
| 7813 | |
| 7814 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7815 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7816 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7817 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7818 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7819 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7820 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7821 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7822 | } |
| 7823 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7824 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7825 | } |
| 7826 | |
| 7827 | // "convert" it into SurfaceFlinger's format |
| 7828 | // (a 2x2 matrix + an offset) |
| 7829 | // Here we must not transform the position of the surface |
| 7830 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7831 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7832 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7833 | tmpMatrix.getValues(tmpFloats); |
| 7834 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7835 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7836 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7837 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7838 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7839 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | int w = frame.width(); |
| 7841 | int h = frame.height(); |
| 7842 | mShownFrame.set(x, y, x+w, y+h); |
| 7843 | |
| 7844 | // Now set the alpha... but because our current hardware |
| 7845 | // can't do alpha transformation on a non-opaque surface, |
| 7846 | // turn it off if we are running an animation that is also |
| 7847 | // transforming since it is more important to have that |
| 7848 | // animation be smooth. |
| 7849 | mShownAlpha = mAlpha; |
| 7850 | if (!mLimitedAlphaCompositing |
| 7851 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7852 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7853 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7854 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7855 | if (selfTransformation) { |
| 7856 | mShownAlpha *= mTransformation.getAlpha(); |
| 7857 | } |
| 7858 | if (attachedTransformation != null) { |
| 7859 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7860 | } |
| 7861 | if (appTransformation != null) { |
| 7862 | mShownAlpha *= appTransformation.getAlpha(); |
| 7863 | } |
| 7864 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7865 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7866 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7867 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7868 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | TAG, "Continuing animation in " + this + |
| 7870 | ": " + mShownFrame + |
| 7871 | ", alpha=" + mTransformation.getAlpha()); |
| 7872 | return; |
| 7873 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7874 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7875 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7876 | if (mXOffset != 0 || mYOffset != 0) { |
| 7877 | mShownFrame.offset(mXOffset, mYOffset); |
| 7878 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7879 | mShownAlpha = mAlpha; |
| 7880 | mDsDx = 1; |
| 7881 | mDtDx = 0; |
| 7882 | mDsDy = 0; |
| 7883 | mDtDy = 1; |
| 7884 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7886 | /** |
| 7887 | * Is this window visible? It is not visible if there is no |
| 7888 | * surface, or we are in the process of running an exit animation |
| 7889 | * that will remove the surface, or its app token has been hidden. |
| 7890 | */ |
| 7891 | public boolean isVisibleLw() { |
| 7892 | final AppWindowToken atoken = mAppToken; |
| 7893 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7894 | && (atoken == null || !atoken.hiddenRequested) |
| 7895 | && !mExiting && !mDestroying; |
| 7896 | } |
| 7897 | |
| 7898 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7899 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7900 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7901 | * things like window flags that impact the keyguard. |
| 7902 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7903 | * for this "hidden behind keyguard" state rather than overloading |
| 7904 | * mPolicyVisibility. Ungh. |
| 7905 | */ |
| 7906 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7907 | final AppWindowToken atoken = mAppToken; |
| 7908 | return mSurface != null && !mAttachedHidden |
| 7909 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7910 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7911 | && !mExiting && !mDestroying; |
| 7912 | } |
| 7913 | |
| 7914 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7915 | * Is this window visible, ignoring its app token? It is not visible |
| 7916 | * if there is no surface, or we are in the process of running an exit animation |
| 7917 | * that will remove the surface. |
| 7918 | */ |
| 7919 | public boolean isWinVisibleLw() { |
| 7920 | final AppWindowToken atoken = mAppToken; |
| 7921 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7922 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7923 | && !mExiting && !mDestroying; |
| 7924 | } |
| 7925 | |
| 7926 | /** |
| 7927 | * The same as isVisible(), but follows the current hidden state of |
| 7928 | * the associated app token, not the pending requested hidden state. |
| 7929 | */ |
| 7930 | boolean isVisibleNow() { |
| 7931 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7932 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7933 | } |
| 7934 | |
| 7935 | /** |
| 7936 | * Same as isVisible(), but we also count it as visible between the |
| 7937 | * call to IWindowSession.add() and the first relayout(). |
| 7938 | */ |
| 7939 | boolean isVisibleOrAdding() { |
| 7940 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7941 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7942 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7943 | && mPolicyVisibility && !mAttachedHidden |
| 7944 | && (atoken == null || !atoken.hiddenRequested) |
| 7945 | && !mExiting && !mDestroying; |
| 7946 | } |
| 7947 | |
| 7948 | /** |
| 7949 | * Is this window currently on-screen? It is on-screen either if it |
| 7950 | * is visible or it is currently running an animation before no longer |
| 7951 | * being visible. |
| 7952 | */ |
| 7953 | boolean isOnScreen() { |
| 7954 | final AppWindowToken atoken = mAppToken; |
| 7955 | if (atoken != null) { |
| 7956 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7957 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7958 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7959 | } else { |
| 7960 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7961 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7962 | } |
| 7963 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7964 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7965 | /** |
| 7966 | * Like isOnScreen(), but we don't return true if the window is part |
| 7967 | * of a transition that has not yet been started. |
| 7968 | */ |
| 7969 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7970 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7971 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7972 | return false; |
| 7973 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7975 | final boolean animating = atoken != null |
| 7976 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7977 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7978 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7979 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7980 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7981 | } |
| 7982 | |
| 7983 | /** Is the window or its container currently animating? */ |
| 7984 | boolean isAnimating() { |
| 7985 | final WindowState attached = mAttachedWindow; |
| 7986 | final AppWindowToken atoken = mAppToken; |
| 7987 | return mAnimation != null |
| 7988 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7989 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7990 | (atoken.animation != null |
| 7991 | || atoken.inPendingTransaction)); |
| 7992 | } |
| 7993 | |
| 7994 | /** Is this window currently animating? */ |
| 7995 | boolean isWindowAnimating() { |
| 7996 | return mAnimation != null; |
| 7997 | } |
| 7998 | |
| 7999 | /** |
| 8000 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 8001 | * been drawn. |
| 8002 | */ |
| 8003 | public boolean isDisplayedLw() { |
| 8004 | final AppWindowToken atoken = mAppToken; |
| 8005 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8006 | && !mDrawPending && !mCommitDrawPending |
| 8007 | && ((!mAttachedHidden && |
| 8008 | (atoken == null || !atoken.hiddenRequested)) |
| 8009 | || mAnimating); |
| 8010 | } |
| 8011 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8012 | /** |
| 8013 | * Returns true if the window has a surface that it has drawn a |
| 8014 | * complete UI in to. |
| 8015 | */ |
| 8016 | public boolean isDrawnLw() { |
| 8017 | final AppWindowToken atoken = mAppToken; |
| 8018 | return mSurface != null && !mDestroying |
| 8019 | && !mDrawPending && !mCommitDrawPending; |
| 8020 | } |
| 8021 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8022 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 8023 | boolean shownFrame, boolean onlyOpaque) { |
| 8024 | if (mSurface == null) { |
| 8025 | return false; |
| 8026 | } |
| 8027 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 8028 | return false; |
| 8029 | } |
| 8030 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 8031 | return false; |
| 8032 | } |
| 8033 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8034 | |
| 8035 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8036 | return frame.left <= mCompatibleScreenFrame.left && |
| 8037 | frame.top <= mCompatibleScreenFrame.top && |
| 8038 | frame.right >= mCompatibleScreenFrame.right && |
| 8039 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 8040 | } else { |
| 8041 | return frame.left <= 0 && frame.top <= 0 |
| 8042 | && frame.right >= screenWidth |
| 8043 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8044 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8045 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8046 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8047 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8048 | * Return true if the window is opaque and fully drawn. This indicates |
| 8049 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8050 | */ |
| 8051 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8052 | return (mAttrs.format == PixelFormat.OPAQUE |
| 8053 | || mAttrs.type == TYPE_WALLPAPER) |
| 8054 | && mSurface != null && mAnimation == null |
| 8055 | && (mAppToken == null || mAppToken.animation == null) |
| 8056 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8057 | } |
| 8058 | |
| 8059 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 8060 | return |
| 8061 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8062 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 8063 | // only if it's visible |
| 8064 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8065 | // and only if the application fills the compatible screen |
| 8066 | mFrame.left <= mCompatibleScreenFrame.left && |
| 8067 | mFrame.top <= mCompatibleScreenFrame.top && |
| 8068 | mFrame.right >= mCompatibleScreenFrame.right && |
| 8069 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8070 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8071 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8072 | } |
| 8073 | |
| 8074 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 8075 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8076 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8077 | } |
| 8078 | |
| 8079 | void removeLocked() { |
| 8080 | if (mAttachedWindow != null) { |
| 8081 | mAttachedWindow.mChildWindows.remove(this); |
| 8082 | } |
| 8083 | destroySurfaceLocked(); |
| 8084 | mSession.windowRemovedLocked(); |
| 8085 | try { |
| 8086 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8087 | } catch (RuntimeException e) { |
| 8088 | // Ignore if it has already been removed (usually because |
| 8089 | // we are doing this as part of processing a death note.) |
| 8090 | } |
| 8091 | } |
| 8092 | |
| 8093 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8094 | public void binderDied() { |
| 8095 | try { |
| 8096 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8097 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8098 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8099 | if (win != null) { |
| 8100 | removeWindowLocked(mSession, win); |
| 8101 | } |
| 8102 | } |
| 8103 | } catch (IllegalArgumentException ex) { |
| 8104 | // This will happen if the window has already been |
| 8105 | // removed. |
| 8106 | } |
| 8107 | } |
| 8108 | } |
| 8109 | |
| 8110 | /** Returns true if this window desires key events. */ |
| 8111 | public final boolean canReceiveKeys() { |
| 8112 | return isVisibleOrAdding() |
| 8113 | && (mViewVisibility == View.VISIBLE) |
| 8114 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8115 | } |
| 8116 | |
| 8117 | public boolean hasDrawnLw() { |
| 8118 | return mHasDrawn; |
| 8119 | } |
| 8120 | |
| 8121 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8122 | return showLw(doAnimation, true); |
| 8123 | } |
| 8124 | |
| 8125 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8126 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8127 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8129 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8130 | if (doAnimation) { |
| 8131 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8132 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8133 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8134 | doAnimation = false; |
| 8135 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8136 | // Check for the case where we are currently visible and |
| 8137 | // not animating; we do not want to do animation at such a |
| 8138 | // point to become visible when we already are. |
| 8139 | doAnimation = false; |
| 8140 | } |
| 8141 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8142 | mPolicyVisibility = true; |
| 8143 | mPolicyVisibilityAfterAnim = true; |
| 8144 | if (doAnimation) { |
| 8145 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8146 | } |
| 8147 | if (requestAnim) { |
| 8148 | requestAnimationLocked(0); |
| 8149 | } |
| 8150 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8151 | } |
| 8152 | |
| 8153 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8154 | return hideLw(doAnimation, true); |
| 8155 | } |
| 8156 | |
| 8157 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8158 | if (doAnimation) { |
| 8159 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8160 | doAnimation = false; |
| 8161 | } |
| 8162 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8163 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8164 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8165 | if (!current) { |
| 8166 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8167 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8168 | if (doAnimation) { |
| 8169 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8170 | if (mAnimation == null) { |
| 8171 | doAnimation = false; |
| 8172 | } |
| 8173 | } |
| 8174 | if (doAnimation) { |
| 8175 | mPolicyVisibilityAfterAnim = false; |
| 8176 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8177 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8178 | mPolicyVisibilityAfterAnim = false; |
| 8179 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8180 | // Window is no longer visible -- make sure if we were waiting |
| 8181 | // for it to be displayed before enabling the display, that |
| 8182 | // we allow the display to be enabled now. |
| 8183 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8184 | if (mCurrentFocus == this) { |
| 8185 | mFocusMayChange = true; |
| 8186 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8187 | } |
| 8188 | if (requestAnim) { |
| 8189 | requestAnimationLocked(0); |
| 8190 | } |
| 8191 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8192 | } |
| 8193 | |
| 8194 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8195 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8196 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8197 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8198 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8199 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8200 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8201 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8202 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8203 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8204 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8205 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8206 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8207 | } |
| 8208 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8209 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8210 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8211 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8212 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8213 | pw.print("="); pw.print(mAnimLayer); |
| 8214 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8215 | if (mSurface != null) { |
| 8216 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8217 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8218 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8219 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8220 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8221 | pw.print(","); pw.print(mSurfaceY); |
| 8222 | pw.print(") "); pw.print(mSurfaceW); |
| 8223 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8224 | } |
| 8225 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8226 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8227 | if (mAppToken != null) { |
| 8228 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8229 | } |
| 8230 | if (mTargetAppToken != null) { |
| 8231 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8232 | } |
| 8233 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8234 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8235 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8236 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8237 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8238 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8239 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8240 | pw.print(mPolicyVisibility); |
| 8241 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8242 | pw.print(mPolicyVisibilityAfterAnim); |
| 8243 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8244 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8245 | if (!mRelayoutCalled) { |
| 8246 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8247 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8248 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8249 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8250 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8251 | if (mXOffset != 0 || mYOffset != 0) { |
| 8252 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8253 | pw.print(" y="); pw.println(mYOffset); |
| 8254 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8255 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8256 | mGivenContentInsets.printShortString(pw); |
| 8257 | pw.print(" mGivenVisibleInsets="); |
| 8258 | mGivenVisibleInsets.printShortString(pw); |
| 8259 | pw.println(); |
| 8260 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8261 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8262 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8263 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8264 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8265 | pw.print(prefix); pw.print("mShownFrame="); |
| 8266 | mShownFrame.printShortString(pw); |
| 8267 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8268 | pw.println(); |
| 8269 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8270 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8271 | pw.println(); |
| 8272 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8273 | mContainingFrame.printShortString(pw); |
| 8274 | pw.print(" mDisplayFrame="); |
| 8275 | mDisplayFrame.printShortString(pw); |
| 8276 | pw.println(); |
| 8277 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8278 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8279 | pw.println(); |
| 8280 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8281 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8282 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8283 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8284 | pw.println(); |
| 8285 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8286 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8287 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8288 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8289 | } |
| 8290 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8291 | || mAnimation != null) { |
| 8292 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8293 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8294 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8295 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8296 | } |
| 8297 | if (mHasTransformation || mHasLocalTransformation) { |
| 8298 | pw.print(prefix); pw.print("XForm: has="); |
| 8299 | pw.print(mHasTransformation); |
| 8300 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8301 | pw.print(" "); mTransformation.printShortString(pw); |
| 8302 | pw.println(); |
| 8303 | } |
| 8304 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8305 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8306 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8307 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8308 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8309 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8310 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8311 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8312 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8313 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8314 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8315 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8316 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8317 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8318 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8319 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8320 | if (mHScale != 1 || mVScale != 1) { |
| 8321 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8322 | pw.print(" mVScale="); pw.println(mVScale); |
| 8323 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8324 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8325 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8326 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8327 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8328 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8329 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8330 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8331 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | } |
| 8333 | |
| 8334 | @Override |
| 8335 | public String toString() { |
| 8336 | return "Window{" |
| 8337 | + Integer.toHexString(System.identityHashCode(this)) |
| 8338 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 8339 | } |
| 8340 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8342 | // ------------------------------------------------------------- |
| 8343 | // Window Token State |
| 8344 | // ------------------------------------------------------------- |
| 8345 | |
| 8346 | class WindowToken { |
| 8347 | // The actual token. |
| 8348 | final IBinder token; |
| 8349 | |
| 8350 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8351 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8352 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8353 | // Set if this token was explicitly added by a client, so should |
| 8354 | // not be removed when all windows are removed. |
| 8355 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8356 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8357 | // For printing. |
| 8358 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8359 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8360 | // If this is an AppWindowToken, this is non-null. |
| 8361 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8363 | // All of the windows associated with this token. |
| 8364 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8365 | |
| 8366 | // Is key dispatching paused for this token? |
| 8367 | boolean paused = false; |
| 8368 | |
| 8369 | // Should this token's windows be hidden? |
| 8370 | boolean hidden; |
| 8371 | |
| 8372 | // Temporary for finding which tokens no longer have visible windows. |
| 8373 | boolean hasVisible; |
| 8374 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8375 | // Set to true when this token is in a pending transaction where it |
| 8376 | // will be shown. |
| 8377 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8378 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8379 | // Set to true when this token is in a pending transaction where it |
| 8380 | // will be hidden. |
| 8381 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8382 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8383 | // Set to true when this token is in a pending transaction where its |
| 8384 | // windows will be put to the bottom of the list. |
| 8385 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8386 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8387 | // Set to true when this token is in a pending transaction where its |
| 8388 | // windows will be put to the top of the list. |
| 8389 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8390 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8391 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8392 | token = _token; |
| 8393 | windowType = type; |
| 8394 | explicit = _explicit; |
| 8395 | } |
| 8396 | |
| 8397 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8398 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8399 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8400 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8401 | pw.print(" hidden="); pw.print(hidden); |
| 8402 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8403 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8404 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8405 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8406 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8407 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8408 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8409 | } |
| 8410 | |
| 8411 | @Override |
| 8412 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8413 | if (stringName == null) { |
| 8414 | StringBuilder sb = new StringBuilder(); |
| 8415 | sb.append("WindowToken{"); |
| 8416 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8417 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8418 | stringName = sb.toString(); |
| 8419 | } |
| 8420 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8421 | } |
| 8422 | }; |
| 8423 | |
| 8424 | class AppWindowToken extends WindowToken { |
| 8425 | // Non-null only for application tokens. |
| 8426 | final IApplicationToken appToken; |
| 8427 | |
| 8428 | // All of the windows and child windows that are included in this |
| 8429 | // application token. Note this list is NOT sorted! |
| 8430 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8431 | |
| 8432 | int groupId = -1; |
| 8433 | boolean appFullscreen; |
| 8434 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8436 | // These are used for determining when all windows associated with |
| 8437 | // an activity have been drawn, so they can be made visible together |
| 8438 | // at the same time. |
| 8439 | int lastTransactionSequence = mTransactionSequence-1; |
| 8440 | int numInterestingWindows; |
| 8441 | int numDrawnWindows; |
| 8442 | boolean inPendingTransaction; |
| 8443 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8444 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8445 | // Is this token going to be hidden in a little while? If so, it |
| 8446 | // won't be taken into account for setting the screen orientation. |
| 8447 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8448 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8449 | // Is this window's surface needed? This is almost like hidden, except |
| 8450 | // it will sometimes be true a little earlier: when the token has |
| 8451 | // been shown, but is still waiting for its app transition to execute |
| 8452 | // before making its windows shown. |
| 8453 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8454 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8455 | // Have we told the window clients to hide themselves? |
| 8456 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8457 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8458 | // Last visibility state we reported to the app token. |
| 8459 | boolean reportedVisible; |
| 8460 | |
| 8461 | // Set to true when the token has been removed from the window mgr. |
| 8462 | boolean removed; |
| 8463 | |
| 8464 | // Have we been asked to have this token keep the screen frozen? |
| 8465 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8466 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8467 | boolean animating; |
| 8468 | Animation animation; |
| 8469 | boolean hasTransformation; |
| 8470 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8472 | // Offset to the window of all layers in the token, for use by |
| 8473 | // AppWindowToken animations. |
| 8474 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8475 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8476 | // Information about an application starting window if displayed. |
| 8477 | StartingData startingData; |
| 8478 | WindowState startingWindow; |
| 8479 | View startingView; |
| 8480 | boolean startingDisplayed; |
| 8481 | boolean startingMoved; |
| 8482 | boolean firstWindowDrawn; |
| 8483 | |
| 8484 | AppWindowToken(IApplicationToken _token) { |
| 8485 | super(_token.asBinder(), |
| 8486 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8487 | appWindowToken = this; |
| 8488 | appToken = _token; |
| 8489 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8490 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8491 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8492 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | TAG, "Setting animation in " + this + ": " + anim); |
| 8494 | animation = anim; |
| 8495 | animating = false; |
| 8496 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8497 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8498 | int zorder = anim.getZAdjustment(); |
| 8499 | int adj = 0; |
| 8500 | if (zorder == Animation.ZORDER_TOP) { |
| 8501 | adj = TYPE_LAYER_OFFSET; |
| 8502 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8503 | adj = -TYPE_LAYER_OFFSET; |
| 8504 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8506 | if (animLayerAdjustment != adj) { |
| 8507 | animLayerAdjustment = adj; |
| 8508 | updateLayers(); |
| 8509 | } |
| 8510 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8511 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8512 | public void setDummyAnimation() { |
| 8513 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8514 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8515 | TAG, "Setting dummy animation in " + this); |
| 8516 | animation = sDummyAnimation; |
| 8517 | } |
| 8518 | } |
| 8519 | |
| 8520 | public void clearAnimation() { |
| 8521 | if (animation != null) { |
| 8522 | animation = null; |
| 8523 | animating = true; |
| 8524 | } |
| 8525 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8527 | void updateLayers() { |
| 8528 | final int N = allAppWindows.size(); |
| 8529 | final int adj = animLayerAdjustment; |
| 8530 | for (int i=0; i<N; i++) { |
| 8531 | WindowState w = allAppWindows.get(i); |
| 8532 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8533 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8534 | + w.mAnimLayer); |
| 8535 | if (w == mInputMethodTarget) { |
| 8536 | setInputMethodAnimLayerAdjustment(adj); |
| 8537 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8538 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8539 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8540 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8541 | } |
| 8542 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8543 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8544 | void sendAppVisibilityToClients() { |
| 8545 | final int N = allAppWindows.size(); |
| 8546 | for (int i=0; i<N; i++) { |
| 8547 | WindowState win = allAppWindows.get(i); |
| 8548 | if (win == startingWindow && clientHidden) { |
| 8549 | // Don't hide the starting window. |
| 8550 | continue; |
| 8551 | } |
| 8552 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8553 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8554 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8555 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8556 | } catch (RemoteException e) { |
| 8557 | } |
| 8558 | } |
| 8559 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | void showAllWindowsLocked() { |
| 8562 | final int NW = allAppWindows.size(); |
| 8563 | for (int i=0; i<NW; i++) { |
| 8564 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8565 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8566 | "performing show on: " + w); |
| 8567 | w.performShowLocked(); |
| 8568 | } |
| 8569 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8571 | // This must be called while inside a transaction. |
| 8572 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8573 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8574 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8575 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8576 | if (animation == sDummyAnimation) { |
| 8577 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8578 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8579 | // when it is really time to animate, this will be set to |
| 8580 | // a real animation and the next call will execute normally. |
| 8581 | return false; |
| 8582 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8583 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8584 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8585 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8586 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8587 | TAG, "Starting animation in " + this + |
| 8588 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8589 | + " scale=" + mTransitionAnimationScale |
| 8590 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8591 | animation.initialize(dw, dh, dw, dh); |
| 8592 | animation.setStartTime(currentTime); |
| 8593 | animating = true; |
| 8594 | } |
| 8595 | transformation.clear(); |
| 8596 | final boolean more = animation.getTransformation( |
| 8597 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8598 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8599 | TAG, "Stepped animation in " + this + |
| 8600 | ": more=" + more + ", xform=" + transformation); |
| 8601 | if (more) { |
| 8602 | // we're done! |
| 8603 | hasTransformation = true; |
| 8604 | return true; |
| 8605 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8606 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8607 | TAG, "Finished animation in " + this + |
| 8608 | " @ " + currentTime); |
| 8609 | animation = null; |
| 8610 | } |
| 8611 | } else if (animation != null) { |
| 8612 | // If the display is frozen, and there is a pending animation, |
| 8613 | // clear it and make sure we run the cleanup code. |
| 8614 | animating = true; |
| 8615 | animation = null; |
| 8616 | } |
| 8617 | |
| 8618 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8619 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | if (!animating) { |
| 8621 | return false; |
| 8622 | } |
| 8623 | |
| 8624 | clearAnimation(); |
| 8625 | animating = false; |
| 8626 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8627 | moveInputMethodWindowsIfNeededLocked(true); |
| 8628 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8629 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8630 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8631 | TAG, "Animation done in " + this |
| 8632 | + ": reportedVisible=" + reportedVisible); |
| 8633 | |
| 8634 | transformation.clear(); |
| 8635 | if (animLayerAdjustment != 0) { |
| 8636 | animLayerAdjustment = 0; |
| 8637 | updateLayers(); |
| 8638 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8639 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8640 | final int N = windows.size(); |
| 8641 | for (int i=0; i<N; i++) { |
| 8642 | ((WindowState)windows.get(i)).finishExit(); |
| 8643 | } |
| 8644 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8646 | return false; |
| 8647 | } |
| 8648 | |
| 8649 | void updateReportedVisibilityLocked() { |
| 8650 | if (appToken == null) { |
| 8651 | return; |
| 8652 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8653 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8654 | int numInteresting = 0; |
| 8655 | int numVisible = 0; |
| 8656 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8657 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8658 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8659 | final int N = allAppWindows.size(); |
| 8660 | for (int i=0; i<N; i++) { |
| 8661 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8662 | if (win == startingWindow || win.mAppFreezing |
| 8663 | || win.mViewVisibility != View.VISIBLE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8664 | continue; |
| 8665 | } |
| 8666 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8667 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8668 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8669 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8670 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8671 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8672 | + " pv=" + win.mPolicyVisibility |
| 8673 | + " dp=" + win.mDrawPending |
| 8674 | + " cdp=" + win.mCommitDrawPending |
| 8675 | + " ah=" + win.mAttachedHidden |
| 8676 | + " th=" |
| 8677 | + (win.mAppToken != null |
| 8678 | ? win.mAppToken.hiddenRequested : false) |
| 8679 | + " a=" + win.mAnimating); |
| 8680 | } |
| 8681 | } |
| 8682 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8683 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8684 | if (!win.isAnimating()) { |
| 8685 | numVisible++; |
| 8686 | } |
| 8687 | nowGone = false; |
| 8688 | } else if (win.isAnimating()) { |
| 8689 | nowGone = false; |
| 8690 | } |
| 8691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8693 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8694 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8695 | + numInteresting + " visible=" + numVisible); |
| 8696 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8697 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8698 | TAG, "Visibility changed in " + this |
| 8699 | + ": vis=" + nowVisible); |
| 8700 | reportedVisible = nowVisible; |
| 8701 | Message m = mH.obtainMessage( |
| 8702 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8703 | nowVisible ? 1 : 0, |
| 8704 | nowGone ? 1 : 0, |
| 8705 | this); |
| 8706 | mH.sendMessage(m); |
| 8707 | } |
| 8708 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8709 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8710 | WindowState findMainWindow() { |
| 8711 | int j = windows.size(); |
| 8712 | while (j > 0) { |
| 8713 | j--; |
| 8714 | WindowState win = windows.get(j); |
| 8715 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8716 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8717 | return win; |
| 8718 | } |
| 8719 | } |
| 8720 | return null; |
| 8721 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8722 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8723 | void dump(PrintWriter pw, String prefix) { |
| 8724 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8725 | if (appToken != null) { |
| 8726 | pw.print(prefix); pw.println("app=true"); |
| 8727 | } |
| 8728 | if (allAppWindows.size() > 0) { |
| 8729 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8730 | } |
| 8731 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8732 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8733 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8734 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8735 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8736 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8737 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8738 | if (paused || freezingScreen) { |
| 8739 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8740 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8741 | } |
| 8742 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8743 | || inPendingTransaction || allDrawn) { |
| 8744 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8745 | pw.print(numInterestingWindows); |
| 8746 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8747 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8748 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8749 | } |
| 8750 | if (animating || animation != null) { |
| 8751 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8752 | pw.print(" animation="); pw.println(animation); |
| 8753 | } |
| 8754 | if (animLayerAdjustment != 0) { |
| 8755 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8756 | } |
| 8757 | if (hasTransformation) { |
| 8758 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8759 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8760 | pw.println(); |
| 8761 | } |
| 8762 | if (startingData != null || removed || firstWindowDrawn) { |
| 8763 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8764 | pw.print(" removed="); pw.print(removed); |
| 8765 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8766 | } |
| 8767 | if (startingWindow != null || startingView != null |
| 8768 | || startingDisplayed || startingMoved) { |
| 8769 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8770 | pw.print(" startingView="); pw.print(startingView); |
| 8771 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8772 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8773 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8774 | } |
| 8775 | |
| 8776 | @Override |
| 8777 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8778 | if (stringName == null) { |
| 8779 | StringBuilder sb = new StringBuilder(); |
| 8780 | sb.append("AppWindowToken{"); |
| 8781 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8782 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8783 | stringName = sb.toString(); |
| 8784 | } |
| 8785 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8786 | } |
| 8787 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8789 | // ------------------------------------------------------------- |
| 8790 | // DummyAnimation |
| 8791 | // ------------------------------------------------------------- |
| 8792 | |
| 8793 | // This is an animation that does nothing: it just immediately finishes |
| 8794 | // itself every time it is called. It is used as a stub animation in cases |
| 8795 | // where we want to synchronize multiple things that may be animating. |
| 8796 | static final class DummyAnimation extends Animation { |
| 8797 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8798 | return false; |
| 8799 | } |
| 8800 | } |
| 8801 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8802 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8803 | // ------------------------------------------------------------- |
| 8804 | // Async Handler |
| 8805 | // ------------------------------------------------------------- |
| 8806 | |
| 8807 | static final class StartingData { |
| 8808 | final String pkg; |
| 8809 | final int theme; |
| 8810 | final CharSequence nonLocalizedLabel; |
| 8811 | final int labelRes; |
| 8812 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8814 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8815 | int _labelRes, int _icon) { |
| 8816 | pkg = _pkg; |
| 8817 | theme = _theme; |
| 8818 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8819 | labelRes = _labelRes; |
| 8820 | icon = _icon; |
| 8821 | } |
| 8822 | } |
| 8823 | |
| 8824 | private final class H extends Handler { |
| 8825 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8826 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8827 | public static final int ANIMATE = 4; |
| 8828 | public static final int ADD_STARTING = 5; |
| 8829 | public static final int REMOVE_STARTING = 6; |
| 8830 | public static final int FINISHED_STARTING = 7; |
| 8831 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8832 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8833 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8834 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8835 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8836 | public static final int FORCE_GC = 15; |
| 8837 | public static final int ENABLE_SCREEN = 16; |
| 8838 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8839 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8840 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8841 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8843 | public H() { |
| 8844 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8845 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8846 | @Override |
| 8847 | public void handleMessage(Message msg) { |
| 8848 | switch (msg.what) { |
| 8849 | case REPORT_FOCUS_CHANGE: { |
| 8850 | WindowState lastFocus; |
| 8851 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8852 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8853 | synchronized(mWindowMap) { |
| 8854 | lastFocus = mLastFocus; |
| 8855 | newFocus = mCurrentFocus; |
| 8856 | if (lastFocus == newFocus) { |
| 8857 | // Focus is not changing, so nothing to do. |
| 8858 | return; |
| 8859 | } |
| 8860 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8861 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8862 | // + " to " + newFocus); |
| 8863 | if (newFocus != null && lastFocus != null |
| 8864 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8865 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8866 | mLosingFocus.add(lastFocus); |
| 8867 | lastFocus = null; |
| 8868 | } |
| 8869 | } |
| 8870 | |
| 8871 | if (lastFocus != newFocus) { |
| 8872 | //System.out.println("Changing focus from " + lastFocus |
| 8873 | // + " to " + newFocus); |
| 8874 | if (newFocus != null) { |
| 8875 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8876 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8877 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8878 | } catch (RemoteException e) { |
| 8879 | // Ignore if process has died. |
| 8880 | } |
| 8881 | } |
| 8882 | |
| 8883 | if (lastFocus != null) { |
| 8884 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8885 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8886 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8887 | } catch (RemoteException e) { |
| 8888 | // Ignore if process has died. |
| 8889 | } |
| 8890 | } |
| 8891 | } |
| 8892 | } break; |
| 8893 | |
| 8894 | case REPORT_LOSING_FOCUS: { |
| 8895 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8897 | synchronized(mWindowMap) { |
| 8898 | losers = mLosingFocus; |
| 8899 | mLosingFocus = new ArrayList<WindowState>(); |
| 8900 | } |
| 8901 | |
| 8902 | final int N = losers.size(); |
| 8903 | for (int i=0; i<N; i++) { |
| 8904 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8905 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8906 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8907 | } catch (RemoteException e) { |
| 8908 | // Ignore if process has died. |
| 8909 | } |
| 8910 | } |
| 8911 | } break; |
| 8912 | |
| 8913 | case ANIMATE: { |
| 8914 | synchronized(mWindowMap) { |
| 8915 | mAnimationPending = false; |
| 8916 | performLayoutAndPlaceSurfacesLocked(); |
| 8917 | } |
| 8918 | } break; |
| 8919 | |
| 8920 | case ADD_STARTING: { |
| 8921 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8922 | final StartingData sd = wtoken.startingData; |
| 8923 | |
| 8924 | if (sd == null) { |
| 8925 | // Animation has been canceled... do nothing. |
| 8926 | return; |
| 8927 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8928 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8929 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8930 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8932 | View view = null; |
| 8933 | try { |
| 8934 | view = mPolicy.addStartingWindow( |
| 8935 | wtoken.token, sd.pkg, |
| 8936 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8937 | sd.icon); |
| 8938 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8939 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8940 | } |
| 8941 | |
| 8942 | if (view != null) { |
| 8943 | boolean abort = false; |
| 8944 | |
| 8945 | synchronized(mWindowMap) { |
| 8946 | if (wtoken.removed || wtoken.startingData == null) { |
| 8947 | // If the window was successfully added, then |
| 8948 | // we need to remove it. |
| 8949 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8950 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8951 | "Aborted starting " + wtoken |
| 8952 | + ": removed=" + wtoken.removed |
| 8953 | + " startingData=" + wtoken.startingData); |
| 8954 | wtoken.startingWindow = null; |
| 8955 | wtoken.startingData = null; |
| 8956 | abort = true; |
| 8957 | } |
| 8958 | } else { |
| 8959 | wtoken.startingView = view; |
| 8960 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8961 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8962 | "Added starting " + wtoken |
| 8963 | + ": startingWindow=" |
| 8964 | + wtoken.startingWindow + " startingView=" |
| 8965 | + wtoken.startingView); |
| 8966 | } |
| 8967 | |
| 8968 | if (abort) { |
| 8969 | try { |
| 8970 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8971 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8972 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8973 | } |
| 8974 | } |
| 8975 | } |
| 8976 | } break; |
| 8977 | |
| 8978 | case REMOVE_STARTING: { |
| 8979 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8980 | IBinder token = null; |
| 8981 | View view = null; |
| 8982 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8983 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8984 | + wtoken + ": startingWindow=" |
| 8985 | + wtoken.startingWindow + " startingView=" |
| 8986 | + wtoken.startingView); |
| 8987 | if (wtoken.startingWindow != null) { |
| 8988 | view = wtoken.startingView; |
| 8989 | token = wtoken.token; |
| 8990 | wtoken.startingData = null; |
| 8991 | wtoken.startingView = null; |
| 8992 | wtoken.startingWindow = null; |
| 8993 | } |
| 8994 | } |
| 8995 | if (view != null) { |
| 8996 | try { |
| 8997 | mPolicy.removeStartingWindow(token, view); |
| 8998 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8999 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | } |
| 9001 | } |
| 9002 | } break; |
| 9003 | |
| 9004 | case FINISHED_STARTING: { |
| 9005 | IBinder token = null; |
| 9006 | View view = null; |
| 9007 | while (true) { |
| 9008 | synchronized (mWindowMap) { |
| 9009 | final int N = mFinishedStarting.size(); |
| 9010 | if (N <= 0) { |
| 9011 | break; |
| 9012 | } |
| 9013 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9014 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9015 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9016 | "Finished starting " + wtoken |
| 9017 | + ": startingWindow=" + wtoken.startingWindow |
| 9018 | + " startingView=" + wtoken.startingView); |
| 9019 | |
| 9020 | if (wtoken.startingWindow == null) { |
| 9021 | continue; |
| 9022 | } |
| 9023 | |
| 9024 | view = wtoken.startingView; |
| 9025 | token = wtoken.token; |
| 9026 | wtoken.startingData = null; |
| 9027 | wtoken.startingView = null; |
| 9028 | wtoken.startingWindow = null; |
| 9029 | } |
| 9030 | |
| 9031 | try { |
| 9032 | mPolicy.removeStartingWindow(token, view); |
| 9033 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9034 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9035 | } |
| 9036 | } |
| 9037 | } break; |
| 9038 | |
| 9039 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9040 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9041 | |
| 9042 | boolean nowVisible = msg.arg1 != 0; |
| 9043 | boolean nowGone = msg.arg2 != 0; |
| 9044 | |
| 9045 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9046 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9047 | TAG, "Reporting visible in " + wtoken |
| 9048 | + " visible=" + nowVisible |
| 9049 | + " gone=" + nowGone); |
| 9050 | if (nowVisible) { |
| 9051 | wtoken.appToken.windowsVisible(); |
| 9052 | } else { |
| 9053 | wtoken.appToken.windowsGone(); |
| 9054 | } |
| 9055 | } catch (RemoteException ex) { |
| 9056 | } |
| 9057 | } break; |
| 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 | case WINDOW_FREEZE_TIMEOUT: { |
| 9060 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9061 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9062 | int i = mWindows.size(); |
| 9063 | while (i > 0) { |
| 9064 | i--; |
| 9065 | WindowState w = (WindowState)mWindows.get(i); |
| 9066 | if (w.mOrientationChanging) { |
| 9067 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9068 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9069 | } |
| 9070 | } |
| 9071 | performLayoutAndPlaceSurfacesLocked(); |
| 9072 | } |
| 9073 | break; |
| 9074 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9075 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9076 | case HOLD_SCREEN_CHANGED: { |
| 9077 | Session oldHold; |
| 9078 | Session newHold; |
| 9079 | synchronized (mWindowMap) { |
| 9080 | oldHold = mLastReportedHold; |
| 9081 | newHold = (Session)msg.obj; |
| 9082 | mLastReportedHold = newHold; |
| 9083 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9084 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9085 | if (oldHold != newHold) { |
| 9086 | try { |
| 9087 | if (oldHold != null) { |
| 9088 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 9089 | "window", |
| 9090 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9091 | } |
| 9092 | if (newHold != null) { |
| 9093 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 9094 | "window", |
| 9095 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9096 | } |
| 9097 | } catch (RemoteException e) { |
| 9098 | } |
| 9099 | } |
| 9100 | break; |
| 9101 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9102 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9103 | case APP_TRANSITION_TIMEOUT: { |
| 9104 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9105 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9106 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9107 | "*** APP TRANSITION TIMEOUT"); |
| 9108 | mAppTransitionReady = true; |
| 9109 | mAppTransitionTimeout = true; |
| 9110 | performLayoutAndPlaceSurfacesLocked(); |
| 9111 | } |
| 9112 | } |
| 9113 | break; |
| 9114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9116 | case PERSIST_ANIMATION_SCALE: { |
| 9117 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9118 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9119 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9120 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9121 | break; |
| 9122 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | case FORCE_GC: { |
| 9125 | synchronized(mWindowMap) { |
| 9126 | if (mAnimationPending) { |
| 9127 | // If we are animating, don't do the gc now but |
| 9128 | // delay a bit so we don't interrupt the animation. |
| 9129 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9130 | 2000); |
| 9131 | return; |
| 9132 | } |
| 9133 | // If we are currently rotating the display, it will |
| 9134 | // schedule a new message when done. |
| 9135 | if (mDisplayFrozen) { |
| 9136 | return; |
| 9137 | } |
| 9138 | mFreezeGcPending = 0; |
| 9139 | } |
| 9140 | Runtime.getRuntime().gc(); |
| 9141 | break; |
| 9142 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9143 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9144 | case ENABLE_SCREEN: { |
| 9145 | performEnableScreen(); |
| 9146 | break; |
| 9147 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9148 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9149 | case APP_FREEZE_TIMEOUT: { |
| 9150 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9151 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | int i = mAppTokens.size(); |
| 9153 | while (i > 0) { |
| 9154 | i--; |
| 9155 | AppWindowToken tok = mAppTokens.get(i); |
| 9156 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9157 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9158 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9159 | } |
| 9160 | } |
| 9161 | } |
| 9162 | break; |
| 9163 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9164 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9165 | case SEND_NEW_CONFIGURATION: { |
| 9166 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9167 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9168 | break; |
| 9169 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9171 | } |
| 9172 | } |
| 9173 | } |
| 9174 | |
| 9175 | // ------------------------------------------------------------- |
| 9176 | // IWindowManager API |
| 9177 | // ------------------------------------------------------------- |
| 9178 | |
| 9179 | public IWindowSession openSession(IInputMethodClient client, |
| 9180 | IInputContext inputContext) { |
| 9181 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9182 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| 9183 | return new Session(client, inputContext); |
| 9184 | } |
| 9185 | |
| 9186 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9187 | synchronized (mWindowMap) { |
| 9188 | // The focus for the client is the window immediately below |
| 9189 | // where we would place the input method window. |
| 9190 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9191 | WindowState imFocus; |
| 9192 | if (idx > 0) { |
| 9193 | imFocus = (WindowState)mWindows.get(idx-1); |
| 9194 | if (imFocus != null) { |
| 9195 | if (imFocus.mSession.mClient != null && |
| 9196 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9197 | return true; |
| 9198 | } |
| 9199 | } |
| 9200 | } |
| 9201 | } |
| 9202 | return false; |
| 9203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9205 | // ------------------------------------------------------------- |
| 9206 | // Internals |
| 9207 | // ------------------------------------------------------------- |
| 9208 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9209 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9210 | boolean throwOnError) { |
| 9211 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9212 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9213 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9214 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9215 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9216 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9217 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | TAG, "Looking up client " + client + ": " + win); |
| 9219 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9220 | RuntimeException ex = new IllegalArgumentException( |
| 9221 | "Requested window " + client + " does not exist"); |
| 9222 | if (throwOnError) { |
| 9223 | throw ex; |
| 9224 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9225 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9226 | return null; |
| 9227 | } |
| 9228 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9229 | RuntimeException ex = new IllegalArgumentException( |
| 9230 | "Requested window " + client + " is in session " + |
| 9231 | win.mSession + ", not " + session); |
| 9232 | if (throwOnError) { |
| 9233 | throw ex; |
| 9234 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9235 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9236 | return null; |
| 9237 | } |
| 9238 | |
| 9239 | return win; |
| 9240 | } |
| 9241 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9242 | final void rebuildAppWindowListLocked() { |
| 9243 | int NW = mWindows.size(); |
| 9244 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9245 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9246 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9247 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9248 | // First remove all existing app windows. |
| 9249 | i=0; |
| 9250 | while (i < NW) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9251 | WindowState w = (WindowState)mWindows.get(i); |
| 9252 | if (w.mAppToken != null) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9253 | WindowState win = (WindowState)mWindows.remove(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9254 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9255 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9256 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9257 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9258 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9259 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9260 | && lastWallpaper == i-1) { |
| 9261 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9262 | } |
| 9263 | i++; |
| 9264 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9265 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9266 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9267 | // so skip them before adding app tokens. |
| 9268 | lastWallpaper++; |
| 9269 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9270 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9271 | // First add all of the exiting app tokens... these are no longer |
| 9272 | // in the main app list, but still have windows shown. We put them |
| 9273 | // in the back because now that the animation is over we no longer |
| 9274 | // will care about them. |
| 9275 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9276 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9277 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9278 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9279 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9280 | // And add in the still active app tokens in Z order. |
| 9281 | NT = mAppTokens.size(); |
| 9282 | for (int j=0; j<NT; j++) { |
| 9283 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9284 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9285 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9286 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9287 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9288 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9289 | + " windows but added " + i); |
| 9290 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9291 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9292 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9293 | private final void assignLayersLocked() { |
| 9294 | int N = mWindows.size(); |
| 9295 | int curBaseLayer = 0; |
| 9296 | int curLayer = 0; |
| 9297 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9299 | for (i=0; i<N; i++) { |
| 9300 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9301 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9302 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9303 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9304 | w.mLayer = curLayer; |
| 9305 | } else { |
| 9306 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9307 | w.mLayer = curLayer; |
| 9308 | } |
| 9309 | if (w.mTargetAppToken != null) { |
| 9310 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9311 | } else if (w.mAppToken != null) { |
| 9312 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9313 | } else { |
| 9314 | w.mAnimLayer = w.mLayer; |
| 9315 | } |
| 9316 | if (w.mIsImWindow) { |
| 9317 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9318 | } else if (w.mIsWallpaper) { |
| 9319 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9321 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9322 | + w.mAnimLayer); |
| 9323 | //System.out.println( |
| 9324 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9325 | } |
| 9326 | } |
| 9327 | |
| 9328 | private boolean mInLayout = false; |
| 9329 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9330 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9331 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9332 | throw new RuntimeException("Recursive call!"); |
| 9333 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9334 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9335 | return; |
| 9336 | } |
| 9337 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9338 | if (mWaitingForConfig) { |
| 9339 | // Our configuration has changed (most likely rotation), but we |
| 9340 | // don't yet have the complete configuration to report to |
| 9341 | // applications. Don't do any window layout until we have it. |
| 9342 | return; |
| 9343 | } |
| 9344 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | boolean recoveringMemory = false; |
| 9346 | if (mForceRemoves != null) { |
| 9347 | recoveringMemory = true; |
| 9348 | // Wait a little it for things to settle down, and off we go. |
| 9349 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9350 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9351 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9352 | removeWindowInnerLocked(ws.mSession, ws); |
| 9353 | } |
| 9354 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9355 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9356 | Object tmp = new Object(); |
| 9357 | synchronized (tmp) { |
| 9358 | try { |
| 9359 | tmp.wait(250); |
| 9360 | } catch (InterruptedException e) { |
| 9361 | } |
| 9362 | } |
| 9363 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9365 | mInLayout = true; |
| 9366 | try { |
| 9367 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| 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 | int i = mPendingRemove.size()-1; |
| 9370 | if (i >= 0) { |
| 9371 | while (i >= 0) { |
| 9372 | WindowState w = mPendingRemove.get(i); |
| 9373 | removeWindowInnerLocked(w.mSession, w); |
| 9374 | i--; |
| 9375 | } |
| 9376 | mPendingRemove.clear(); |
| 9377 | |
| 9378 | mInLayout = false; |
| 9379 | assignLayersLocked(); |
| 9380 | mLayoutNeeded = true; |
| 9381 | performLayoutAndPlaceSurfacesLocked(); |
| 9382 | |
| 9383 | } else { |
| 9384 | mInLayout = false; |
| 9385 | if (mLayoutNeeded) { |
| 9386 | requestAnimationLocked(0); |
| 9387 | } |
| 9388 | } |
| 9389 | } catch (RuntimeException e) { |
| 9390 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9391 | Slog.e(TAG, "Unhandled exception while layout out windows", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9392 | } |
| 9393 | } |
| 9394 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9395 | private final int performLayoutLockedInner() { |
| 9396 | if (!mLayoutNeeded) { |
| 9397 | return 0; |
| 9398 | } |
| 9399 | |
| 9400 | mLayoutNeeded = false; |
| 9401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9402 | final int dw = mDisplay.getWidth(); |
| 9403 | final int dh = mDisplay.getHeight(); |
| 9404 | |
| 9405 | final int N = mWindows.size(); |
| 9406 | int i; |
| 9407 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9408 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9409 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9410 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9411 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9412 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9413 | int seq = mLayoutSeq+1; |
| 9414 | if (seq < 0) seq = 0; |
| 9415 | mLayoutSeq = seq; |
| 9416 | |
| 9417 | // First perform layout of any root windows (not attached |
| 9418 | // to another window). |
| 9419 | int topAttached = -1; |
| 9420 | for (i = N-1; i >= 0; i--) { |
| 9421 | WindowState win = (WindowState) mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9422 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9423 | // Don't do layout of a window if it is not visible, or |
| 9424 | // soon won't be visible, to avoid wasting time and funky |
| 9425 | // changes while a window is animating away. |
| 9426 | final AppWindowToken atoken = win.mAppToken; |
| 9427 | final boolean gone = win.mViewVisibility == View.GONE |
| 9428 | || !win.mRelayoutCalled |
| 9429 | || win.mRootToken.hidden |
| 9430 | || (atoken != null && atoken.hiddenRequested) |
| 9431 | || win.mAttachedHidden |
| 9432 | || win.mExiting || win.mDestroying; |
| 9433 | |
| 9434 | if (!win.mLayoutAttached) { |
| 9435 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 9436 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9437 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9438 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 9439 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9440 | + win.mRelayoutCalled + " hidden=" |
| 9441 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9442 | + (atoken != null && atoken.hiddenRequested) |
| 9443 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9444 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9445 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9446 | // If this view is GONE, then skip it -- keep the current |
| 9447 | // frame, and let the caller know so they can ignore it |
| 9448 | // if they want. (We do the normal layout for INVISIBLE |
| 9449 | // windows, since that means "perform layout as normal, |
| 9450 | // just don't display"). |
| 9451 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9452 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9453 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9454 | win.mLayoutSeq = seq; |
| 9455 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9456 | + win.mFrame + " mContainingFrame=" |
| 9457 | + win.mContainingFrame + " mDisplayFrame=" |
| 9458 | + win.mDisplayFrame); |
| 9459 | } else { |
| 9460 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9461 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9462 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9463 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9464 | |
| 9465 | // Now perform layout of attached windows, which usually |
| 9466 | // depend on the position of the window they are attached to. |
| 9467 | // XXX does not deal with windows that are attached to windows |
| 9468 | // that are themselves attached. |
| 9469 | for (i = topAttached; i >= 0; i--) { |
| 9470 | WindowState win = (WindowState) mWindows.get(i); |
| 9471 | |
| 9472 | // If this view is GONE, then skip it -- keep the current |
| 9473 | // frame, and let the caller know so they can ignore it |
| 9474 | // if they want. (We do the normal layout for INVISIBLE |
| 9475 | // windows, since that means "perform layout as normal, |
| 9476 | // just don't display"). |
| 9477 | if (win.mLayoutAttached) { |
| 9478 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9479 | + " mHaveFrame=" + win.mHaveFrame |
| 9480 | + " mViewVisibility=" + win.mViewVisibility |
| 9481 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 9482 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9483 | || !win.mHaveFrame) { |
| 9484 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9485 | win.mLayoutSeq = seq; |
| 9486 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9487 | + win.mFrame + " mContainingFrame=" |
| 9488 | + win.mContainingFrame + " mDisplayFrame=" |
| 9489 | + win.mDisplayFrame); |
| 9490 | } |
| 9491 | } |
| 9492 | } |
| 9493 | |
| 9494 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9495 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9496 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9497 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9498 | boolean recoveringMemory) { |
| 9499 | final long currentTime = SystemClock.uptimeMillis(); |
| 9500 | final int dw = mDisplay.getWidth(); |
| 9501 | final int dh = mDisplay.getHeight(); |
| 9502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | int i; |
| 9504 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9505 | if (mFocusMayChange) { |
| 9506 | mFocusMayChange = false; |
| 9507 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9508 | } |
| 9509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9510 | if (mFxSession == null) { |
| 9511 | mFxSession = new SurfaceSession(); |
| 9512 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9513 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9514 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9515 | |
| 9516 | // Initialize state of exiting tokens. |
| 9517 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9518 | mExitingTokens.get(i).hasVisible = false; |
| 9519 | } |
| 9520 | |
| 9521 | // Initialize state of exiting applications. |
| 9522 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9523 | mExitingAppTokens.get(i).hasVisible = false; |
| 9524 | } |
| 9525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9526 | boolean orientationChangeComplete = true; |
| 9527 | Session holdScreen = null; |
| 9528 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9529 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9530 | boolean focusDisplayed = false; |
| 9531 | boolean animating = false; |
| 9532 | |
| 9533 | Surface.openTransaction(); |
| 9534 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9535 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9536 | int repeats = 0; |
| 9537 | int changes = 0; |
| 9538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9539 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9540 | repeats++; |
| 9541 | if (repeats > 6) { |
| 9542 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9543 | mLayoutNeeded = false; |
| 9544 | break; |
| 9545 | } |
| 9546 | |
| 9547 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9548 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9549 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9550 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9551 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9552 | assignLayersLocked(); |
| 9553 | mLayoutNeeded = true; |
| 9554 | } |
| 9555 | } |
| 9556 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9557 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9558 | if (updateOrientationFromAppTokensLocked()) { |
| 9559 | mLayoutNeeded = true; |
| 9560 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9561 | } |
| 9562 | } |
| 9563 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9564 | mLayoutNeeded = true; |
| 9565 | } |
| 9566 | } |
| 9567 | |
| 9568 | // FIRST LOOP: Perform a layout, if needed. |
| 9569 | if (repeats < 4) { |
| 9570 | changes = performLayoutLockedInner(); |
| 9571 | if (changes != 0) { |
| 9572 | continue; |
| 9573 | } |
| 9574 | } else { |
| 9575 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9576 | changes = 0; |
| 9577 | } |
| 9578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9579 | final int transactionSequence = ++mTransactionSequence; |
| 9580 | |
| 9581 | // Update animations of all applications, including those |
| 9582 | // associated with exiting/removed apps |
| 9583 | boolean tokensAnimating = false; |
| 9584 | final int NAT = mAppTokens.size(); |
| 9585 | for (i=0; i<NAT; i++) { |
| 9586 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9587 | tokensAnimating = true; |
| 9588 | } |
| 9589 | } |
| 9590 | final int NEAT = mExitingAppTokens.size(); |
| 9591 | for (i=0; i<NEAT; i++) { |
| 9592 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9593 | tokensAnimating = true; |
| 9594 | } |
| 9595 | } |
| 9596 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9597 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9598 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9599 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9600 | + transactionSequence + " tokensAnimating=" |
| 9601 | + tokensAnimating); |
| 9602 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9603 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9604 | |
| 9605 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9606 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9607 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | |
| 9609 | mPolicy.beginAnimationLw(dw, dh); |
| 9610 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9611 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9612 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | for (i=N-1; i>=0; i--) { |
| 9614 | WindowState w = (WindowState)mWindows.get(i); |
| 9615 | |
| 9616 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9617 | |
| 9618 | if (w.mSurface != null) { |
| 9619 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9620 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9621 | if ((w.mAttrs.flags |
| 9622 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9623 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9624 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9625 | wallpaperMayChange = true; |
| 9626 | } |
| 9627 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9628 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9629 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9630 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9631 | animating = true; |
| 9632 | //w.dump(" "); |
| 9633 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9634 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9635 | wallpaperMayChange = true; |
| 9636 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9637 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9638 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9639 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9640 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9641 | "Animation done that could impact force hide: " |
| 9642 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9643 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9644 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9645 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9646 | forceHiding = true; |
| 9647 | } |
| 9648 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9649 | boolean changed; |
| 9650 | if (forceHiding) { |
| 9651 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9652 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9653 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9654 | } else { |
| 9655 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9656 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9657 | "Now policy shown: " + w); |
| 9658 | if (changed) { |
| 9659 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9660 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9661 | // Assume we will need to animate. If |
| 9662 | // we don't (because the wallpaper will |
| 9663 | // stay with the lock screen), then we will |
| 9664 | // clean up later. |
| 9665 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9666 | if (a != null) { |
| 9667 | w.setAnimation(a); |
| 9668 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9669 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9670 | if (mCurrentFocus == null || |
| 9671 | mCurrentFocus.mLayer < w.mLayer) { |
| 9672 | // We are showing on to of the current |
| 9673 | // focus, so re-evaluate focus to make |
| 9674 | // sure it is correct. |
| 9675 | mFocusMayChange = true; |
| 9676 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9677 | } |
| 9678 | } |
| 9679 | if (changed && (attrs.flags |
| 9680 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9681 | wallpaperMayChange = true; |
| 9682 | } |
| 9683 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9685 | mPolicy.animatingWindowLw(w, attrs); |
| 9686 | } |
| 9687 | |
| 9688 | final AppWindowToken atoken = w.mAppToken; |
| 9689 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9690 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9691 | atoken.lastTransactionSequence = transactionSequence; |
| 9692 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9693 | atoken.startingDisplayed = false; |
| 9694 | } |
| 9695 | if ((w.isOnScreen() || w.mAttrs.type |
| 9696 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9697 | && !w.mExiting && !w.mDestroying) { |
| 9698 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9699 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9700 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9701 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9702 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9703 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9704 | + " pv=" + w.mPolicyVisibility |
| 9705 | + " dp=" + w.mDrawPending |
| 9706 | + " cdp=" + w.mCommitDrawPending |
| 9707 | + " ah=" + w.mAttachedHidden |
| 9708 | + " th=" + atoken.hiddenRequested |
| 9709 | + " a=" + w.mAnimating); |
| 9710 | } |
| 9711 | } |
| 9712 | if (w != atoken.startingWindow) { |
| 9713 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9714 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9715 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9716 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9717 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9718 | "tokenMayBeDrawn: " + atoken |
| 9719 | + " freezingScreen=" + atoken.freezingScreen |
| 9720 | + " mAppFreezing=" + w.mAppFreezing); |
| 9721 | tokenMayBeDrawn = true; |
| 9722 | } |
| 9723 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9724 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9725 | atoken.startingDisplayed = true; |
| 9726 | } |
| 9727 | } |
| 9728 | } else if (w.mReadyToShow) { |
| 9729 | w.performShowLocked(); |
| 9730 | } |
| 9731 | } |
| 9732 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9733 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9734 | |
| 9735 | if (tokenMayBeDrawn) { |
| 9736 | // See if any windows have been drawn, so they (and others |
| 9737 | // associated with them) can now be shown. |
| 9738 | final int NT = mTokenList.size(); |
| 9739 | for (i=0; i<NT; i++) { |
| 9740 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9741 | if (wtoken == null) { |
| 9742 | continue; |
| 9743 | } |
| 9744 | if (wtoken.freezingScreen) { |
| 9745 | int numInteresting = wtoken.numInterestingWindows; |
| 9746 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9747 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9748 | "allDrawn: " + wtoken |
| 9749 | + " interesting=" + numInteresting |
| 9750 | + " drawn=" + wtoken.numDrawnWindows); |
| 9751 | wtoken.showAllWindowsLocked(); |
| 9752 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9753 | orientationChangeComplete = true; |
| 9754 | } |
| 9755 | } else if (!wtoken.allDrawn) { |
| 9756 | int numInteresting = wtoken.numInterestingWindows; |
| 9757 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9758 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9759 | "allDrawn: " + wtoken |
| 9760 | + " interesting=" + numInteresting |
| 9761 | + " drawn=" + wtoken.numDrawnWindows); |
| 9762 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9763 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9764 | |
| 9765 | // We can now show all of the drawn windows! |
| 9766 | if (!mOpeningApps.contains(wtoken)) { |
| 9767 | wtoken.showAllWindowsLocked(); |
| 9768 | } |
| 9769 | } |
| 9770 | } |
| 9771 | } |
| 9772 | } |
| 9773 | |
| 9774 | // If we are ready to perform an app transition, check through |
| 9775 | // all of the app tokens to be shown and see if they are ready |
| 9776 | // to go. |
| 9777 | if (mAppTransitionReady) { |
| 9778 | int NN = mOpeningApps.size(); |
| 9779 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9780 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9781 | "Checking " + NN + " opening apps (frozen=" |
| 9782 | + mDisplayFrozen + " timeout=" |
| 9783 | + mAppTransitionTimeout + ")..."); |
| 9784 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9785 | // If the display isn't frozen, wait to do anything until |
| 9786 | // all of the apps are ready. Otherwise just go because |
| 9787 | // we'll unfreeze the display when everyone is ready. |
| 9788 | for (i=0; i<NN && goodToGo; i++) { |
| 9789 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9790 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9791 | "Check opening app" + wtoken + ": allDrawn=" |
| 9792 | + wtoken.allDrawn + " startingDisplayed=" |
| 9793 | + wtoken.startingDisplayed); |
| 9794 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9795 | && !wtoken.startingMoved) { |
| 9796 | goodToGo = false; |
| 9797 | } |
| 9798 | } |
| 9799 | } |
| 9800 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9801 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9802 | int transit = mNextAppTransition; |
| 9803 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9804 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9805 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9806 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9807 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9808 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9809 | mAppTransitionTimeout = false; |
| 9810 | mStartingIconInTransition = false; |
| 9811 | mSkipAppTransitionAnimation = false; |
| 9812 | |
| 9813 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9814 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9815 | // If there are applications waiting to come to the |
| 9816 | // top of the stack, now is the time to move their windows. |
| 9817 | // (Note that we don't do apps going to the bottom |
| 9818 | // here -- we want to keep their windows in the old |
| 9819 | // Z-order until the animation completes.) |
| 9820 | if (mToTopApps.size() > 0) { |
| 9821 | NN = mAppTokens.size(); |
| 9822 | for (i=0; i<NN; i++) { |
| 9823 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9824 | if (wtoken.sendingToTop) { |
| 9825 | wtoken.sendingToTop = false; |
| 9826 | moveAppWindowsLocked(wtoken, NN, false); |
| 9827 | } |
| 9828 | } |
| 9829 | mToTopApps.clear(); |
| 9830 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9831 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9832 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9833 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9834 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9835 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9836 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9837 | // The top-most window will supply the layout params, |
| 9838 | // and we will determine it below. |
| 9839 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9840 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9841 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9842 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9843 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9844 | "New wallpaper target=" + mWallpaperTarget |
| 9845 | + ", lower target=" + mLowerWallpaperTarget |
| 9846 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9847 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9848 | // Do a first pass through the tokens for two |
| 9849 | // things: |
| 9850 | // (1) Determine if both the closing and opening |
| 9851 | // app token sets are wallpaper targets, in which |
| 9852 | // case special animations are needed |
| 9853 | // (since the wallpaper needs to stay static |
| 9854 | // behind them). |
| 9855 | // (2) Find the layout params of the top-most |
| 9856 | // application window in the tokens, which is |
| 9857 | // what will control the animation theme. |
| 9858 | final int NC = mClosingApps.size(); |
| 9859 | NN = NC + mOpeningApps.size(); |
| 9860 | for (i=0; i<NN; i++) { |
| 9861 | AppWindowToken wtoken; |
| 9862 | int mode; |
| 9863 | if (i < NC) { |
| 9864 | wtoken = mClosingApps.get(i); |
| 9865 | mode = 1; |
| 9866 | } else { |
| 9867 | wtoken = mOpeningApps.get(i-NC); |
| 9868 | mode = 2; |
| 9869 | } |
| 9870 | if (mLowerWallpaperTarget != null) { |
| 9871 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9872 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9873 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9874 | } |
| 9875 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9876 | if (wtoken.appFullscreen) { |
| 9877 | WindowState ws = wtoken.findMainWindow(); |
| 9878 | if (ws != null) { |
| 9879 | // If this is a compatibility mode |
| 9880 | // window, we will always use its anim. |
| 9881 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9882 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9883 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9884 | bestAnimLayer = Integer.MAX_VALUE; |
| 9885 | } else if (ws.mLayer > bestAnimLayer) { |
| 9886 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9887 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9888 | bestAnimLayer = ws.mLayer; |
| 9889 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9890 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9891 | } |
| 9892 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9893 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9894 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9895 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9896 | "Wallpaper animation!"); |
| 9897 | switch (transit) { |
| 9898 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9899 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9900 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9901 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9902 | break; |
| 9903 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9904 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9905 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9906 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9907 | break; |
| 9908 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9909 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9910 | "New transit: " + transit); |
| 9911 | } else if (oldWallpaper != null) { |
| 9912 | // We are transitioning from an activity with |
| 9913 | // a wallpaper to one without. |
| 9914 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9915 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9916 | "New transit away from wallpaper: " + transit); |
| 9917 | } else if (mWallpaperTarget != null) { |
| 9918 | // We are transitioning from an activity without |
| 9919 | // a wallpaper to now showing the wallpaper |
| 9920 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9921 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9922 | "New transit into wallpaper: " + transit); |
| 9923 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9924 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9925 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9926 | mLastEnterAnimToken = animToken; |
| 9927 | mLastEnterAnimParams = animLp; |
| 9928 | } else if (mLastEnterAnimParams != null) { |
| 9929 | animLp = mLastEnterAnimParams; |
| 9930 | mLastEnterAnimToken = null; |
| 9931 | mLastEnterAnimParams = null; |
| 9932 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9933 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9934 | // If all closing windows are obscured, then there is |
| 9935 | // no need to do an animation. This is the case, for |
| 9936 | // example, when this transition is being done behind |
| 9937 | // the lock screen. |
| 9938 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9939 | animLp = null; |
| 9940 | } |
| 9941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9942 | NN = mOpeningApps.size(); |
| 9943 | for (i=0; i<NN; i++) { |
| 9944 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9945 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9946 | "Now opening app" + wtoken); |
| 9947 | wtoken.reportedVisible = false; |
| 9948 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9949 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9950 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9951 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9952 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9953 | wtoken.showAllWindowsLocked(); |
| 9954 | } |
| 9955 | NN = mClosingApps.size(); |
| 9956 | for (i=0; i<NN; i++) { |
| 9957 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9958 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9959 | "Now closing app" + wtoken); |
| 9960 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9961 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9962 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9963 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9964 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9965 | // Force the allDrawn flag, because we want to start |
| 9966 | // this guy's animations regardless of whether it's |
| 9967 | // gotten drawn. |
| 9968 | wtoken.allDrawn = true; |
| 9969 | } |
| 9970 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9971 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9973 | mOpeningApps.clear(); |
| 9974 | mClosingApps.clear(); |
| 9975 | |
| 9976 | // This has changed the visibility of windows, so perform |
| 9977 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9978 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9979 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9980 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9981 | assignLayersLocked(); |
| 9982 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9983 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9984 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9985 | } |
| 9986 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9987 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9988 | int adjResult = 0; |
| 9989 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9990 | if (!animating && mAppTransitionRunning) { |
| 9991 | // We have finished the animation of an app transition. To do |
| 9992 | // this, we have delayed a lot of operations like showing and |
| 9993 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9994 | // reflects the correct Z-order, but the window list may now |
| 9995 | // be out of sync with it. So here we will just rebuild the |
| 9996 | // entire app window list. Fun! |
| 9997 | mAppTransitionRunning = false; |
| 9998 | // Clear information about apps that were moving. |
| 9999 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10000 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10001 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10002 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10003 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10004 | moveInputMethodWindowsIfNeededLocked(false); |
| 10005 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10006 | // Since the window list has been rebuilt, focus might |
| 10007 | // have to be recomputed since the actual order of windows |
| 10008 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10009 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10010 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10011 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10012 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10013 | // At this point, there was a window with a wallpaper that |
| 10014 | // was force hiding other windows behind it, but now it |
| 10015 | // is going away. This may be simple -- just animate |
| 10016 | // away the wallpaper and its window -- or it may be |
| 10017 | // hard -- the wallpaper now needs to be shown behind |
| 10018 | // something that was hidden. |
| 10019 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10020 | if (mLowerWallpaperTarget != null |
| 10021 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10022 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10023 | "wallpaperForceHiding changed with lower=" |
| 10024 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10025 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10026 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10027 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10028 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10029 | // The lower target has become hidden before we |
| 10030 | // actually started the animation... let's completely |
| 10031 | // re-evaluate everything. |
| 10032 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10033 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10034 | } |
| 10035 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10036 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10037 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10038 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10039 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10040 | + " NEW: " + mWallpaperTarget |
| 10041 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10042 | if (mLowerWallpaperTarget == null) { |
| 10043 | // Whoops, we don't need a special wallpaper animation. |
| 10044 | // Clear them out. |
| 10045 | forceHiding = false; |
| 10046 | for (i=N-1; i>=0; i--) { |
| 10047 | WindowState w = (WindowState)mWindows.get(i); |
| 10048 | if (w.mSurface != null) { |
| 10049 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10050 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10051 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10052 | forceHiding = true; |
| 10053 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10054 | if (!w.mAnimating) { |
| 10055 | // We set the animation above so it |
| 10056 | // is not yet running. |
| 10057 | w.clearAnimation(); |
| 10058 | } |
| 10059 | } |
| 10060 | } |
| 10061 | } |
| 10062 | } |
| 10063 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10064 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10065 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10066 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10067 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10068 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10069 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10070 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10071 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10072 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10073 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10074 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10075 | assignLayersLocked(); |
| 10076 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10077 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10078 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10079 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10080 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10081 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10082 | if (mFocusMayChange) { |
| 10083 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10084 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10085 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10086 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10087 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10088 | } |
| 10089 | |
| 10090 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10091 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10092 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10093 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10094 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10095 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10096 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10097 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10098 | |
| 10099 | // THIRD LOOP: Update the surfaces of all windows. |
| 10100 | |
| 10101 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10102 | |
| 10103 | boolean obscured = false; |
| 10104 | boolean blurring = false; |
| 10105 | boolean dimming = false; |
| 10106 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10107 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10108 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10109 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10110 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10112 | for (i=N-1; i>=0; i--) { |
| 10113 | WindowState w = (WindowState)mWindows.get(i); |
| 10114 | |
| 10115 | boolean displayed = false; |
| 10116 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10117 | final int attrFlags = attrs.flags; |
| 10118 | |
| 10119 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10120 | // XXX NOTE: The logic here could be improved. We have |
| 10121 | // the decision about whether to resize a window separated |
| 10122 | // from whether to hide the surface. This can cause us to |
| 10123 | // resize a surface even if we are going to hide it. You |
| 10124 | // can see this by (1) holding device in landscape mode on |
| 10125 | // home screen; (2) tapping browser icon (device will rotate |
| 10126 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10127 | // in step 2 but then immediately hidden, causing us to |
| 10128 | // have to resize and then redraw it again in step 3. It |
| 10129 | // would be nice to figure out how to avoid this, but it is |
| 10130 | // difficult because we do need to resize surfaces in some |
| 10131 | // cases while they are hidden such as when first showing a |
| 10132 | // window. |
| 10133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10134 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10135 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10136 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10137 | + ": new=" + w.mShownFrame + ", old=" |
| 10138 | + w.mLastShownFrame); |
| 10139 | |
| 10140 | boolean resize; |
| 10141 | int width, height; |
| 10142 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 10143 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 10144 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 10145 | // for a scaled surface, we just want to use |
| 10146 | // the requested size. |
| 10147 | width = w.mRequestedWidth; |
| 10148 | height = w.mRequestedHeight; |
| 10149 | w.mLastRequestedWidth = width; |
| 10150 | w.mLastRequestedHeight = height; |
| 10151 | w.mLastShownFrame.set(w.mShownFrame); |
| 10152 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10153 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10154 | "POS " + w.mShownFrame.left |
| 10155 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10156 | w.mSurfaceX = w.mShownFrame.left; |
| 10157 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10158 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10159 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10160 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10161 | if (!recoveringMemory) { |
| 10162 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10163 | } |
| 10164 | } |
| 10165 | } else { |
| 10166 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 10167 | width = w.mShownFrame.width(); |
| 10168 | height = w.mShownFrame.height(); |
| 10169 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10170 | } |
| 10171 | |
| 10172 | if (resize) { |
| 10173 | if (width < 1) width = 1; |
| 10174 | if (height < 1) height = 1; |
| 10175 | if (w.mSurface != null) { |
| 10176 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10177 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10178 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10179 | + w.mShownFrame.top + " SIZE " |
| 10180 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10181 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10182 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10183 | w.mSurfaceW = width; |
| 10184 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10185 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10186 | w.mSurfaceX = w.mShownFrame.left; |
| 10187 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10188 | w.mSurface.setPosition(w.mShownFrame.left, |
| 10189 | w.mShownFrame.top); |
| 10190 | } catch (RuntimeException e) { |
| 10191 | // If something goes wrong with the surface (such |
| 10192 | // as running out of memory), don't take down the |
| 10193 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10194 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10195 | + "size=(" + width + "x" + height |
| 10196 | + "), pos=(" + w.mShownFrame.left |
| 10197 | + "," + w.mShownFrame.top + ")", e); |
| 10198 | if (!recoveringMemory) { |
| 10199 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10200 | } |
| 10201 | } |
| 10202 | } |
| 10203 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10204 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10205 | w.mContentInsetsChanged = |
| 10206 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10207 | w.mVisibleInsetsChanged = |
| 10208 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10209 | boolean configChanged = |
| 10210 | w.mConfiguration != mCurConfiguration |
| 10211 | && (w.mConfiguration == null |
| 10212 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10213 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10214 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10215 | + mCurConfiguration); |
| 10216 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10217 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10218 | + ": configChanged=" + configChanged |
| 10219 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10220 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10221 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10222 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10223 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10224 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10225 | w.mLastFrame.set(w.mFrame); |
| 10226 | w.mLastContentInsets.set(w.mContentInsets); |
| 10227 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10228 | // If the screen is currently frozen, then keep |
| 10229 | // it frozen until this window draws at its new |
| 10230 | // orientation. |
| 10231 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10232 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10233 | "Resizing while display frozen: " + w); |
| 10234 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10235 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10236 | mWindowsFreezingScreen = true; |
| 10237 | // XXX should probably keep timeout from |
| 10238 | // when we first froze the display. |
| 10239 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10240 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10241 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10242 | } |
| 10243 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10244 | // If the orientation is changing, then we need to |
| 10245 | // hold off on unfreezing the display until this |
| 10246 | // window has been redrawn; to do that, we need |
| 10247 | // to go through the process of getting informed |
| 10248 | // by the application when it has finished drawing. |
| 10249 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10250 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10251 | "Orientation start waiting for draw in " |
| 10252 | + w + ", surface " + w.mSurface); |
| 10253 | w.mDrawPending = true; |
| 10254 | w.mCommitDrawPending = false; |
| 10255 | w.mReadyToShow = false; |
| 10256 | if (w.mAppToken != null) { |
| 10257 | w.mAppToken.allDrawn = false; |
| 10258 | } |
| 10259 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10260 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10261 | "Resizing window " + w + " to " + w.mFrame); |
| 10262 | mResizingWindows.add(w); |
| 10263 | } else if (w.mOrientationChanging) { |
| 10264 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10265 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10266 | "Orientation not waiting for draw in " |
| 10267 | + w + ", surface " + w.mSurface); |
| 10268 | w.mOrientationChanging = false; |
| 10269 | } |
| 10270 | } |
| 10271 | } |
| 10272 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10273 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10274 | if (!w.mLastHidden) { |
| 10275 | //dump(); |
| 10276 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10277 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10278 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10279 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10280 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10281 | try { |
| 10282 | w.mSurface.hide(); |
| 10283 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10284 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10285 | } |
| 10286 | } |
| 10287 | mKeyWaiter.releasePendingPointerLocked(w.mSession); |
| 10288 | } |
| 10289 | // If we are waiting for this window to handle an |
| 10290 | // orientation change, well, it is hidden, so |
| 10291 | // doesn't really matter. Note that this does |
| 10292 | // introduce a potential glitch if the window |
| 10293 | // becomes unhidden before it has drawn for the |
| 10294 | // new orientation. |
| 10295 | if (w.mOrientationChanging) { |
| 10296 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10297 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10298 | "Orientation change skips hidden " + w); |
| 10299 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10300 | } else if (w.mLastLayer != w.mAnimLayer |
| 10301 | || w.mLastAlpha != w.mShownAlpha |
| 10302 | || w.mLastDsDx != w.mDsDx |
| 10303 | || w.mLastDtDx != w.mDtDx |
| 10304 | || w.mLastDsDy != w.mDsDy |
| 10305 | || w.mLastDtDy != w.mDtDy |
| 10306 | || w.mLastHScale != w.mHScale |
| 10307 | || w.mLastVScale != w.mVScale |
| 10308 | || w.mLastHidden) { |
| 10309 | displayed = true; |
| 10310 | w.mLastAlpha = w.mShownAlpha; |
| 10311 | w.mLastLayer = w.mAnimLayer; |
| 10312 | w.mLastDsDx = w.mDsDx; |
| 10313 | w.mLastDtDx = w.mDtDx; |
| 10314 | w.mLastDsDy = w.mDsDy; |
| 10315 | w.mLastDtDy = w.mDtDy; |
| 10316 | w.mLastHScale = w.mHScale; |
| 10317 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10318 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10319 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10320 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10321 | + "," + (w.mDtDx*w.mVScale) |
| 10322 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10323 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10324 | if (w.mSurface != null) { |
| 10325 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10326 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10327 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10328 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10329 | w.mSurface.setLayer(w.mAnimLayer); |
| 10330 | w.mSurface.setMatrix( |
| 10331 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10332 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10333 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10334 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10335 | if (!recoveringMemory) { |
| 10336 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10337 | } |
| 10338 | } |
| 10339 | } |
| 10340 | |
| 10341 | if (w.mLastHidden && !w.mDrawPending |
| 10342 | && !w.mCommitDrawPending |
| 10343 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10344 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10345 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10346 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10347 | + " during relayout"); |
| 10348 | if (showSurfaceRobustlyLocked(w)) { |
| 10349 | w.mHasDrawn = true; |
| 10350 | w.mLastHidden = false; |
| 10351 | } else { |
| 10352 | w.mOrientationChanging = false; |
| 10353 | } |
| 10354 | } |
| 10355 | if (w.mSurface != null) { |
| 10356 | w.mToken.hasVisible = true; |
| 10357 | } |
| 10358 | } else { |
| 10359 | displayed = true; |
| 10360 | } |
| 10361 | |
| 10362 | if (displayed) { |
| 10363 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10364 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10365 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10366 | covered = true; |
| 10367 | } |
| 10368 | } |
| 10369 | if (w.mOrientationChanging) { |
| 10370 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10371 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10372 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10373 | "Orientation continue waiting for draw in " + w); |
| 10374 | } else { |
| 10375 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10376 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10377 | "Orientation change complete in " + w); |
| 10378 | } |
| 10379 | } |
| 10380 | w.mToken.hasVisible = true; |
| 10381 | } |
| 10382 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10383 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10384 | "Orientation change skips hidden " + w); |
| 10385 | w.mOrientationChanging = false; |
| 10386 | } |
| 10387 | |
| 10388 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10389 | |
| 10390 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10391 | focusDisplayed = true; |
| 10392 | } |
| 10393 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10394 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10396 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10397 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10398 | if (w.mSurface != null) { |
| 10399 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10400 | holdScreen = w.mSession; |
| 10401 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10402 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10403 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10404 | screenBrightness = w.mAttrs.screenBrightness; |
| 10405 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10406 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10407 | && buttonBrightness < 0) { |
| 10408 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10409 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10410 | if (canBeSeen |
| 10411 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10412 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10413 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10414 | syswin = true; |
| 10415 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10416 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10417 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10418 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10419 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10420 | // This window completely covers everything behind it, |
| 10421 | // so we want to leave all of them as unblurred (for |
| 10422 | // performance reasons). |
| 10423 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10424 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10425 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10426 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10427 | obscured = true; |
| 10428 | if (mBackgroundFillerSurface == null) { |
| 10429 | try { |
| 10430 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10431 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10432 | 0, dw, dh, |
| 10433 | PixelFormat.OPAQUE, |
| 10434 | Surface.FX_SURFACE_NORMAL); |
| 10435 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10436 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10437 | } |
| 10438 | } |
| 10439 | try { |
| 10440 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10441 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10442 | // Using the same layer as Dim because they will never be shown at the |
| 10443 | // same time. |
| 10444 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10445 | mBackgroundFillerSurface.show(); |
| 10446 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10447 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10448 | } |
| 10449 | backgroundFillerShown = true; |
| 10450 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10451 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10452 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10453 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10454 | + ": blurring=" + blurring |
| 10455 | + " obscured=" + obscured |
| 10456 | + " displayed=" + displayed); |
| 10457 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10458 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10459 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10460 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10461 | if (mDimAnimator == null) { |
| 10462 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10463 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10464 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10465 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10466 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10467 | } |
| 10468 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10469 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10470 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10471 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10472 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10473 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10474 | + mBlurSurface + ": CREATE"); |
| 10475 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10476 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10477 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10478 | -1, 16, 16, |
| 10479 | PixelFormat.OPAQUE, |
| 10480 | Surface.FX_SURFACE_BLUR); |
| 10481 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10482 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10483 | } |
| 10484 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10485 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10486 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10487 | + mBlurSurface + ": pos=(0,0) (" + |
| 10488 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10489 | mBlurSurface.setPosition(0, 0); |
| 10490 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10491 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10492 | if (!mBlurShown) { |
| 10493 | try { |
| 10494 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10495 | + mBlurSurface + ": SHOW"); |
| 10496 | mBlurSurface.show(); |
| 10497 | } catch (RuntimeException e) { |
| 10498 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10499 | } |
| 10500 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10501 | } |
| 10502 | } |
| 10503 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10504 | } |
| 10505 | } |
| 10506 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10507 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10508 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10509 | // This is the wallpaper target and its obscured state |
| 10510 | // changed... make sure the current wallaper's visibility |
| 10511 | // has been updated accordingly. |
| 10512 | updateWallpaperVisibilityLocked(); |
| 10513 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10514 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10515 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10516 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10517 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10518 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10519 | try { |
| 10520 | mBackgroundFillerSurface.hide(); |
| 10521 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10522 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10523 | } |
| 10524 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10525 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10526 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10527 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10528 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10529 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10531 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10532 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10533 | + ": HIDE"); |
| 10534 | try { |
| 10535 | mBlurSurface.hide(); |
| 10536 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10537 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10538 | } |
| 10539 | mBlurShown = false; |
| 10540 | } |
| 10541 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10542 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10543 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10544 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10545 | } |
| 10546 | |
| 10547 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10548 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10549 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10550 | "With display frozen, orientationChangeComplete=" |
| 10551 | + orientationChangeComplete); |
| 10552 | if (orientationChangeComplete) { |
| 10553 | if (mWindowsFreezingScreen) { |
| 10554 | mWindowsFreezingScreen = false; |
| 10555 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10556 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10557 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10558 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10559 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10560 | i = mResizingWindows.size(); |
| 10561 | if (i > 0) { |
| 10562 | do { |
| 10563 | i--; |
| 10564 | WindowState win = mResizingWindows.get(i); |
| 10565 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10566 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10567 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10568 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10569 | boolean configChanged = |
| 10570 | win.mConfiguration != mCurConfiguration |
| 10571 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10572 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10573 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10574 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10575 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10576 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10577 | + " / " + mCurConfiguration + " / 0x" |
| 10578 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10579 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10580 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10581 | win.mClient.resized(win.mFrame.width(), |
| 10582 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10583 | win.mLastVisibleInsets, win.mDrawPending, |
| 10584 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10585 | win.mContentInsetsChanged = false; |
| 10586 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10587 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10588 | } catch (RemoteException e) { |
| 10589 | win.mOrientationChanging = false; |
| 10590 | } |
| 10591 | } while (i > 0); |
| 10592 | mResizingWindows.clear(); |
| 10593 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10594 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10595 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10596 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10597 | i = mDestroySurface.size(); |
| 10598 | if (i > 0) { |
| 10599 | do { |
| 10600 | i--; |
| 10601 | WindowState win = mDestroySurface.get(i); |
| 10602 | win.mDestroying = false; |
| 10603 | if (mInputMethodWindow == win) { |
| 10604 | mInputMethodWindow = null; |
| 10605 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10606 | if (win == mWallpaperTarget) { |
| 10607 | wallpaperDestroyed = true; |
| 10608 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10609 | win.destroySurfaceLocked(); |
| 10610 | } while (i > 0); |
| 10611 | mDestroySurface.clear(); |
| 10612 | } |
| 10613 | |
| 10614 | // Time to remove any exiting tokens? |
| 10615 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10616 | WindowToken token = mExitingTokens.get(i); |
| 10617 | if (!token.hasVisible) { |
| 10618 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10619 | if (token.windowType == TYPE_WALLPAPER) { |
| 10620 | mWallpaperTokens.remove(token); |
| 10621 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10622 | } |
| 10623 | } |
| 10624 | |
| 10625 | // Time to remove any exiting applications? |
| 10626 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10627 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10628 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10629 | // Make sure there is no animation running on this token, |
| 10630 | // so any windows associated with it will be removed as |
| 10631 | // soon as their animations are complete |
| 10632 | token.animation = null; |
| 10633 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10634 | mAppTokens.remove(token); |
| 10635 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10636 | if (mLastEnterAnimToken == token) { |
| 10637 | mLastEnterAnimToken = null; |
| 10638 | mLastEnterAnimParams = null; |
| 10639 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10640 | } |
| 10641 | } |
| 10642 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10643 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10644 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10645 | if (!animating && mAppTransitionRunning) { |
| 10646 | // We have finished the animation of an app transition. To do |
| 10647 | // this, we have delayed a lot of operations like showing and |
| 10648 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10649 | // reflects the correct Z-order, but the window list may now |
| 10650 | // be out of sync with it. So here we will just rebuild the |
| 10651 | // entire app window list. Fun! |
| 10652 | mAppTransitionRunning = false; |
| 10653 | needRelayout = true; |
| 10654 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10655 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10656 | // Clear information about apps that were moving. |
| 10657 | mToBottomApps.clear(); |
| 10658 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10660 | if (focusDisplayed) { |
| 10661 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10662 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10663 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10664 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10665 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10666 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10667 | requestAnimationLocked(0); |
| 10668 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10669 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10670 | } |
| 10671 | mQueue.setHoldScreenLocked(holdScreen != null); |
| 10672 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10673 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10674 | } else { |
| 10675 | mPowerManager.setScreenBrightnessOverride((int) |
| 10676 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10677 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10678 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10679 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10680 | } else { |
| 10681 | mPowerManager.setButtonBrightnessOverride((int) |
| 10682 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10683 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10684 | if (holdScreen != mHoldingScreenOn) { |
| 10685 | mHoldingScreenOn = holdScreen; |
| 10686 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10687 | mH.sendMessage(m); |
| 10688 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10689 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10690 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10691 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10692 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10693 | LocalPowerManager.BUTTON_EVENT, true); |
| 10694 | mTurnOnScreen = false; |
| 10695 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10696 | |
| 10697 | // Check to see if we are now in a state where the screen should |
| 10698 | // be enabled, because the window obscured flags have changed. |
| 10699 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10700 | } |
| 10701 | |
| 10702 | void requestAnimationLocked(long delay) { |
| 10703 | if (!mAnimationPending) { |
| 10704 | mAnimationPending = true; |
| 10705 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10706 | } |
| 10707 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10709 | /** |
| 10710 | * Have the surface flinger show a surface, robustly dealing with |
| 10711 | * error conditions. In particular, if there is not enough memory |
| 10712 | * to show the surface, then we will try to get rid of other surfaces |
| 10713 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10714 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10715 | * @return Returns true if the surface was successfully shown. |
| 10716 | */ |
| 10717 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10718 | try { |
| 10719 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10720 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10721 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10722 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10723 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10724 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10725 | win.mTurnOnScreen = false; |
| 10726 | mTurnOnScreen = true; |
| 10727 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10728 | } |
| 10729 | return true; |
| 10730 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10731 | Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10732 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10733 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10734 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10735 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10736 | return false; |
| 10737 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10738 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10739 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10740 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10741 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10742 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10743 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10745 | if (mForceRemoves == null) { |
| 10746 | mForceRemoves = new ArrayList<WindowState>(); |
| 10747 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10749 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10750 | try { |
| 10751 | // There was some problem... first, do a sanity check of the |
| 10752 | // window list to make sure we haven't left any dangling surfaces |
| 10753 | // around. |
| 10754 | int N = mWindows.size(); |
| 10755 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10756 | Slog.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10757 | for (int i=0; i<N; i++) { |
| 10758 | WindowState ws = (WindowState)mWindows.get(i); |
| 10759 | if (ws.mSurface != null) { |
| 10760 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10761 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10762 | + ws + " surface=" + ws.mSurface |
| 10763 | + " token=" + win.mToken |
| 10764 | + " pid=" + ws.mSession.mPid |
| 10765 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10766 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10767 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10768 | ws.mSurface = null; |
| 10769 | mForceRemoves.add(ws); |
| 10770 | i--; |
| 10771 | N--; |
| 10772 | leakedSurface = true; |
| 10773 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10774 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10775 | + ws + " surface=" + ws.mSurface |
| 10776 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10777 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10778 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10779 | ws.mSurface = null; |
| 10780 | leakedSurface = true; |
| 10781 | } |
| 10782 | } |
| 10783 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10784 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10785 | boolean killedApps = false; |
| 10786 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10787 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10788 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10789 | for (int i=0; i<N; i++) { |
| 10790 | WindowState ws = (WindowState)mWindows.get(i); |
| 10791 | if (ws.mSurface != null) { |
| 10792 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10793 | } |
| 10794 | } |
| 10795 | if (pidCandidates.size() > 0) { |
| 10796 | int[] pids = new int[pidCandidates.size()]; |
| 10797 | for (int i=0; i<pids.length; i++) { |
| 10798 | pids[i] = pidCandidates.keyAt(i); |
| 10799 | } |
| 10800 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10801 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10802 | killedApps = true; |
| 10803 | } |
| 10804 | } catch (RemoteException e) { |
| 10805 | } |
| 10806 | } |
| 10807 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10808 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10809 | if (leakedSurface || killedApps) { |
| 10810 | // We managed to reclaim some memory, so get rid of the trouble |
| 10811 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10812 | Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10813 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10814 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10815 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10816 | win.mSurface = null; |
| 10817 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10818 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10819 | try { |
| 10820 | win.mClient.dispatchGetNewSurface(); |
| 10821 | } catch (RemoteException e) { |
| 10822 | } |
| 10823 | } |
| 10824 | } finally { |
| 10825 | Binder.restoreCallingIdentity(callingIdentity); |
| 10826 | } |
| 10827 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10828 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10829 | private boolean updateFocusedWindowLocked(int mode) { |
| 10830 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10831 | if (mCurrentFocus != newFocus) { |
| 10832 | // This check makes sure that we don't already have the focus |
| 10833 | // change message pending. |
| 10834 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10835 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10836 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10837 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10838 | final WindowState oldFocus = mCurrentFocus; |
| 10839 | mCurrentFocus = newFocus; |
| 10840 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10841 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10842 | final WindowState imWindow = mInputMethodWindow; |
| 10843 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10844 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10845 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10846 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10847 | mLayoutNeeded = true; |
| 10848 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10849 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10850 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10851 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10852 | // Client will do the layout, but we need to assign layers |
| 10853 | // for handleNewWindowLocked() below. |
| 10854 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10855 | } |
| 10856 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10857 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10858 | if (newFocus != null && mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10859 | mKeyWaiter.handleNewWindowLocked(newFocus); |
| 10860 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10861 | return true; |
| 10862 | } |
| 10863 | return false; |
| 10864 | } |
| 10865 | |
| 10866 | private WindowState computeFocusedWindowLocked() { |
| 10867 | WindowState result = null; |
| 10868 | WindowState win; |
| 10869 | |
| 10870 | int i = mWindows.size() - 1; |
| 10871 | int nextAppIndex = mAppTokens.size()-1; |
| 10872 | WindowToken nextApp = nextAppIndex >= 0 |
| 10873 | ? mAppTokens.get(nextAppIndex) : null; |
| 10874 | |
| 10875 | while (i >= 0) { |
| 10876 | win = (WindowState)mWindows.get(i); |
| 10877 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10878 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10879 | TAG, "Looking for focus: " + i |
| 10880 | + " = " + win |
| 10881 | + ", flags=" + win.mAttrs.flags |
| 10882 | + ", canReceive=" + win.canReceiveKeys()); |
| 10883 | |
| 10884 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10886 | // If this window's application has been removed, just skip it. |
| 10887 | if (thisApp != null && thisApp.removed) { |
| 10888 | i--; |
| 10889 | continue; |
| 10890 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10891 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10892 | // If there is a focused app, don't allow focus to go to any |
| 10893 | // windows below it. If this is an application window, step |
| 10894 | // through the app tokens until we find its app. |
| 10895 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10896 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10897 | int origAppIndex = nextAppIndex; |
| 10898 | while (nextAppIndex > 0) { |
| 10899 | if (nextApp == mFocusedApp) { |
| 10900 | // Whoops, we are below the focused app... no focus |
| 10901 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10902 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10903 | TAG, "Reached focused app: " + mFocusedApp); |
| 10904 | return null; |
| 10905 | } |
| 10906 | nextAppIndex--; |
| 10907 | nextApp = mAppTokens.get(nextAppIndex); |
| 10908 | if (nextApp == thisApp) { |
| 10909 | break; |
| 10910 | } |
| 10911 | } |
| 10912 | if (thisApp != nextApp) { |
| 10913 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10914 | // happen, but if it does we can get totally hosed... |
| 10915 | // so restart at the original app. |
| 10916 | nextAppIndex = origAppIndex; |
| 10917 | nextApp = mAppTokens.get(nextAppIndex); |
| 10918 | } |
| 10919 | } |
| 10920 | |
| 10921 | // Dispatch to this window if it is wants key events. |
| 10922 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10923 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10924 | TAG, "Found focus @ " + i + " = " + win); |
| 10925 | result = win; |
| 10926 | break; |
| 10927 | } |
| 10928 | |
| 10929 | i--; |
| 10930 | } |
| 10931 | |
| 10932 | return result; |
| 10933 | } |
| 10934 | |
| 10935 | private void startFreezingDisplayLocked() { |
| 10936 | if (mDisplayFrozen) { |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10937 | // Freezing the display also suspends key event delivery, to |
| 10938 | // keep events from going astray while the display is reconfigured. |
| 10939 | // If someone has changed orientation again while the screen is |
| 10940 | // still frozen, the events will continue to be blocked while the |
| 10941 | // successive orientation change is processed. To prevent spurious |
| 10942 | // ANRs, we reset the event dispatch timeout in this case. |
| 10943 | synchronized (mKeyWaiter) { |
| 10944 | mKeyWaiter.mWasFrozen = true; |
| 10945 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10946 | return; |
| 10947 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10948 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10949 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10951 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10952 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10953 | if (mFreezeGcPending != 0) { |
| 10954 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10955 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10956 | mH.removeMessages(H.FORCE_GC); |
| 10957 | Runtime.getRuntime().gc(); |
| 10958 | mFreezeGcPending = now; |
| 10959 | } |
| 10960 | } else { |
| 10961 | mFreezeGcPending = now; |
| 10962 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10963 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10964 | mDisplayFrozen = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10965 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10966 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10967 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10968 | mAppTransitionReady = true; |
| 10969 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10970 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10971 | if (PROFILE_ORIENTATION) { |
| 10972 | File file = new File("/data/system/frozen"); |
| 10973 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10974 | } |
| 10975 | Surface.freezeDisplay(0); |
| 10976 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10978 | private void stopFreezingDisplayLocked() { |
| 10979 | if (!mDisplayFrozen) { |
| 10980 | return; |
| 10981 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10982 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10983 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10984 | return; |
| 10985 | } |
| 10986 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10987 | mDisplayFrozen = false; |
| 10988 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10989 | if (PROFILE_ORIENTATION) { |
| 10990 | Debug.stopMethodTracing(); |
| 10991 | } |
| 10992 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10993 | |
| Chris Tate | 2ad63a9 | 2009-03-25 17:36:48 -0700 | [diff] [blame] | 10994 | // Reset the key delivery timeout on unfreeze, too. We force a wakeup here |
| 10995 | // too because regular key delivery processing should resume immediately. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10996 | synchronized (mKeyWaiter) { |
| 10997 | mKeyWaiter.mWasFrozen = true; |
| 10998 | mKeyWaiter.notifyAll(); |
| 10999 | } |
| 11000 | |
| 11001 | // A little kludge: a lot could have happened while the |
| 11002 | // display was frozen, so now that we are coming back we |
| 11003 | // do a gc so that any remote references the system |
| 11004 | // processes holds on others can be released if they are |
| 11005 | // no longer needed. |
| 11006 | mH.removeMessages(H.FORCE_GC); |
| 11007 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11008 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11009 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11010 | mScreenFrozenLock.release(); |
| 11011 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11012 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11013 | @Override |
| 11014 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11015 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11016 | != PackageManager.PERMISSION_GRANTED) { |
| 11017 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11018 | + Binder.getCallingPid() |
| 11019 | + ", uid=" + Binder.getCallingUid()); |
| 11020 | return; |
| 11021 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11022 | |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11023 | pw.println("Input State:"); |
| 11024 | mQueue.dump(pw, " "); |
| 11025 | pw.println(" "); |
| 11026 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11027 | synchronized(mWindowMap) { |
| 11028 | pw.println("Current Window Manager state:"); |
| 11029 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 11030 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11031 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11032 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11033 | w.dump(pw, " "); |
| 11034 | } |
| 11035 | if (mInputMethodDialogs.size() > 0) { |
| 11036 | pw.println(" "); |
| 11037 | pw.println(" Input method dialogs:"); |
| 11038 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11039 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11040 | 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] | 11041 | } |
| 11042 | } |
| 11043 | if (mPendingRemove.size() > 0) { |
| 11044 | pw.println(" "); |
| 11045 | pw.println(" Remove pending for:"); |
| 11046 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11047 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11048 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11049 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11050 | w.dump(pw, " "); |
| 11051 | } |
| 11052 | } |
| 11053 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11054 | pw.println(" "); |
| 11055 | pw.println(" Windows force removing:"); |
| 11056 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11057 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11058 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11059 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11060 | w.dump(pw, " "); |
| 11061 | } |
| 11062 | } |
| 11063 | if (mDestroySurface.size() > 0) { |
| 11064 | pw.println(" "); |
| 11065 | pw.println(" Windows waiting to destroy their surface:"); |
| 11066 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11067 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11068 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11069 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11070 | w.dump(pw, " "); |
| 11071 | } |
| 11072 | } |
| 11073 | if (mLosingFocus.size() > 0) { |
| 11074 | pw.println(" "); |
| 11075 | pw.println(" Windows losing focus:"); |
| 11076 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11077 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11078 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11079 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11080 | w.dump(pw, " "); |
| 11081 | } |
| 11082 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11083 | if (mResizingWindows.size() > 0) { |
| 11084 | pw.println(" "); |
| 11085 | pw.println(" Windows waiting to resize:"); |
| 11086 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11087 | WindowState w = mResizingWindows.get(i); |
| 11088 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11089 | pw.print(w); pw.println(":"); |
| 11090 | w.dump(pw, " "); |
| 11091 | } |
| 11092 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11093 | if (mSessions.size() > 0) { |
| 11094 | pw.println(" "); |
| 11095 | pw.println(" All active sessions:"); |
| 11096 | Iterator<Session> it = mSessions.iterator(); |
| 11097 | while (it.hasNext()) { |
| 11098 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11099 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11100 | s.dump(pw, " "); |
| 11101 | } |
| 11102 | } |
| 11103 | if (mTokenMap.size() > 0) { |
| 11104 | pw.println(" "); |
| 11105 | pw.println(" All tokens:"); |
| 11106 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11107 | while (it.hasNext()) { |
| 11108 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11109 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11110 | token.dump(pw, " "); |
| 11111 | } |
| 11112 | } |
| 11113 | if (mTokenList.size() > 0) { |
| 11114 | pw.println(" "); |
| 11115 | pw.println(" Window token list:"); |
| 11116 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11117 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 11118 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11119 | } |
| 11120 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11121 | if (mWallpaperTokens.size() > 0) { |
| 11122 | pw.println(" "); |
| 11123 | pw.println(" Wallpaper tokens:"); |
| 11124 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11125 | WindowToken token = mWallpaperTokens.get(i); |
| 11126 | pw.print(" Wallpaper #"); pw.print(i); |
| 11127 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11128 | token.dump(pw, " "); |
| 11129 | } |
| 11130 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11131 | if (mAppTokens.size() > 0) { |
| 11132 | pw.println(" "); |
| 11133 | pw.println(" Application tokens in Z order:"); |
| 11134 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11135 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11136 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11137 | } |
| 11138 | } |
| 11139 | if (mFinishedStarting.size() > 0) { |
| 11140 | pw.println(" "); |
| 11141 | pw.println(" Finishing start of application tokens:"); |
| 11142 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11143 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11144 | pw.print(" Finished Starting #"); pw.print(i); |
| 11145 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11146 | token.dump(pw, " "); |
| 11147 | } |
| 11148 | } |
| 11149 | if (mExitingTokens.size() > 0) { |
| 11150 | pw.println(" "); |
| 11151 | pw.println(" Exiting tokens:"); |
| 11152 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11153 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11154 | pw.print(" Exiting #"); pw.print(i); |
| 11155 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11156 | token.dump(pw, " "); |
| 11157 | } |
| 11158 | } |
| 11159 | if (mExitingAppTokens.size() > 0) { |
| 11160 | pw.println(" "); |
| 11161 | pw.println(" Exiting application tokens:"); |
| 11162 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11163 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11164 | pw.print(" Exiting App #"); pw.print(i); |
| 11165 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11166 | token.dump(pw, " "); |
| 11167 | } |
| 11168 | } |
| 11169 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11170 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11171 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11172 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11173 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11174 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11175 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11176 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11177 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11178 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11179 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11180 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11181 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11182 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11183 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11184 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11185 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11186 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11187 | if (mDimAnimator != null) { |
| 11188 | mDimAnimator.printTo(pw); |
| 11189 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11190 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11191 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11192 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11193 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11194 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11195 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11196 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11197 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11198 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11199 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11200 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11201 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11202 | pw.print(" mRotation="); pw.print(mRotation); |
| 11203 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11204 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11205 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11206 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11207 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11208 | pw.print(" mNextAppTransition=0x"); |
| 11209 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11210 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11211 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11212 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11213 | if (mNextAppTransitionPackage != null) { |
| 11214 | pw.print(" mNextAppTransitionPackage="); |
| 11215 | pw.print(mNextAppTransitionPackage); |
| 11216 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11217 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11218 | pw.print(", mNextAppTransitionExit=0x"); |
| 11219 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11220 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11221 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11222 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11223 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11224 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11225 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11226 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11227 | if (mOpeningApps.size() > 0) { |
| 11228 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11229 | } |
| 11230 | if (mClosingApps.size() > 0) { |
| 11231 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11232 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11233 | if (mToTopApps.size() > 0) { |
| 11234 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11235 | } |
| 11236 | if (mToBottomApps.size() > 0) { |
| 11237 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11238 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11239 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11240 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11241 | pw.println(" KeyWaiter state:"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11242 | pw.print(" mLastWin="); pw.print(mKeyWaiter.mLastWin); |
| 11243 | pw.print(" mLastBinder="); pw.println(mKeyWaiter.mLastBinder); |
| 11244 | pw.print(" mFinished="); pw.print(mKeyWaiter.mFinished); |
| 11245 | pw.print(" mGotFirstWindow="); pw.print(mKeyWaiter.mGotFirstWindow); |
| 11246 | pw.print(" mEventDispatching="); pw.print(mKeyWaiter.mEventDispatching); |
| 11247 | pw.print(" mTimeToSwitch="); pw.println(mKeyWaiter.mTimeToSwitch); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11248 | } |
| 11249 | } |
| 11250 | |
| 11251 | public void monitor() { |
| 11252 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11253 | synchronized (mKeyguardTokenWatcher) { } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11254 | synchronized (mKeyWaiter) { } |
| 11255 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11256 | |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11257 | public void virtualKeyFeedback(KeyEvent event) { |
| 11258 | mPolicy.keyFeedbackFromInput(event); |
| 11259 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11260 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11261 | /** |
| 11262 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11263 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11264 | */ |
| 11265 | private static class DimAnimator { |
| 11266 | Surface mDimSurface; |
| 11267 | boolean mDimShown = false; |
| 11268 | float mDimCurrentAlpha; |
| 11269 | float mDimTargetAlpha; |
| 11270 | float mDimDeltaPerMs; |
| 11271 | long mLastDimAnimTime; |
| 11272 | |
| 11273 | DimAnimator (SurfaceSession session) { |
| 11274 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11275 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11276 | + mDimSurface + ": CREATE"); |
| 11277 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11278 | mDimSurface = new Surface(session, 0, |
| 11279 | "DimSurface", |
| 11280 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11281 | Surface.FX_SURFACE_DIM); |
| 11282 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11283 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11284 | } |
| 11285 | } |
| 11286 | } |
| 11287 | |
| 11288 | /** |
| 11289 | * Show the dim surface. |
| 11290 | */ |
| 11291 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11292 | if (!mDimShown) { |
| 11293 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11294 | dw + "x" + dh + ")"); |
| 11295 | mDimShown = true; |
| 11296 | try { |
| 11297 | mDimSurface.setPosition(0, 0); |
| 11298 | mDimSurface.setSize(dw, dh); |
| 11299 | mDimSurface.show(); |
| 11300 | } catch (RuntimeException e) { |
| 11301 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11302 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11303 | } |
| 11304 | } |
| 11305 | |
| 11306 | /** |
| 11307 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11308 | * {@link updateSurface} after all windows are examined. |
| 11309 | */ |
| 11310 | void updateParameters(WindowState w, long currentTime) { |
| 11311 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11312 | |
| 11313 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11314 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11315 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11316 | if (mDimTargetAlpha != target) { |
| 11317 | // If the desired dim level has changed, then |
| 11318 | // start an animation to it. |
| 11319 | mLastDimAnimTime = currentTime; |
| 11320 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11321 | ? w.mAnimation.computeDurationHint() |
| 11322 | : DEFAULT_DIM_DURATION; |
| 11323 | if (target > mDimTargetAlpha) { |
| 11324 | // This is happening behind the activity UI, |
| 11325 | // so we can make it run a little longer to |
| 11326 | // give a stronger impression without disrupting |
| 11327 | // the user. |
| 11328 | duration *= DIM_DURATION_MULTIPLIER; |
| 11329 | } |
| 11330 | if (duration < 1) { |
| 11331 | // Don't divide by zero |
| 11332 | duration = 1; |
| 11333 | } |
| 11334 | mDimTargetAlpha = target; |
| 11335 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11336 | } |
| 11337 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11338 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11339 | /** |
| 11340 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11341 | * false when the animation is finished and the dim surface is hidden. |
| 11342 | */ |
| 11343 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11344 | if (!dimming) { |
| 11345 | if (mDimTargetAlpha != 0) { |
| 11346 | mLastDimAnimTime = currentTime; |
| 11347 | mDimTargetAlpha = 0; |
| 11348 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11349 | } |
| 11350 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11351 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11352 | boolean animating = false; |
| 11353 | if (mLastDimAnimTime != 0) { |
| 11354 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11355 | * (currentTime-mLastDimAnimTime); |
| 11356 | boolean more = true; |
| 11357 | if (displayFrozen) { |
| 11358 | // If the display is frozen, there is no reason to animate. |
| 11359 | more = false; |
| 11360 | } else if (mDimDeltaPerMs > 0) { |
| 11361 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11362 | more = false; |
| 11363 | } |
| 11364 | } else if (mDimDeltaPerMs < 0) { |
| 11365 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11366 | more = false; |
| 11367 | } |
| 11368 | } else { |
| 11369 | more = false; |
| 11370 | } |
| 11371 | |
| 11372 | // Do we need to continue animating? |
| 11373 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11374 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11375 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11376 | mLastDimAnimTime = currentTime; |
| 11377 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11378 | animating = true; |
| 11379 | } else { |
| 11380 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11381 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11382 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11383 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11384 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11385 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11386 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11387 | + ": HIDE"); |
| 11388 | try { |
| 11389 | mDimSurface.hide(); |
| 11390 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11391 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11392 | } |
| 11393 | mDimShown = false; |
| 11394 | } |
| 11395 | } |
| 11396 | } |
| 11397 | return animating; |
| 11398 | } |
| 11399 | |
| 11400 | public void printTo(PrintWriter pw) { |
| 11401 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11402 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11403 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11404 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11405 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11406 | } |
| 11407 | } |
| 11408 | |
| 11409 | /** |
| 11410 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11411 | * This is used for opening/closing transition for apps in compatible mode. |
| 11412 | */ |
| 11413 | private static class FadeInOutAnimation extends Animation { |
| 11414 | int mWidth; |
| 11415 | boolean mFadeIn; |
| 11416 | |
| 11417 | public FadeInOutAnimation(boolean fadeIn) { |
| 11418 | setInterpolator(new AccelerateInterpolator()); |
| 11419 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11420 | mFadeIn = fadeIn; |
| 11421 | } |
| 11422 | |
| 11423 | @Override |
| 11424 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11425 | float x = interpolatedTime; |
| 11426 | if (!mFadeIn) { |
| 11427 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11428 | } |
| 11429 | if (x < 0.5) { |
| 11430 | // move the window out of the screen. |
| 11431 | t.getMatrix().setTranslate(mWidth, 0); |
| 11432 | } else { |
| 11433 | t.getMatrix().setTranslate(0, 0);// show |
| 11434 | t.setAlpha((x - 0.5f) * 2); |
| 11435 | } |
| 11436 | } |
| 11437 | |
| 11438 | @Override |
| 11439 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11440 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11441 | mWidth = width; |
| 11442 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11443 | |
| 11444 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11445 | public int getZAdjustment() { |
| 11446 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11447 | } |
| 11448 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11449 | } |