| 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.am.BatteryStatsService; |
| 52 | |
| 53 | import android.Manifest; |
| 54 | import android.app.ActivityManagerNative; |
| 55 | import android.app.IActivityManager; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 56 | import android.app.admin.DevicePolicyManager; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 57 | import android.content.BroadcastReceiver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.Context; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 59 | import android.content.Intent; |
| 60 | import android.content.IntentFilter; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.content.pm.ActivityInfo; |
| 62 | import android.content.pm.PackageManager; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 63 | import android.content.res.CompatibilityInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.content.res.Configuration; |
| 65 | import android.graphics.Matrix; |
| 66 | import android.graphics.PixelFormat; |
| 67 | import android.graphics.Rect; |
| 68 | import android.graphics.Region; |
| 69 | import android.os.BatteryStats; |
| 70 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 71 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.Debug; |
| 73 | import android.os.Handler; |
| 74 | import android.os.IBinder; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 75 | import android.os.LatencyTimer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.os.LocalPowerManager; |
| 77 | import android.os.Looper; |
| 78 | import android.os.Message; |
| 79 | import android.os.Parcel; |
| 80 | import android.os.ParcelFileDescriptor; |
| 81 | import android.os.Power; |
| 82 | import android.os.PowerManager; |
| 83 | import android.os.Process; |
| 84 | import android.os.RemoteException; |
| 85 | import android.os.ServiceManager; |
| 86 | import android.os.SystemClock; |
| 87 | import android.os.SystemProperties; |
| 88 | import android.os.TokenWatcher; |
| 89 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 90 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.util.EventLog; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 92 | import android.util.Log; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 93 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.SparseIntArray; |
| 95 | import android.view.Display; |
| 96 | import android.view.Gravity; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 97 | import android.view.HapticFeedbackConstants; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.view.IApplicationToken; |
| 99 | import android.view.IOnKeyguardExitResult; |
| 100 | import android.view.IRotationWatcher; |
| 101 | import android.view.IWindow; |
| 102 | import android.view.IWindowManager; |
| 103 | import android.view.IWindowSession; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 104 | import android.view.InputChannel; |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 105 | import android.view.InputDevice; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 106 | import android.view.InputQueue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import android.view.KeyEvent; |
| 108 | import android.view.MotionEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | import android.view.Surface; |
| 110 | import android.view.SurfaceSession; |
| 111 | import android.view.View; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 112 | import android.view.ViewConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.ViewTreeObserver; |
| 114 | import android.view.WindowManager; |
| 115 | import android.view.WindowManagerImpl; |
| 116 | import android.view.WindowManagerPolicy; |
| 117 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 118 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | import android.view.animation.Animation; |
| 120 | import android.view.animation.AnimationUtils; |
| 121 | import android.view.animation.Transformation; |
| 122 | |
| 123 | import java.io.BufferedWriter; |
| 124 | import java.io.File; |
| 125 | import java.io.FileDescriptor; |
| 126 | import java.io.IOException; |
| 127 | import java.io.OutputStream; |
| 128 | import java.io.OutputStreamWriter; |
| 129 | import java.io.PrintWriter; |
| 130 | import java.io.StringWriter; |
| 131 | import java.net.Socket; |
| 132 | import java.util.ArrayList; |
| 133 | import java.util.HashMap; |
| 134 | import java.util.HashSet; |
| 135 | import java.util.Iterator; |
| 136 | import java.util.List; |
| 137 | |
| 138 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 139 | public class WindowManagerService extends IWindowManager.Stub |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 140 | implements Watchdog.Monitor { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | static final String TAG = "WindowManager"; |
| 142 | static final boolean DEBUG = false; |
| 143 | static final boolean DEBUG_FOCUS = false; |
| 144 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 146 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_LAYERS = false; |
| 148 | static final boolean DEBUG_INPUT = false; |
| 149 | static final boolean DEBUG_INPUT_METHOD = false; |
| 150 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 151 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 153 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 155 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 156 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 157 | static final boolean DEBUG_WALLPAPER = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 159 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 160 | static final boolean MEASURE_LATENCY = false; |
| 161 | static private LatencyTimer lt; |
| 162 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static final boolean PROFILE_ORIENTATION = false; |
| 164 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 165 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | /** How much to multiply the policy's type layer, to reserve room |
| 168 | * for multiple windows of the same type and Z-ordering adjustment |
| 169 | * with TYPE_LAYER_OFFSET. */ |
| 170 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| 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 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 173 | * or below others in the same layer. */ |
| 174 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 175 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | /** How much to increment the layer for each window, to reserve room |
| 177 | * for effect surfaces between them. |
| 178 | */ |
| 179 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | /** The maximum length we will accept for a loaded animation duration: |
| 182 | * this is 10 seconds. |
| 183 | */ |
| 184 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 185 | |
| 186 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 187 | * value to another, when no window animation is driving it. |
| 188 | */ |
| 189 | static final int DEFAULT_DIM_DURATION = 200; |
| 190 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 191 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 192 | * compatible windows. |
| 193 | */ |
| 194 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 197 | */ |
| 198 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 199 | |
| 200 | // Maximum number of milliseconds to wait for input event injection. |
| 201 | // FIXME is this value reasonable? |
| 202 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 203 | |
| 204 | // Default input dispatching timeout in nanoseconds. |
| 205 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 208 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 209 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 210 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 213 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 217 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 218 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 219 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 221 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 223 | private static final int ALLOW_DISABLE_YES = 1; |
| 224 | private static final int ALLOW_DISABLE_NO = 0; |
| 225 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 226 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 227 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 228 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 229 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | public void acquired() { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 231 | if (shouldAllowDisableKeyguard()) { |
| 232 | mPolicy.enableKeyguard(false); |
| 233 | mKeyguardDisabled = true; |
| 234 | } else { |
| 235 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 236 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | } |
| 238 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 239 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 240 | synchronized (mKeyguardTokenWatcher) { |
| 241 | mKeyguardDisabled = false; |
| 242 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | }; |
| 246 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 247 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 248 | @Override |
| 249 | public void onReceive(Context context, Intent intent) { |
| 250 | mPolicy.enableKeyguard(true); |
| 251 | synchronized(mKeyguardTokenWatcher) { |
| 252 | // lazily evaluate this next time we're asked to disable keyguard |
| 253 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 254 | mKeyguardDisabled = false; |
| 255 | } |
| 256 | } |
| 257 | }; |
| 258 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | final Context mContext; |
| 260 | |
| 261 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 264 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 266 | |
| 267 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | /** |
| 272 | * All currently active sessions with clients. |
| 273 | */ |
| 274 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | /** |
| 277 | * Mapping from an IWindow IBinder to the server's Window object. |
| 278 | * This is also used as the lock for all of our state. |
| 279 | */ |
| 280 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 281 | |
| 282 | /** |
| 283 | * Mapping from a token IBinder to a WindowToken object. |
| 284 | */ |
| 285 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 286 | new HashMap<IBinder, WindowToken>(); |
| 287 | |
| 288 | /** |
| 289 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 290 | * over them. |
| 291 | */ |
| 292 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | /** |
| 295 | * Window tokens that are in the process of exiting, but still |
| 296 | * on screen for animations. |
| 297 | */ |
| 298 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 299 | |
| 300 | /** |
| 301 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 302 | * controlling the ordering of windows in different applications. This |
| 303 | * contains WindowToken objects. |
| 304 | */ |
| 305 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 306 | |
| 307 | /** |
| 308 | * Application tokens that are in the process of exiting, but still |
| 309 | * on screen for animations. |
| 310 | */ |
| 311 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 312 | |
| 313 | /** |
| 314 | * List of window tokens that have finished starting their application, |
| 315 | * and now need to have the policy remove their windows. |
| 316 | */ |
| 317 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 318 | |
| 319 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 320 | * This was the app token that was used to retrieve the last enter |
| 321 | * animation. It will be used for the next exit animation. |
| 322 | */ |
| 323 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 324 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 325 | /** |
| 326 | * These were the layout params used to retrieve the last enter animation. |
| 327 | * They will be used for the next exit animation. |
| 328 | */ |
| 329 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 330 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 331 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | * Z-ordered (bottom-most first) list of all Window objects. |
| 333 | */ |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 334 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | |
| 336 | /** |
| 337 | * Windows that are being resized. Used so we can tell the client about |
| 338 | * the resize after closing the transaction in which we resized the |
| 339 | * underlying surface. |
| 340 | */ |
| 341 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 342 | |
| 343 | /** |
| 344 | * Windows whose animations have ended and now must be removed. |
| 345 | */ |
| 346 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 347 | |
| 348 | /** |
| 349 | * Windows whose surface should be destroyed. |
| 350 | */ |
| 351 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 352 | |
| 353 | /** |
| 354 | * Windows that have lost input focus and are waiting for the new |
| 355 | * focus window to be displayed before they are told about this. |
| 356 | */ |
| 357 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 358 | |
| 359 | /** |
| 360 | * This is set when we have run out of memory, and will either be an empty |
| 361 | * list or contain windows that need to be force removed. |
| 362 | */ |
| 363 | ArrayList<WindowState> mForceRemoves; |
| 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 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 366 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 368 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | Surface mBlurSurface; |
| 370 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 371 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | final float[] mTmpFloats = new float[9]; |
| 375 | |
| 376 | boolean mSafeMode; |
| 377 | boolean mDisplayEnabled = false; |
| 378 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 379 | int mInitialDisplayWidth = 0; |
| 380 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | int mRotation = 0; |
| 382 | int mRequestedRotation = 0; |
| 383 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 384 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | ArrayList<IRotationWatcher> mRotationWatchers |
| 386 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 387 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | boolean mLayoutNeeded = true; |
| 389 | boolean mAnimationPending = false; |
| 390 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 391 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | boolean mWindowsFreezingScreen = false; |
| 393 | long mFreezeGcPending = 0; |
| 394 | int mAppsFreezingScreen = 0; |
| 395 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 396 | int mLayoutSeq = 0; |
| 397 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 398 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 399 | boolean mFocusMayChange; |
| 400 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 401 | Configuration mCurConfiguration = new Configuration(); |
| 402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | // This is held as long as we have the screen frozen, to give us time to |
| 404 | // perform a rotation animation when turning off shows the lock screen which |
| 405 | // changes the orientation. |
| 406 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 407 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | // State management of app transitions. When we are preparing for a |
| 409 | // transition, mNextAppTransition will be the kind of transition to |
| 410 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 411 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 412 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 413 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 414 | String mNextAppTransitionPackage; |
| 415 | int mNextAppTransitionEnter; |
| 416 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 418 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | boolean mAppTransitionTimeout = false; |
| 420 | boolean mStartingIconInTransition = false; |
| 421 | boolean mSkipAppTransitionAnimation = false; |
| 422 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 423 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 424 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 425 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 426 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 428 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | H mH = new H(); |
| 430 | |
| 431 | WindowState mCurrentFocus = null; |
| 432 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | // This just indicates the window the input method is on top of, not |
| 435 | // necessarily the window its input is going to. |
| 436 | WindowState mInputMethodTarget = null; |
| 437 | WindowState mUpcomingInputMethodTarget = null; |
| 438 | boolean mInputMethodTargetWaitingAnim; |
| 439 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 440 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | WindowState mInputMethodWindow = null; |
| 442 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 443 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 444 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 445 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 446 | // If non-null, this is the currently visible window that is associated |
| 447 | // with the wallpaper. |
| 448 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 449 | // If non-null, we are in the middle of animating from one wallpaper target |
| 450 | // to another, and this is the lower one in Z-order. |
| 451 | WindowState mLowerWallpaperTarget = null; |
| 452 | // If non-null, we are in the middle of animating from one wallpaper target |
| 453 | // to another, and this is the higher one in Z-order. |
| 454 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 455 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 456 | float mLastWallpaperX = -1; |
| 457 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 458 | float mLastWallpaperXStep = -1; |
| 459 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 460 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 461 | // changing its scroll position. |
| 462 | WindowState mWaitingOnWallpaper; |
| 463 | // The last time we had a timeout when waiting for a wallpaper. |
| 464 | long mLastWallpaperTimeoutTime; |
| 465 | // We give a wallpaper up to 150ms to finish scrolling. |
| 466 | static final long WALLPAPER_TIMEOUT = 150; |
| 467 | // Time we wait after a timeout before trying to wait again. |
| 468 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 469 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | AppWindowToken mFocusedApp = null; |
| 471 | |
| 472 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | float mWindowAnimationScale = 1.0f; |
| 475 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 476 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 477 | final InputManager mInputManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | |
| 479 | // Who is holding the screen on. |
| 480 | Session mHoldingScreenOn; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 481 | PowerManager.WakeLock mHoldingScreenWakeLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 482 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 483 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 484 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | /** |
| 486 | * Whether the UI is currently running in touch mode (not showing |
| 487 | * navigational focus because the user is directly pressing the screen). |
| 488 | */ |
| 489 | boolean mInTouchMode = false; |
| 490 | |
| 491 | private ViewServer mViewServer; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 492 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 493 | new ArrayList<WindowChangeListener>(); |
| 494 | private boolean mWindowsChanged = false; |
| 495 | |
| 496 | public interface WindowChangeListener { |
| 497 | public void windowsChanged(); |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 498 | public void focusChanged(); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 499 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 501 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 502 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 503 | |
| 504 | // The frame use to limit the size of the app running in compatibility mode. |
| 505 | Rect mCompatibleScreenFrame = new Rect(); |
| 506 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 507 | Surface mBackgroundFillerSurface = null; |
| 508 | boolean mBackgroundFillerShown = false; |
| 509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | public static WindowManagerService main(Context context, |
| 511 | PowerManagerService pm, boolean haveInputMethods) { |
| 512 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 513 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 514 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | synchronized (thr) { |
| 516 | while (thr.mService == null) { |
| 517 | try { |
| 518 | thr.wait(); |
| 519 | } catch (InterruptedException e) { |
| 520 | } |
| 521 | } |
| 522 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 523 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | return thr.mService; |
| 525 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | static class WMThread extends Thread { |
| 528 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 529 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | private final Context mContext; |
| 531 | private final PowerManagerService mPM; |
| 532 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 533 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | public WMThread(Context context, PowerManagerService pm, |
| 535 | boolean haveInputMethods) { |
| 536 | super("WindowManager"); |
| 537 | mContext = context; |
| 538 | mPM = pm; |
| 539 | mHaveInputMethods = haveInputMethods; |
| 540 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 541 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | public void run() { |
| 543 | Looper.prepare(); |
| 544 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 545 | mHaveInputMethods); |
| 546 | android.os.Process.setThreadPriority( |
| 547 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 548 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | synchronized (this) { |
| 551 | mService = s; |
| 552 | notifyAll(); |
| 553 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | Looper.loop(); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | static class PolicyThread extends Thread { |
| 560 | private final WindowManagerPolicy mPolicy; |
| 561 | private final WindowManagerService mService; |
| 562 | private final Context mContext; |
| 563 | private final PowerManagerService mPM; |
| 564 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 565 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | public PolicyThread(WindowManagerPolicy policy, |
| 567 | WindowManagerService service, Context context, |
| 568 | PowerManagerService pm) { |
| 569 | super("WindowManagerPolicy"); |
| 570 | mPolicy = policy; |
| 571 | mService = service; |
| 572 | mContext = context; |
| 573 | mPM = pm; |
| 574 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 575 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | public void run() { |
| 577 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 578 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 579 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 581 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | android.os.Process.setThreadPriority( |
| 583 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 584 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 586 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | synchronized (this) { |
| 588 | mRunning = true; |
| 589 | notifyAll(); |
| 590 | } |
| 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 | Looper.loop(); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | private WindowManagerService(Context context, PowerManagerService pm, |
| 597 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 598 | if (MEASURE_LATENCY) { |
| 599 | lt = new LatencyTimer(100, 1000); |
| 600 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | mContext = context; |
| 603 | mHaveInputMethods = haveInputMethods; |
| 604 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 605 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | mPowerManager = pm; |
| 608 | mPowerManager.setPolicy(mPolicy); |
| 609 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 610 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 611 | "SCREEN_FROZEN"); |
| 612 | mScreenFrozenLock.setReferenceCounted(false); |
| 613 | |
| 614 | mActivityManager = ActivityManagerNative.getDefault(); |
| 615 | mBatteryStats = BatteryStatsService.getService(); |
| 616 | |
| 617 | // Get persisted window scale setting |
| 618 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 619 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 620 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 621 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 622 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 623 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 624 | IntentFilter filter = new IntentFilter(); |
| 625 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 626 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 627 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 628 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 629 | "KEEP_SCREEN_ON_FLAG"); |
| 630 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 632 | mInputManager = new InputManager(context, this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 633 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 635 | thr.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 | synchronized (thr) { |
| 638 | while (!thr.mRunning) { |
| 639 | try { |
| 640 | thr.wait(); |
| 641 | } catch (InterruptedException e) { |
| 642 | } |
| 643 | } |
| 644 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 645 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 646 | mInputManager.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 647 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 648 | // Add ourself to the Watchdog monitors. |
| 649 | Watchdog.getInstance().addMonitor(this); |
| 650 | } |
| 651 | |
| 652 | @Override |
| 653 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 654 | throws RemoteException { |
| 655 | try { |
| 656 | return super.onTransact(code, data, reply, flags); |
| 657 | } catch (RuntimeException e) { |
| 658 | // The window manager only throws security exceptions, so let's |
| 659 | // log all others. |
| 660 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 661 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | } |
| 663 | throw e; |
| 664 | } |
| 665 | } |
| 666 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 667 | private void placeWindowAfter(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 669 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | TAG, "Adding window " + window + " at " |
| 671 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 672 | mWindows.add(i+1, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 673 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | } |
| 675 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 676 | private void placeWindowBefore(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 678 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | TAG, "Adding window " + window + " at " |
| 680 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 681 | mWindows.add(i, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 682 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | //This method finds out the index of a window that has the same app token as |
| 686 | //win. used for z ordering the windows in mWindows |
| 687 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 688 | //use a local variable to cache mWindows |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 689 | ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | int jmax = localmWindows.size(); |
| 691 | if(jmax == 0) { |
| 692 | return -1; |
| 693 | } |
| 694 | for(int j = (jmax-1); j >= 0; j--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 695 | WindowState wentry = localmWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 696 | if(wentry.mAppToken == win.mAppToken) { |
| 697 | return j; |
| 698 | } |
| 699 | } |
| 700 | return -1; |
| 701 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 702 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 704 | final IWindow client = win.mClient; |
| 705 | final WindowToken token = win.mToken; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 706 | final ArrayList<WindowState> localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 707 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | final int N = localmWindows.size(); |
| 709 | final WindowState attached = win.mAttachedWindow; |
| 710 | int i; |
| 711 | if (attached == null) { |
| 712 | int tokenWindowsPos = token.windows.size(); |
| 713 | if (token.appWindowToken != null) { |
| 714 | int index = tokenWindowsPos-1; |
| 715 | if (index >= 0) { |
| 716 | // If this application has existing windows, we |
| 717 | // simply place the new window on top of them... but |
| 718 | // keep the starting window on top. |
| 719 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 720 | // Base windows go behind everything else. |
| 721 | placeWindowBefore(token.windows.get(0), win); |
| 722 | tokenWindowsPos = 0; |
| 723 | } else { |
| 724 | AppWindowToken atoken = win.mAppToken; |
| 725 | if (atoken != null && |
| 726 | token.windows.get(index) == atoken.startingWindow) { |
| 727 | placeWindowBefore(token.windows.get(index), win); |
| 728 | tokenWindowsPos--; |
| 729 | } else { |
| 730 | int newIdx = findIdxBasedOnAppTokens(win); |
| 731 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 732 | //there is a window above this one associated with the same |
| 733 | //apptoken note that the window could be a floating window |
| 734 | //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] | 735 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 736 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 737 | TAG, "Adding window " + win + " at " |
| 738 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | localmWindows.add(newIdx+1, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 740 | mWindowsChanged = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 741 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 745 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | TAG, "Figuring out where to add app window " |
| 747 | + client.asBinder() + " (token=" + token + ")"); |
| 748 | // Figure out where the window should go, based on the |
| 749 | // order of applications. |
| 750 | final int NA = mAppTokens.size(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 751 | WindowState pos = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | for (i=NA-1; i>=0; i--) { |
| 753 | AppWindowToken t = mAppTokens.get(i); |
| 754 | if (t == token) { |
| 755 | i--; |
| 756 | break; |
| 757 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 758 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 759 | // We haven't reached the token yet; if this token |
| 760 | // is not going to the bottom and has windows, we can |
| 761 | // use it as an anchor for when we do reach the token. |
| 762 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | pos = t.windows.get(0); |
| 764 | } |
| 765 | } |
| 766 | // We now know the index into the apps. If we found |
| 767 | // an app window above, that gives us the position; else |
| 768 | // we need to look some more. |
| 769 | if (pos != null) { |
| 770 | // Move behind any windows attached to this one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 771 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | if (atoken != null) { |
| 773 | final int NC = atoken.windows.size(); |
| 774 | if (NC > 0) { |
| 775 | WindowState bottom = atoken.windows.get(0); |
| 776 | if (bottom.mSubLayer < 0) { |
| 777 | pos = bottom; |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | placeWindowBefore(pos, win); |
| 782 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 783 | // Continue looking down until we find the first |
| 784 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | while (i >= 0) { |
| 786 | AppWindowToken t = mAppTokens.get(i); |
| 787 | final int NW = t.windows.size(); |
| 788 | if (NW > 0) { |
| 789 | pos = t.windows.get(NW-1); |
| 790 | break; |
| 791 | } |
| 792 | i--; |
| 793 | } |
| 794 | if (pos != null) { |
| 795 | // Move in front of any windows attached to this |
| 796 | // one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 797 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | if (atoken != null) { |
| 799 | final int NC = atoken.windows.size(); |
| 800 | if (NC > 0) { |
| 801 | WindowState top = atoken.windows.get(NC-1); |
| 802 | if (top.mSubLayer >= 0) { |
| 803 | pos = top; |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | placeWindowAfter(pos, win); |
| 808 | } else { |
| 809 | // Just search for the start of this layer. |
| 810 | final int myLayer = win.mBaseLayer; |
| 811 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 812 | WindowState w = localmWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | if (w.mBaseLayer > myLayer) { |
| 814 | break; |
| 815 | } |
| 816 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 817 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 818 | TAG, "Adding window " + win + " at " |
| 819 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 821 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | } |
| 825 | } else { |
| 826 | // Figure out where window should go, based on layer. |
| 827 | final int myLayer = win.mBaseLayer; |
| 828 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 829 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | i++; |
| 831 | break; |
| 832 | } |
| 833 | } |
| 834 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 835 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 836 | TAG, "Adding window " + win + " at " |
| 837 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 839 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | } |
| 841 | if (addToToken) { |
| 842 | token.windows.add(tokenWindowsPos, win); |
| 843 | } |
| 844 | |
| 845 | } else { |
| 846 | // Figure out this window's ordering relative to the window |
| 847 | // it is attached to. |
| 848 | final int NA = token.windows.size(); |
| 849 | final int sublayer = win.mSubLayer; |
| 850 | int largestSublayer = Integer.MIN_VALUE; |
| 851 | WindowState windowWithLargestSublayer = null; |
| 852 | for (i=0; i<NA; i++) { |
| 853 | WindowState w = token.windows.get(i); |
| 854 | final int wSublayer = w.mSubLayer; |
| 855 | if (wSublayer >= largestSublayer) { |
| 856 | largestSublayer = wSublayer; |
| 857 | windowWithLargestSublayer = w; |
| 858 | } |
| 859 | if (sublayer < 0) { |
| 860 | // For negative sublayers, we go below all windows |
| 861 | // in the same sublayer. |
| 862 | if (wSublayer >= sublayer) { |
| 863 | if (addToToken) { |
| 864 | token.windows.add(i, win); |
| 865 | } |
| 866 | placeWindowBefore( |
| 867 | wSublayer >= 0 ? attached : w, win); |
| 868 | break; |
| 869 | } |
| 870 | } else { |
| 871 | // For positive sublayers, we go above all windows |
| 872 | // in the same sublayer. |
| 873 | if (wSublayer > sublayer) { |
| 874 | if (addToToken) { |
| 875 | token.windows.add(i, win); |
| 876 | } |
| 877 | placeWindowBefore(w, win); |
| 878 | break; |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | if (i >= NA) { |
| 883 | if (addToToken) { |
| 884 | token.windows.add(win); |
| 885 | } |
| 886 | if (sublayer < 0) { |
| 887 | placeWindowBefore(attached, win); |
| 888 | } else { |
| 889 | placeWindowAfter(largestSublayer >= 0 |
| 890 | ? windowWithLargestSublayer |
| 891 | : attached, |
| 892 | win); |
| 893 | } |
| 894 | } |
| 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 | if (win.mAppToken != null && addToToken) { |
| 898 | win.mAppToken.allAppWindows.add(win); |
| 899 | } |
| 900 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | static boolean canBeImeTarget(WindowState w) { |
| 903 | final int fl = w.mAttrs.flags |
| 904 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 905 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 906 | return w.isVisibleOrAdding(); |
| 907 | } |
| 908 | return false; |
| 909 | } |
| 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 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 912 | final ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | final int N = localmWindows.size(); |
| 914 | WindowState w = null; |
| 915 | int i = N; |
| 916 | while (i > 0) { |
| 917 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 918 | w = localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 919 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 920 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | // + Integer.toHexString(w.mAttrs.flags)); |
| 922 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 923 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 924 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | // Yet more tricksyness! If this window is a "starting" |
| 926 | // window, we do actually want to be on top of it, but |
| 927 | // it is not -really- where input will go. So if the caller |
| 928 | // is not actually looking to move the IME, look down below |
| 929 | // for a real window to target... |
| 930 | if (!willMove |
| 931 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 932 | && i > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 933 | WindowState wb = localmWindows.get(i-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 935 | i--; |
| 936 | w = wb; |
| 937 | } |
| 938 | } |
| 939 | break; |
| 940 | } |
| 941 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 944 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 945 | 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] | 946 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 948 | if (willMove && w != null) { |
| 949 | final WindowState curTarget = mInputMethodTarget; |
| 950 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 951 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | // Now some fun for dealing with window animations that |
| 953 | // modify the Z order. We need to look at all windows below |
| 954 | // the current target that are in this app, finding the highest |
| 955 | // visible one in layering. |
| 956 | AppWindowToken token = curTarget.mAppToken; |
| 957 | WindowState highestTarget = null; |
| 958 | int highestPos = 0; |
| 959 | if (token.animating || token.animation != null) { |
| 960 | int pos = 0; |
| 961 | pos = localmWindows.indexOf(curTarget); |
| 962 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 963 | WindowState win = localmWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | if (win.mAppToken != token) { |
| 965 | break; |
| 966 | } |
| 967 | if (!win.mRemoved) { |
| 968 | if (highestTarget == null || win.mAnimLayer > |
| 969 | highestTarget.mAnimLayer) { |
| 970 | highestTarget = win; |
| 971 | highestPos = pos; |
| 972 | } |
| 973 | } |
| 974 | pos--; |
| 975 | } |
| 976 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 979 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | + mNextAppTransition + " " + highestTarget |
| 981 | + " animating=" + highestTarget.isAnimating() |
| 982 | + " layer=" + highestTarget.mAnimLayer |
| 983 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 984 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 985 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | // If we are currently setting up for an animation, |
| 987 | // hold everything until we can find out what will happen. |
| 988 | mInputMethodTargetWaitingAnim = true; |
| 989 | mInputMethodTarget = highestTarget; |
| 990 | return highestPos + 1; |
| 991 | } else if (highestTarget.isAnimating() && |
| 992 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 993 | // If the window we are currently targeting is involved |
| 994 | // with an animation, and it is on top of the next target |
| 995 | // we will be over, then hold off on moving until |
| 996 | // that is done. |
| 997 | mInputMethodTarget = highestTarget; |
| 998 | return highestPos + 1; |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1003 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1004 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | if (w != null) { |
| 1006 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1007 | if (DEBUG_INPUT_METHOD) { |
| 1008 | RuntimeException e = null; |
| 1009 | if (!HIDE_STACK_CRAWLS) { |
| 1010 | e = new RuntimeException(); |
| 1011 | e.fillInStackTrace(); |
| 1012 | } |
| 1013 | Slog.w(TAG, "Moving IM target from " |
| 1014 | + mInputMethodTarget + " to " + w, e); |
| 1015 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | mInputMethodTarget = w; |
| 1017 | if (w.mAppToken != null) { |
| 1018 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1019 | } else { |
| 1020 | setInputMethodAnimLayerAdjustment(0); |
| 1021 | } |
| 1022 | } |
| 1023 | return i+1; |
| 1024 | } |
| 1025 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1026 | if (DEBUG_INPUT_METHOD) { |
| 1027 | RuntimeException e = null; |
| 1028 | if (!HIDE_STACK_CRAWLS) { |
| 1029 | e = new RuntimeException(); |
| 1030 | e.fillInStackTrace(); |
| 1031 | } |
| 1032 | Slog.w(TAG, "Moving IM target from " |
| 1033 | + mInputMethodTarget + " to null", e); |
| 1034 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | mInputMethodTarget = null; |
| 1036 | setInputMethodAnimLayerAdjustment(0); |
| 1037 | } |
| 1038 | return -1; |
| 1039 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1042 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1043 | if (pos >= 0) { |
| 1044 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1045 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1046 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | mWindows.add(pos, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1048 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | moveInputMethodDialogsLocked(pos+1); |
| 1050 | return; |
| 1051 | } |
| 1052 | win.mTargetAppToken = null; |
| 1053 | addWindowToListInOrderLocked(win, true); |
| 1054 | moveInputMethodDialogsLocked(pos); |
| 1055 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1058 | 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] | 1059 | mInputMethodAnimLayerAdjustment = adj; |
| 1060 | WindowState imw = mInputMethodWindow; |
| 1061 | if (imw != null) { |
| 1062 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1063 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | + " anim layer: " + imw.mAnimLayer); |
| 1065 | int wi = imw.mChildWindows.size(); |
| 1066 | while (wi > 0) { |
| 1067 | wi--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1068 | WindowState cw = imw.mChildWindows.get(wi); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1070 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | + " anim layer: " + cw.mAnimLayer); |
| 1072 | } |
| 1073 | } |
| 1074 | int di = mInputMethodDialogs.size(); |
| 1075 | while (di > 0) { |
| 1076 | di --; |
| 1077 | imw = mInputMethodDialogs.get(di); |
| 1078 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1079 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | + " anim layer: " + imw.mAnimLayer); |
| 1081 | } |
| 1082 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1083 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1085 | int wpos = mWindows.indexOf(win); |
| 1086 | if (wpos >= 0) { |
| 1087 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1088 | 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] | 1089 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1090 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | int NC = win.mChildWindows.size(); |
| 1092 | while (NC > 0) { |
| 1093 | NC--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1094 | WindowState cw = win.mChildWindows.get(NC); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | int cpos = mWindows.indexOf(cw); |
| 1096 | if (cpos >= 0) { |
| 1097 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1098 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1099 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | mWindows.remove(cpos); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | return interestingPos; |
| 1105 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1108 | addWindowToListInOrderLocked(win, false); |
| 1109 | // This is a hack to get all of the child windows added as well |
| 1110 | // at the right position. Child windows should be rare and |
| 1111 | // this case should be rare, so it shouldn't be that big a deal. |
| 1112 | int wpos = mWindows.indexOf(win); |
| 1113 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1114 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1115 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1117 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | reAddWindowLocked(wpos, win); |
| 1119 | } |
| 1120 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1121 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | void logWindowList(String prefix) { |
| 1123 | int N = mWindows.size(); |
| 1124 | while (N > 0) { |
| 1125 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1126 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1127 | } |
| 1128 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | void moveInputMethodDialogsLocked(int pos) { |
| 1131 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1134 | 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] | 1135 | for (int i=0; i<N; i++) { |
| 1136 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1137 | } |
| 1138 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1139 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | logWindowList(" "); |
| 1141 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1142 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | if (pos >= 0) { |
| 1144 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1145 | if (pos < mWindows.size()) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1146 | WindowState wp = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | if (wp == mInputMethodWindow) { |
| 1148 | pos++; |
| 1149 | } |
| 1150 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1151 | 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] | 1152 | for (int i=0; i<N; i++) { |
| 1153 | WindowState win = dialogs.get(i); |
| 1154 | win.mTargetAppToken = targetAppToken; |
| 1155 | pos = reAddWindowLocked(pos, win); |
| 1156 | } |
| 1157 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1158 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | logWindowList(" "); |
| 1160 | } |
| 1161 | return; |
| 1162 | } |
| 1163 | for (int i=0; i<N; i++) { |
| 1164 | WindowState win = dialogs.get(i); |
| 1165 | win.mTargetAppToken = null; |
| 1166 | reAddWindowToListInOrderLocked(win); |
| 1167 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1168 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | logWindowList(" "); |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1173 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1174 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1175 | final WindowState imWin = mInputMethodWindow; |
| 1176 | final int DN = mInputMethodDialogs.size(); |
| 1177 | if (imWin == null && DN == 0) { |
| 1178 | return false; |
| 1179 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1182 | if (imPos >= 0) { |
| 1183 | // In this case, the input method windows are to be placed |
| 1184 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | // First check to see if the input method windows are already |
| 1187 | // located here, and contiguous. |
| 1188 | final int N = mWindows.size(); |
| 1189 | WindowState firstImWin = imPos < N |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1190 | ? mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | // Figure out the actual input method window that should be |
| 1193 | // at the bottom of their stack. |
| 1194 | WindowState baseImWin = imWin != null |
| 1195 | ? imWin : mInputMethodDialogs.get(0); |
| 1196 | if (baseImWin.mChildWindows.size() > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1197 | WindowState cw = baseImWin.mChildWindows.get(0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1199 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1200 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | if (firstImWin == baseImWin) { |
| 1202 | // The windows haven't moved... but are they still contiguous? |
| 1203 | // First find the top IM window. |
| 1204 | int pos = imPos+1; |
| 1205 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1206 | if (!(mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | break; |
| 1208 | } |
| 1209 | pos++; |
| 1210 | } |
| 1211 | pos++; |
| 1212 | // Now there should be no more input method windows above. |
| 1213 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1214 | if ((mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | break; |
| 1216 | } |
| 1217 | pos++; |
| 1218 | } |
| 1219 | if (pos >= N) { |
| 1220 | // All is good! |
| 1221 | return false; |
| 1222 | } |
| 1223 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1224 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | if (imWin != null) { |
| 1226 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1227 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | logWindowList(" "); |
| 1229 | } |
| 1230 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1231 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1232 | 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] | 1233 | logWindowList(" "); |
| 1234 | } |
| 1235 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1236 | reAddWindowLocked(imPos, imWin); |
| 1237 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1238 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1239 | logWindowList(" "); |
| 1240 | } |
| 1241 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1242 | } else { |
| 1243 | moveInputMethodDialogsLocked(imPos); |
| 1244 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | } else { |
| 1247 | // In this case, the input method windows go in a fixed layer, |
| 1248 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1249 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1251 | 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] | 1252 | tmpRemoveWindowLocked(0, imWin); |
| 1253 | imWin.mTargetAppToken = null; |
| 1254 | reAddWindowToListInOrderLocked(imWin); |
| 1255 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1256 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | logWindowList(" "); |
| 1258 | } |
| 1259 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1260 | } else { |
| 1261 | moveInputMethodDialogsLocked(-1);; |
| 1262 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1263 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1265 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | if (needAssignLayers) { |
| 1267 | assignLayersLocked(); |
| 1268 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1269 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | return true; |
| 1271 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | void adjustInputMethodDialogsLocked() { |
| 1274 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1275 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1276 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1277 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1278 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1279 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1280 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1281 | ? wallpaperTarget.mAppToken.animation : null) |
| 1282 | + " upper=" + mUpperWallpaperTarget |
| 1283 | + " lower=" + mLowerWallpaperTarget); |
| 1284 | return (wallpaperTarget != null |
| 1285 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1286 | && wallpaperTarget.mAppToken.animation != null))) |
| 1287 | || mUpperWallpaperTarget != null |
| 1288 | || mLowerWallpaperTarget != null; |
| 1289 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1290 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1291 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1292 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1293 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1294 | int adjustWallpaperWindowsLocked() { |
| 1295 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1296 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1297 | final int dw = mDisplay.getWidth(); |
| 1298 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1299 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1300 | // First find top-most window that has asked to be on top of the |
| 1301 | // wallpaper; all wallpapers go behind it. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1302 | final ArrayList<WindowState> localmWindows = mWindows; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1303 | int N = localmWindows.size(); |
| 1304 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1305 | WindowState foundW = null; |
| 1306 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1307 | WindowState topCurW = null; |
| 1308 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1309 | int i = N; |
| 1310 | while (i > 0) { |
| 1311 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1312 | w = localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1313 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1314 | if (topCurW == null) { |
| 1315 | topCurW = w; |
| 1316 | topCurI = i; |
| 1317 | } |
| 1318 | continue; |
| 1319 | } |
| 1320 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1321 | if (w.mAppToken != null) { |
| 1322 | // If this window's app token is hidden and not animating, |
| 1323 | // it is of no interest to us. |
| 1324 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1325 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1326 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1327 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1328 | continue; |
| 1329 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1330 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1331 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1332 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1333 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1334 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1335 | && (mWallpaperTarget == w |
| 1336 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1337 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1338 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1339 | foundW = w; |
| 1340 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1341 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1342 | && w.mAppToken.animation != null) |
| 1343 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1344 | // The current wallpaper target is animating, so we'll |
| 1345 | // look behind it for another possible target and figure |
| 1346 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1347 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1348 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1349 | continue; |
| 1350 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1351 | break; |
| 1352 | } |
| 1353 | } |
| 1354 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1355 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1356 | // If we are currently waiting for an app transition, and either |
| 1357 | // the current target or the next target are involved with it, |
| 1358 | // then hold off on doing anything with the wallpaper. |
| 1359 | // Note that we are checking here for just whether the target |
| 1360 | // is part of an app token... which is potentially overly aggressive |
| 1361 | // (the app token may not be involved in the transition), but good |
| 1362 | // enough (we'll just wait until whatever transition is pending |
| 1363 | // executes). |
| 1364 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1365 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1366 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1367 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1368 | } |
| 1369 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1370 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1371 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1372 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1373 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1374 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1375 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1376 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1377 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1378 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1379 | + " oldTarget: " + mWallpaperTarget); |
| 1380 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1381 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1382 | mLowerWallpaperTarget = null; |
| 1383 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1384 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1385 | WindowState oldW = mWallpaperTarget; |
| 1386 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1387 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1388 | // Now what is happening... if the current and new targets are |
| 1389 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1390 | if (foundW != null && oldW != null) { |
| 1391 | boolean oldAnim = oldW.mAnimation != null |
| 1392 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1393 | boolean foundAnim = foundW.mAnimation != null |
| 1394 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1395 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1396 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1397 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1398 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1399 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1400 | int oldI = localmWindows.indexOf(oldW); |
| 1401 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1402 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1403 | } |
| 1404 | if (oldI >= 0) { |
| 1405 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1406 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1407 | + "=" + oldW + "; new#" + foundI |
| 1408 | + "=" + foundW); |
| 1409 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1410 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1411 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1412 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1413 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1414 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1415 | } |
| 1416 | mWallpaperTarget = oldW; |
| 1417 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1418 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1419 | // Now set the upper and lower wallpaper targets |
| 1420 | // correctly, and make sure that we are positioning |
| 1421 | // the wallpaper below the lower. |
| 1422 | if (foundI > oldI) { |
| 1423 | // The new target is on top of the old one. |
| 1424 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1425 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1426 | } |
| 1427 | mUpperWallpaperTarget = foundW; |
| 1428 | mLowerWallpaperTarget = oldW; |
| 1429 | foundW = oldW; |
| 1430 | foundI = oldI; |
| 1431 | } else { |
| 1432 | // The new target is below the old one. |
| 1433 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1434 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1435 | } |
| 1436 | mUpperWallpaperTarget = oldW; |
| 1437 | mLowerWallpaperTarget = foundW; |
| 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1442 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1443 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1444 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1445 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1446 | || (mLowerWallpaperTarget.mAppToken != null |
| 1447 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1448 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1449 | || (mUpperWallpaperTarget.mAppToken != null |
| 1450 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1451 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1452 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1453 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1454 | } |
| 1455 | mLowerWallpaperTarget = null; |
| 1456 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1457 | } |
| 1458 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1459 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1460 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1461 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1462 | // The window is visible to the compositor... but is it visible |
| 1463 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1464 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1465 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1466 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1467 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1468 | // its layer adjustment. Only do this if we are not transfering |
| 1469 | // between two wallpaper targets. |
| 1470 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1471 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1472 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1473 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1474 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1475 | * TYPE_LAYER_MULTIPLIER |
| 1476 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1477 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1478 | // Now w is the window we are supposed to be behind... but we |
| 1479 | // 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] | 1480 | // AND any starting window associated with it, AND below the |
| 1481 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1482 | while (foundI > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1483 | WindowState wb = localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1484 | if (wb.mBaseLayer < maxLayer && |
| 1485 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1486 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1487 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1488 | // This window is not related to the previous one in any |
| 1489 | // interesting way, so stop here. |
| 1490 | break; |
| 1491 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1492 | foundW = wb; |
| 1493 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1494 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1495 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1496 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1497 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1498 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1499 | if (foundW == null && topCurW != null) { |
| 1500 | // There is no wallpaper target, so it goes at the bottom. |
| 1501 | // We will assume it is the same place as last time, if known. |
| 1502 | foundW = topCurW; |
| 1503 | foundI = topCurI+1; |
| 1504 | } else { |
| 1505 | // Okay i is the position immediately above the wallpaper. Look at |
| 1506 | // what is below it for later. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1507 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1508 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1509 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1510 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1511 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1512 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1513 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1514 | } |
| 1515 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1516 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1517 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1518 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1519 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1520 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1521 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1522 | // are correctly placed. |
| 1523 | int curTokenIndex = mWallpaperTokens.size(); |
| 1524 | while (curTokenIndex > 0) { |
| 1525 | curTokenIndex--; |
| 1526 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1527 | if (token.hidden == visible) { |
| 1528 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1529 | token.hidden = !visible; |
| 1530 | // Need to do a layout to ensure the wallpaper now has the |
| 1531 | // correct size. |
| 1532 | mLayoutNeeded = true; |
| 1533 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1534 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1535 | int curWallpaperIndex = token.windows.size(); |
| 1536 | while (curWallpaperIndex > 0) { |
| 1537 | curWallpaperIndex--; |
| 1538 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1539 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1540 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1541 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1542 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1543 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1544 | // First, make sure the client has the current visibility |
| 1545 | // state. |
| 1546 | if (wallpaper.mWallpaperVisible != visible) { |
| 1547 | wallpaper.mWallpaperVisible = visible; |
| 1548 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1549 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1550 | "Setting visibility of wallpaper " + wallpaper |
| 1551 | + ": " + visible); |
| 1552 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1553 | } catch (RemoteException e) { |
| 1554 | } |
| 1555 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1556 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1557 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1558 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1559 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1560 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1561 | // First, if this window is at the current index, then all |
| 1562 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1563 | if (wallpaper == foundW) { |
| 1564 | foundI--; |
| 1565 | foundW = foundI > 0 |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1566 | ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1567 | continue; |
| 1568 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1569 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1570 | // The window didn't match... the current wallpaper window, |
| 1571 | // wherever it is, is in the wrong place, so make sure it is |
| 1572 | // not in the list. |
| 1573 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1574 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1575 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1576 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1577 | localmWindows.remove(oldIndex); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1578 | mWindowsChanged = true; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1579 | if (oldIndex < foundI) { |
| 1580 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1581 | } |
| 1582 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1583 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1584 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1585 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1586 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1587 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1588 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1589 | localmWindows.add(foundI, wallpaper); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1590 | mWindowsChanged = true; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1591 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1592 | } |
| 1593 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1594 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1595 | return changed; |
| 1596 | } |
| 1597 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1598 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1599 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1600 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1601 | mWallpaperAnimLayerAdjustment = adj; |
| 1602 | int curTokenIndex = mWallpaperTokens.size(); |
| 1603 | while (curTokenIndex > 0) { |
| 1604 | curTokenIndex--; |
| 1605 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1606 | int curWallpaperIndex = token.windows.size(); |
| 1607 | while (curWallpaperIndex > 0) { |
| 1608 | curWallpaperIndex--; |
| 1609 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1610 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1611 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1612 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | } |
| 1616 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1617 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1618 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1619 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1620 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1621 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1622 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1623 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1624 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1625 | changed = wallpaperWin.mXOffset != offset; |
| 1626 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1627 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1628 | + wallpaperWin + " x: " + offset); |
| 1629 | wallpaperWin.mXOffset = offset; |
| 1630 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1631 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1632 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1633 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1634 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1635 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1636 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1637 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1638 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1639 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1640 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1641 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1642 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1643 | + wallpaperWin + " y: " + offset); |
| 1644 | changed = true; |
| 1645 | wallpaperWin.mYOffset = offset; |
| 1646 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1647 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1648 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1649 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1650 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1651 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1652 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1653 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1654 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1655 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1656 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1657 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1658 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1659 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1660 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1661 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1662 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1663 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1664 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1665 | if (mWaitingOnWallpaper != null) { |
| 1666 | long start = SystemClock.uptimeMillis(); |
| 1667 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1668 | < start) { |
| 1669 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1670 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1671 | "Waiting for offset complete..."); |
| 1672 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1673 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1674 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1675 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1676 | if ((start+WALLPAPER_TIMEOUT) |
| 1677 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1678 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1679 | + wallpaperWin); |
| 1680 | mLastWallpaperTimeoutTime = start; |
| 1681 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1682 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1683 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1684 | } |
| 1685 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1686 | } catch (RemoteException e) { |
| 1687 | } |
| 1688 | } |
| 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 | return changed; |
| 1691 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1692 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1693 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1694 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1695 | if (mWaitingOnWallpaper != null && |
| 1696 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1697 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1698 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1702 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1703 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1704 | final int dw = mDisplay.getWidth(); |
| 1705 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1706 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1707 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1708 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1709 | WindowState target = mWallpaperTarget; |
| 1710 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1711 | if (target.mWallpaperX >= 0) { |
| 1712 | mLastWallpaperX = target.mWallpaperX; |
| 1713 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1714 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1715 | } |
| 1716 | if (target.mWallpaperY >= 0) { |
| 1717 | mLastWallpaperY = target.mWallpaperY; |
| 1718 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1719 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1720 | } |
| 1721 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1722 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1723 | int curTokenIndex = mWallpaperTokens.size(); |
| 1724 | while (curTokenIndex > 0) { |
| 1725 | curTokenIndex--; |
| 1726 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1727 | int curWallpaperIndex = token.windows.size(); |
| 1728 | while (curWallpaperIndex > 0) { |
| 1729 | curWallpaperIndex--; |
| 1730 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1731 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1732 | wallpaper.computeShownFrameLocked(); |
| 1733 | changed = true; |
| 1734 | // We only want to be synchronous with one wallpaper. |
| 1735 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1736 | } |
| 1737 | } |
| 1738 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1739 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1740 | return changed; |
| 1741 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1742 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1743 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1744 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1745 | final int dw = mDisplay.getWidth(); |
| 1746 | final int dh = mDisplay.getHeight(); |
| 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 | int curTokenIndex = mWallpaperTokens.size(); |
| 1749 | while (curTokenIndex > 0) { |
| 1750 | curTokenIndex--; |
| 1751 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1752 | if (token.hidden == visible) { |
| 1753 | token.hidden = !visible; |
| 1754 | // Need to do a layout to ensure the wallpaper now has the |
| 1755 | // correct size. |
| 1756 | mLayoutNeeded = true; |
| 1757 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1758 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1759 | int curWallpaperIndex = token.windows.size(); |
| 1760 | while (curWallpaperIndex > 0) { |
| 1761 | curWallpaperIndex--; |
| 1762 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1763 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1764 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1765 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1766 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1767 | if (wallpaper.mWallpaperVisible != visible) { |
| 1768 | wallpaper.mWallpaperVisible = visible; |
| 1769 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1770 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1771 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1772 | + ": " + visible); |
| 1773 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1774 | } catch (RemoteException e) { |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1781 | public int addWindow(Session session, IWindow client, |
| 1782 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1783 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | int res = mPolicy.checkAddPermission(attrs); |
| 1785 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1786 | return res; |
| 1787 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | boolean reportNewConfig = false; |
| 1790 | WindowState attachedWindow = null; |
| 1791 | WindowState win = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1792 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | synchronized(mWindowMap) { |
| 1794 | // Instantiating a Display requires talking with the simulator, |
| 1795 | // so don't do it until we know the system is mostly up and |
| 1796 | // running. |
| 1797 | if (mDisplay == null) { |
| 1798 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1799 | mDisplay = wm.getDefaultDisplay(); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 1800 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 1801 | mInitialDisplayHeight = mDisplay.getHeight(); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1802 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1803 | reportNewConfig = true; |
| 1804 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1805 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1806 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1807 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1809 | } |
| 1810 | |
| 1811 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1812 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1814 | 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] | 1815 | + attrs.token + ". Aborting."); |
| 1816 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1817 | } |
| 1818 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1819 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1820 | 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] | 1821 | + attrs.token + ". Aborting."); |
| 1822 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | boolean addToken = false; |
| 1827 | WindowToken token = mTokenMap.get(attrs.token); |
| 1828 | if (token == null) { |
| 1829 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1830 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1831 | 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] | 1832 | + attrs.token + ". Aborting."); |
| 1833 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1834 | } |
| 1835 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1836 | 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] | 1837 | + attrs.token + ". Aborting."); |
| 1838 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1839 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1840 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1841 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1842 | + attrs.token + ". Aborting."); |
| 1843 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1844 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1845 | token = new WindowToken(attrs.token, -1, false); |
| 1846 | addToken = true; |
| 1847 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1848 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1849 | AppWindowToken atoken = token.appWindowToken; |
| 1850 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1851 | 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] | 1852 | + token + ". Aborting."); |
| 1853 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1854 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1855 | 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] | 1856 | + token + ". Aborting."); |
| 1857 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1858 | } |
| 1859 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1860 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1861 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1862 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1863 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1864 | } |
| 1865 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1866 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1867 | 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] | 1868 | + attrs.token + ". Aborting."); |
| 1869 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1870 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1871 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1872 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1873 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1874 | + attrs.token + ". Aborting."); |
| 1875 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1876 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | win = new WindowState(session, client, token, |
| 1880 | attachedWindow, attrs, viewVisibility); |
| 1881 | if (win.mDeathRecipient == null) { |
| 1882 | // Client has apparently died, so there is no reason to |
| 1883 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1884 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | + " that is dead, aborting."); |
| 1886 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1887 | } |
| 1888 | |
| 1889 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1890 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1891 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1892 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1893 | return res; |
| 1894 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1895 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1896 | if (outInputChannel != null) { |
| 1897 | String name = win.makeInputChannelName(); |
| 1898 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 1899 | win.mInputChannel = inputChannels[0]; |
| 1900 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 1901 | |
| 1902 | mInputManager.registerInputChannel(win.mInputChannel); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1903 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1904 | |
| 1905 | // From now on, no exceptions or errors allowed! |
| 1906 | |
| 1907 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1911 | if (addToken) { |
| 1912 | mTokenMap.put(attrs.token, token); |
| 1913 | mTokenList.add(token); |
| 1914 | } |
| 1915 | win.attach(); |
| 1916 | mWindowMap.put(client.asBinder(), win); |
| 1917 | |
| 1918 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1919 | token.appWindowToken != null) { |
| 1920 | token.appWindowToken.startingWindow = win; |
| 1921 | } |
| 1922 | |
| 1923 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1924 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1925 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1926 | mInputMethodWindow = win; |
| 1927 | addInputMethodWindowToListLocked(win); |
| 1928 | imMayMove = false; |
| 1929 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1930 | mInputMethodDialogs.add(win); |
| 1931 | addWindowToListInOrderLocked(win, true); |
| 1932 | adjustInputMethodDialogsLocked(); |
| 1933 | imMayMove = false; |
| 1934 | } else { |
| 1935 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1936 | if (attrs.type == TYPE_WALLPAPER) { |
| 1937 | mLastWallpaperTimeoutTime = 0; |
| 1938 | adjustWallpaperWindowsLocked(); |
| 1939 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1940 | adjustWallpaperWindowsLocked(); |
| 1941 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1943 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1944 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1945 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1946 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | if (mInTouchMode) { |
| 1949 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1950 | } |
| 1951 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1952 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1953 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1954 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1955 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1956 | if (win.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1957 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 1958 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | imMayMove = false; |
| 1960 | } |
| 1961 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1962 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1964 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1966 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1967 | assignLayersLocked(); |
| 1968 | // Don't do layout here, the window must call |
| 1969 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1970 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | //dump(); |
| 1972 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1973 | if (focusChanged) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1974 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1975 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1976 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1977 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | TAG, "New client " + client.asBinder() |
| 1979 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1980 | |
| 1981 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 1982 | reportNewConfig = true; |
| 1983 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1987 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1988 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1989 | // block. |
| 1990 | final long origId = Binder.clearCallingIdentity(); |
| 1991 | if (reportNewConfig) { |
| 1992 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | } |
| 1994 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1995 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | return res; |
| 1997 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1998 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | public void removeWindow(Session session, IWindow client) { |
| 2000 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2001 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2002 | if (win == null) { |
| 2003 | return; |
| 2004 | } |
| 2005 | removeWindowLocked(session, win); |
| 2006 | } |
| 2007 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2008 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | public void removeWindowLocked(Session session, WindowState win) { |
| 2010 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2011 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | TAG, "Remove " + win + " client=" |
| 2013 | + Integer.toHexString(System.identityHashCode( |
| 2014 | win.mClient.asBinder())) |
| 2015 | + ", surface=" + win.mSurface); |
| 2016 | |
| 2017 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2018 | |
| 2019 | win.disposeInputChannel(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2020 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2021 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2023 | + " mExiting=" + win.mExiting |
| 2024 | + " isAnimating=" + win.isAnimating() |
| 2025 | + " app-animation=" |
| 2026 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2027 | + " inPendingTransaction=" |
| 2028 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2029 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2030 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2031 | boolean wasVisible = false; |
| 2032 | // First, see if we need to run an animation. If we do, we have |
| 2033 | // to hold off on removing the window until the animation is done. |
| 2034 | // If the display is frozen, just remove immediately, since the |
| 2035 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2036 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | // If we are not currently running the exit animation, we |
| 2038 | // need to see about starting one. |
| 2039 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2042 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2043 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2044 | } |
| 2045 | // Try starting an animation. |
| 2046 | if (applyAnimationLocked(win, transit, false)) { |
| 2047 | win.mExiting = true; |
| 2048 | } |
| 2049 | } |
| 2050 | if (win.mExiting || win.isAnimating()) { |
| 2051 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2052 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2053 | win.mExiting = true; |
| 2054 | win.mRemoveOnExit = true; |
| 2055 | mLayoutNeeded = true; |
| 2056 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2057 | performLayoutAndPlaceSurfacesLocked(); |
| 2058 | if (win.mAppToken != null) { |
| 2059 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2060 | } |
| 2061 | //dump(); |
| 2062 | Binder.restoreCallingIdentity(origId); |
| 2063 | return; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | removeWindowInnerLocked(session, win); |
| 2068 | // Removing a visible window will effect the computed orientation |
| 2069 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2070 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2071 | != mForcedAppOrientation |
| 2072 | && updateOrientationFromAppTokensLocked()) { |
| 2073 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | } |
| 2075 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2076 | Binder.restoreCallingIdentity(origId); |
| 2077 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2080 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | if (mInputMethodTarget == win) { |
| 2083 | moveInputMethodWindowsIfNeededLocked(false); |
| 2084 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2085 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2086 | if (false) { |
| 2087 | RuntimeException e = new RuntimeException("here"); |
| 2088 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2089 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2090 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2091 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2092 | mPolicy.removeWindowLw(win); |
| 2093 | win.removeLocked(); |
| 2094 | |
| 2095 | mWindowMap.remove(win.mClient.asBinder()); |
| 2096 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2097 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2098 | 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] | 2099 | |
| 2100 | if (mInputMethodWindow == win) { |
| 2101 | mInputMethodWindow = null; |
| 2102 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2103 | mInputMethodDialogs.remove(win); |
| 2104 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2105 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2106 | final WindowToken token = win.mToken; |
| 2107 | final AppWindowToken atoken = win.mAppToken; |
| 2108 | token.windows.remove(win); |
| 2109 | if (atoken != null) { |
| 2110 | atoken.allAppWindows.remove(win); |
| 2111 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2112 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | TAG, "**** Removing window " + win + ": count=" |
| 2114 | + token.windows.size()); |
| 2115 | if (token.windows.size() == 0) { |
| 2116 | if (!token.explicit) { |
| 2117 | mTokenMap.remove(token.token); |
| 2118 | mTokenList.remove(token); |
| 2119 | } else if (atoken != null) { |
| 2120 | atoken.firstWindowDrawn = false; |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | if (atoken != null) { |
| 2125 | if (atoken.startingWindow == win) { |
| 2126 | atoken.startingWindow = null; |
| 2127 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2128 | // If this is the last window and we had requested a starting |
| 2129 | // transition window, well there is no point now. |
| 2130 | atoken.startingData = null; |
| 2131 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2132 | // If this is the last window except for a starting transition |
| 2133 | // window, we need to get rid of the starting transition. |
| 2134 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2135 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | + ": no more real windows"); |
| 2137 | } |
| 2138 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2139 | mH.sendMessage(m); |
| 2140 | } |
| 2141 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2142 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2143 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2144 | mLastWallpaperTimeoutTime = 0; |
| 2145 | adjustWallpaperWindowsLocked(); |
| 2146 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2147 | adjustWallpaperWindowsLocked(); |
| 2148 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2149 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | if (!mInLayout) { |
| 2151 | assignLayersLocked(); |
| 2152 | mLayoutNeeded = true; |
| 2153 | performLayoutAndPlaceSurfacesLocked(); |
| 2154 | if (win.mAppToken != null) { |
| 2155 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2156 | } |
| 2157 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2158 | |
| 2159 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2160 | } |
| 2161 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2162 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2163 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2164 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2165 | if (where != null) { |
| 2166 | Slog.i(TAG, str, where); |
| 2167 | } else { |
| 2168 | Slog.i(TAG, str); |
| 2169 | } |
| 2170 | } |
| 2171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2172 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2173 | long origId = Binder.clearCallingIdentity(); |
| 2174 | try { |
| 2175 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2176 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2178 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2179 | Surface.openTransaction(); |
| 2180 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2181 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2182 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | w.mSurface.setTransparentRegionHint(region); |
| 2184 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2185 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2186 | Surface.closeTransaction(); |
| 2187 | } |
| 2188 | } |
| 2189 | } |
| 2190 | } finally { |
| 2191 | Binder.restoreCallingIdentity(origId); |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2196 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2197 | Rect visibleInsets) { |
| 2198 | long origId = Binder.clearCallingIdentity(); |
| 2199 | try { |
| 2200 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2201 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2202 | if (w != null) { |
| 2203 | w.mGivenInsetsPending = false; |
| 2204 | w.mGivenContentInsets.set(contentInsets); |
| 2205 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2206 | w.mTouchableInsets = touchableInsets; |
| 2207 | mLayoutNeeded = true; |
| 2208 | performLayoutAndPlaceSurfacesLocked(); |
| 2209 | } |
| 2210 | } |
| 2211 | } finally { |
| 2212 | Binder.restoreCallingIdentity(origId); |
| 2213 | } |
| 2214 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2215 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2217 | Rect outDisplayFrame) { |
| 2218 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2219 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | if (win == null) { |
| 2221 | outDisplayFrame.setEmpty(); |
| 2222 | return; |
| 2223 | } |
| 2224 | outDisplayFrame.set(win.mDisplayFrame); |
| 2225 | } |
| 2226 | } |
| 2227 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2228 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2229 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2230 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2231 | window.mWallpaperX = x; |
| 2232 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2233 | window.mWallpaperXStep = xStep; |
| 2234 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2235 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2236 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2237 | } |
| 2238 | } |
| 2239 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2240 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2241 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2242 | synchronized (mWindowMap) { |
| 2243 | if (mWaitingOnWallpaper != null && |
| 2244 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2245 | mWaitingOnWallpaper = null; |
| 2246 | mWindowMap.notifyAll(); |
| 2247 | } |
| 2248 | } |
| 2249 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2250 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2251 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2252 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2253 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2254 | || window == mUpperWallpaperTarget) { |
| 2255 | boolean doWait = sync; |
| 2256 | int curTokenIndex = mWallpaperTokens.size(); |
| 2257 | while (curTokenIndex > 0) { |
| 2258 | curTokenIndex--; |
| 2259 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2260 | int curWallpaperIndex = token.windows.size(); |
| 2261 | while (curWallpaperIndex > 0) { |
| 2262 | curWallpaperIndex--; |
| 2263 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2264 | try { |
| 2265 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2266 | x, y, z, extras, sync); |
| 2267 | // We only want to be synchronous with one wallpaper. |
| 2268 | sync = false; |
| 2269 | } catch (RemoteException e) { |
| 2270 | } |
| 2271 | } |
| 2272 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2273 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2274 | if (doWait) { |
| 2275 | // XXX Need to wait for result. |
| 2276 | } |
| 2277 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2278 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2279 | return null; |
| 2280 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | public int relayoutWindow(Session session, IWindow client, |
| 2283 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2284 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2285 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2286 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2287 | boolean displayed = false; |
| 2288 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2289 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2292 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2293 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | if (win == null) { |
| 2295 | return 0; |
| 2296 | } |
| 2297 | win.mRequestedWidth = requestedWidth; |
| 2298 | win.mRequestedHeight = requestedHeight; |
| 2299 | |
| 2300 | if (attrs != null) { |
| 2301 | mPolicy.adjustWindowParamsLw(attrs); |
| 2302 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2304 | int attrChanges = 0; |
| 2305 | int flagChanges = 0; |
| 2306 | if (attrs != null) { |
| 2307 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2308 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2309 | } |
| 2310 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2311 | 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] | 2312 | |
| 2313 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2314 | win.mAlpha = attrs.alpha; |
| 2315 | } |
| 2316 | |
| 2317 | final boolean scaledWindow = |
| 2318 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2319 | |
| 2320 | if (scaledWindow) { |
| 2321 | // requested{Width|Height} Surface's physical size |
| 2322 | // attrs.{width|height} Size on screen |
| 2323 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2324 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2325 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2326 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2327 | } else { |
| 2328 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | boolean imMayMove = (flagChanges&( |
| 2332 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2333 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2334 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2336 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2337 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2338 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2339 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2340 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | win.mRelayoutCalled = true; |
| 2343 | final int oldVisibility = win.mViewVisibility; |
| 2344 | win.mViewVisibility = viewVisibility; |
| 2345 | if (viewVisibility == View.VISIBLE && |
| 2346 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2347 | displayed = !win.isVisibleLw(); |
| 2348 | if (win.mExiting) { |
| 2349 | win.mExiting = false; |
| 2350 | win.mAnimation = null; |
| 2351 | } |
| 2352 | if (win.mDestroying) { |
| 2353 | win.mDestroying = false; |
| 2354 | mDestroySurface.remove(win); |
| 2355 | } |
| 2356 | if (oldVisibility == View.GONE) { |
| 2357 | win.mEnterAnimationPending = true; |
| 2358 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2359 | if (displayed) { |
| 2360 | if (win.mSurface != null && !win.mDrawPending |
| 2361 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2362 | && mPolicy.isScreenOn()) { |
| 2363 | applyEnterAnimationLocked(win); |
| 2364 | } |
| 2365 | if ((win.mAttrs.flags |
| 2366 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2367 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2368 | "Relayout window turning screen on: " + win); |
| 2369 | win.mTurnOnScreen = true; |
| 2370 | } |
| 2371 | int diff = 0; |
| 2372 | if (win.mConfiguration != mCurConfiguration |
| 2373 | && (win.mConfiguration == null |
| 2374 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2375 | win.mConfiguration = mCurConfiguration; |
| 2376 | if (DEBUG_CONFIGURATION) { |
| 2377 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2378 | + win.mConfiguration + " / 0x" |
| 2379 | + Integer.toHexString(diff)); |
| 2380 | } |
| 2381 | outConfig.setTo(mCurConfiguration); |
| 2382 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2383 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2384 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2385 | // To change the format, we need to re-build the surface. |
| 2386 | win.destroySurfaceLocked(); |
| 2387 | displayed = true; |
| 2388 | } |
| 2389 | try { |
| 2390 | Surface surface = win.createSurfaceLocked(); |
| 2391 | if (surface != null) { |
| 2392 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2393 | win.mReportDestroySurface = false; |
| 2394 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2395 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2396 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2398 | // For some reason there isn't a surface. Clear the |
| 2399 | // caller's object so they see the same state. |
| 2400 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2401 | } |
| 2402 | } catch (Exception e) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2403 | mInputMonitor.updateInputWindowsLw(); |
| 2404 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2405 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2406 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2407 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | Binder.restoreCallingIdentity(origId); |
| 2409 | return 0; |
| 2410 | } |
| 2411 | if (displayed) { |
| 2412 | focusMayChange = true; |
| 2413 | } |
| 2414 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2415 | && mInputMethodWindow == null) { |
| 2416 | mInputMethodWindow = win; |
| 2417 | imMayMove = true; |
| 2418 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2419 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2420 | && win.mAppToken != null |
| 2421 | && win.mAppToken.startingWindow != null) { |
| 2422 | // Special handling of starting window over the base |
| 2423 | // window of the app: propagate lock screen flags to it, |
| 2424 | // to provide the correct semantics while starting. |
| 2425 | final int mask = |
| 2426 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2427 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2428 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2429 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2430 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2431 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | } else { |
| 2433 | win.mEnterAnimationPending = false; |
| 2434 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2435 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2436 | + ": mExiting=" + win.mExiting |
| 2437 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | // If we are not currently running the exit animation, we |
| 2439 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2440 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2441 | // Try starting an animation; if there isn't one, we |
| 2442 | // can destroy the surface right away. |
| 2443 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2444 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2445 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2446 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2447 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2449 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | win.mExiting = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | } else if (win.isAnimating()) { |
| 2452 | // Currently in a hide animation... turn this into |
| 2453 | // an exit. |
| 2454 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2455 | } else if (win == mWallpaperTarget) { |
| 2456 | // If the wallpaper is currently behind this |
| 2457 | // window, we need to change both of them inside |
| 2458 | // of a transaction to avoid artifacts. |
| 2459 | win.mExiting = true; |
| 2460 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | } else { |
| 2462 | if (mInputMethodWindow == win) { |
| 2463 | mInputMethodWindow = null; |
| 2464 | } |
| 2465 | win.destroySurfaceLocked(); |
| 2466 | } |
| 2467 | } |
| 2468 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2469 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2470 | if (win.mSurface == null || (win.getAttrs().flags |
| 2471 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2472 | || win.mSurfacePendingDestroy) { |
| 2473 | // We are being called from a local process, which |
| 2474 | // means outSurface holds its current surface. Ensure the |
| 2475 | // surface object is cleared, but we don't want it actually |
| 2476 | // destroyed at this point. |
| 2477 | win.mSurfacePendingDestroy = false; |
| 2478 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2479 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2480 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2481 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2482 | "Keeping surface, will report destroy: " + win); |
| 2483 | win.mReportDestroySurface = true; |
| 2484 | outSurface.copyFrom(win.mSurface); |
| 2485 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | } |
| 2487 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2488 | if (focusMayChange) { |
| 2489 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2490 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2491 | imMayMove = false; |
| 2492 | } |
| 2493 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2494 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2495 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2496 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2497 | // reassign them at this point if the IM window state gets shuffled |
| 2498 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2499 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2501 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2502 | // Little hack here -- we -should- be able to rely on the |
| 2503 | // function to return true if the IME has moved and needs |
| 2504 | // its layer recomputed. However, if the IME was hidden |
| 2505 | // and isn't actually moved in the list, its layer may be |
| 2506 | // 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] | 2507 | assignLayers = true; |
| 2508 | } |
| 2509 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2510 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2511 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2512 | assignLayers = true; |
| 2513 | } |
| 2514 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | mLayoutNeeded = true; |
| 2517 | win.mGivenInsetsPending = insetsPending; |
| 2518 | if (assignLayers) { |
| 2519 | assignLayersLocked(); |
| 2520 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2521 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2523 | if (displayed && win.mIsWallpaper) { |
| 2524 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2525 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2526 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | if (win.mAppToken != null) { |
| 2528 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2529 | } |
| 2530 | outFrame.set(win.mFrame); |
| 2531 | outContentInsets.set(win.mContentInsets); |
| 2532 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2533 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2535 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | + ", requestedHeight=" + requestedHeight |
| 2537 | + ", viewVisibility=" + viewVisibility |
| 2538 | + "\nRelayout returning frame=" + outFrame |
| 2539 | + ", surface=" + outSurface); |
| 2540 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2541 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2543 | |
| 2544 | inTouchMode = mInTouchMode; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2545 | |
| 2546 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | } |
| 2548 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2549 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | sendNewConfiguration(); |
| 2551 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2552 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2553 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2556 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2557 | } |
| 2558 | |
| 2559 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2560 | final long origId = Binder.clearCallingIdentity(); |
| 2561 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2562 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2563 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2564 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2565 | adjustWallpaperWindowsLocked(); |
| 2566 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | mLayoutNeeded = true; |
| 2568 | performLayoutAndPlaceSurfacesLocked(); |
| 2569 | } |
| 2570 | } |
| 2571 | Binder.restoreCallingIdentity(origId); |
| 2572 | } |
| 2573 | |
| 2574 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2575 | 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] | 2576 | + (lp != null ? lp.packageName : null) |
| 2577 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2578 | if (lp != null && lp.windowAnimations != 0) { |
| 2579 | // If this is a system resource, don't try to load it from the |
| 2580 | // application resources. It is nice to avoid loading application |
| 2581 | // resources if we can. |
| 2582 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2583 | int resId = lp.windowAnimations; |
| 2584 | if ((resId&0xFF000000) == 0x01000000) { |
| 2585 | packageName = "android"; |
| 2586 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2587 | 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] | 2588 | + packageName); |
| 2589 | return AttributeCache.instance().get(packageName, resId, |
| 2590 | com.android.internal.R.styleable.WindowAnimation); |
| 2591 | } |
| 2592 | return null; |
| 2593 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2594 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2595 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2596 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2597 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2598 | if (packageName != null) { |
| 2599 | if ((resId&0xFF000000) == 0x01000000) { |
| 2600 | packageName = "android"; |
| 2601 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2602 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2603 | + packageName); |
| 2604 | return AttributeCache.instance().get(packageName, resId, |
| 2605 | com.android.internal.R.styleable.WindowAnimation); |
| 2606 | } |
| 2607 | return null; |
| 2608 | } |
| 2609 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | private void applyEnterAnimationLocked(WindowState win) { |
| 2611 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2612 | if (win.mEnterAnimationPending) { |
| 2613 | win.mEnterAnimationPending = false; |
| 2614 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2615 | } |
| 2616 | |
| 2617 | applyAnimationLocked(win, transit, true); |
| 2618 | } |
| 2619 | |
| 2620 | private boolean applyAnimationLocked(WindowState win, |
| 2621 | int transit, boolean isEntrance) { |
| 2622 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2623 | // If we are trying to apply an animation, but already running |
| 2624 | // an animation of the same type, then just leave that one alone. |
| 2625 | return true; |
| 2626 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2627 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2628 | // Only apply an animation if the display isn't frozen. If it is |
| 2629 | // frozen, there is no reason to animate and it can cause strange |
| 2630 | // artifacts when we unfreeze the display if some different animation |
| 2631 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2632 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2633 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2634 | int attr = -1; |
| 2635 | Animation a = null; |
| 2636 | if (anim != 0) { |
| 2637 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2638 | } else { |
| 2639 | switch (transit) { |
| 2640 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2641 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2642 | break; |
| 2643 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2644 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2645 | break; |
| 2646 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2647 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2648 | break; |
| 2649 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2650 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2651 | break; |
| 2652 | } |
| 2653 | if (attr >= 0) { |
| 2654 | a = loadAnimation(win.mAttrs, attr); |
| 2655 | } |
| 2656 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2657 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2659 | + " mAnimation=" + win.mAnimation |
| 2660 | + " isEntrance=" + isEntrance); |
| 2661 | if (a != null) { |
| 2662 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2663 | RuntimeException e = null; |
| 2664 | if (!HIDE_STACK_CRAWLS) { |
| 2665 | e = new RuntimeException(); |
| 2666 | e.fillInStackTrace(); |
| 2667 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2668 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2669 | } |
| 2670 | win.setAnimation(a); |
| 2671 | win.mAnimationIsEntrance = isEntrance; |
| 2672 | } |
| 2673 | } else { |
| 2674 | win.clearAnimation(); |
| 2675 | } |
| 2676 | |
| 2677 | return win.mAnimation != null; |
| 2678 | } |
| 2679 | |
| 2680 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2681 | int anim = 0; |
| 2682 | Context context = mContext; |
| 2683 | if (animAttr >= 0) { |
| 2684 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2685 | if (ent != null) { |
| 2686 | context = ent.context; |
| 2687 | anim = ent.array.getResourceId(animAttr, 0); |
| 2688 | } |
| 2689 | } |
| 2690 | if (anim != 0) { |
| 2691 | return AnimationUtils.loadAnimation(context, anim); |
| 2692 | } |
| 2693 | return null; |
| 2694 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2695 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2696 | private Animation loadAnimation(String packageName, int resId) { |
| 2697 | int anim = 0; |
| 2698 | Context context = mContext; |
| 2699 | if (resId >= 0) { |
| 2700 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2701 | if (ent != null) { |
| 2702 | context = ent.context; |
| 2703 | anim = resId; |
| 2704 | } |
| 2705 | } |
| 2706 | if (anim != 0) { |
| 2707 | return AnimationUtils.loadAnimation(context, anim); |
| 2708 | } |
| 2709 | return null; |
| 2710 | } |
| 2711 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2712 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2713 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2714 | // Only apply an animation if the display isn't frozen. If it is |
| 2715 | // frozen, there is no reason to animate and it can cause strange |
| 2716 | // artifacts when we unfreeze the display if some different animation |
| 2717 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2718 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2719 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2720 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2721 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2722 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2723 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2724 | } else if (mNextAppTransitionPackage != null) { |
| 2725 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2726 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2727 | } else { |
| 2728 | int animAttr = 0; |
| 2729 | switch (transit) { |
| 2730 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2731 | animAttr = enter |
| 2732 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2733 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2734 | break; |
| 2735 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2736 | animAttr = enter |
| 2737 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2738 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2739 | break; |
| 2740 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2741 | animAttr = enter |
| 2742 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2743 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2744 | break; |
| 2745 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2746 | animAttr = enter |
| 2747 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2748 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2749 | break; |
| 2750 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2751 | animAttr = enter |
| 2752 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2753 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2754 | break; |
| 2755 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2756 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2757 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2758 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2759 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2760 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2761 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2762 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2763 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2764 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2765 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2766 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2767 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2768 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2769 | break; |
| 2770 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2771 | animAttr = enter |
| 2772 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2773 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2774 | break; |
| 2775 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2776 | animAttr = enter |
| 2777 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2778 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2779 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2780 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2781 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2782 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2783 | + " anim=" + a |
| 2784 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2785 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2787 | if (a != null) { |
| 2788 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2789 | RuntimeException e = null; |
| 2790 | if (!HIDE_STACK_CRAWLS) { |
| 2791 | e = new RuntimeException(); |
| 2792 | e.fillInStackTrace(); |
| 2793 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2794 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | } |
| 2796 | wtoken.setAnimation(a); |
| 2797 | } |
| 2798 | } else { |
| 2799 | wtoken.clearAnimation(); |
| 2800 | } |
| 2801 | |
| 2802 | return wtoken.animation != null; |
| 2803 | } |
| 2804 | |
| 2805 | // ------------------------------------------------------------- |
| 2806 | // Application Window Tokens |
| 2807 | // ------------------------------------------------------------- |
| 2808 | |
| 2809 | public void validateAppTokens(List tokens) { |
| 2810 | int v = tokens.size()-1; |
| 2811 | int m = mAppTokens.size()-1; |
| 2812 | while (v >= 0 && m >= 0) { |
| 2813 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2814 | if (wtoken.removed) { |
| 2815 | m--; |
| 2816 | continue; |
| 2817 | } |
| 2818 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2819 | 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] | 2820 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2821 | } |
| 2822 | v--; |
| 2823 | m--; |
| 2824 | } |
| 2825 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2826 | 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] | 2827 | v--; |
| 2828 | } |
| 2829 | while (m >= 0) { |
| 2830 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2831 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2832 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | } |
| 2834 | m--; |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | boolean checkCallingPermission(String permission, String func) { |
| 2839 | // Quick check: if the calling permission is me, it's all okay. |
| 2840 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2841 | return true; |
| 2842 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2843 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2844 | if (mContext.checkCallingPermission(permission) |
| 2845 | == PackageManager.PERMISSION_GRANTED) { |
| 2846 | return true; |
| 2847 | } |
| 2848 | String msg = "Permission Denial: " + func + " from pid=" |
| 2849 | + Binder.getCallingPid() |
| 2850 | + ", uid=" + Binder.getCallingUid() |
| 2851 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2852 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | return false; |
| 2854 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2856 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2857 | WindowToken wtoken = mTokenMap.get(token); |
| 2858 | if (wtoken == null) { |
| 2859 | return null; |
| 2860 | } |
| 2861 | return wtoken.appWindowToken; |
| 2862 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | public void addWindowToken(IBinder token, int type) { |
| 2865 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2866 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2867 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2868 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2869 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | synchronized(mWindowMap) { |
| 2871 | WindowToken wtoken = mTokenMap.get(token); |
| 2872 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2873 | 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] | 2874 | return; |
| 2875 | } |
| 2876 | wtoken = new WindowToken(token, type, true); |
| 2877 | mTokenMap.put(token, wtoken); |
| 2878 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2879 | if (type == TYPE_WALLPAPER) { |
| 2880 | mWallpaperTokens.add(wtoken); |
| 2881 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2882 | } |
| 2883 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2885 | public void removeWindowToken(IBinder token) { |
| 2886 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2887 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2888 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | final long origId = Binder.clearCallingIdentity(); |
| 2892 | synchronized(mWindowMap) { |
| 2893 | WindowToken wtoken = mTokenMap.remove(token); |
| 2894 | mTokenList.remove(wtoken); |
| 2895 | if (wtoken != null) { |
| 2896 | boolean delayed = false; |
| 2897 | if (!wtoken.hidden) { |
| 2898 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | final int N = wtoken.windows.size(); |
| 2901 | boolean changed = false; |
| 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 | for (int i=0; i<N; i++) { |
| 2904 | WindowState win = wtoken.windows.get(i); |
| 2905 | |
| 2906 | if (win.isAnimating()) { |
| 2907 | delayed = true; |
| 2908 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2909 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | if (win.isVisibleNow()) { |
| 2911 | applyAnimationLocked(win, |
| 2912 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | changed = true; |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | if (changed) { |
| 2918 | mLayoutNeeded = true; |
| 2919 | performLayoutAndPlaceSurfacesLocked(); |
| 2920 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2921 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2923 | if (delayed) { |
| 2924 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2925 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2926 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | } |
| 2928 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2929 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2930 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2932 | 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] | 2933 | } |
| 2934 | } |
| 2935 | Binder.restoreCallingIdentity(origId); |
| 2936 | } |
| 2937 | |
| 2938 | public void addAppToken(int addPos, IApplicationToken token, |
| 2939 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2940 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2941 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2942 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2944 | |
| 2945 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 2946 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 2947 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 2948 | // here we would run the chance of introducing a deadlock between the window manager |
| 2949 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 2950 | // (which holds locks while querying the application token). |
| 2951 | long inputDispatchingTimeoutNanos; |
| 2952 | try { |
| 2953 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 2954 | } catch (RemoteException ex) { |
| 2955 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 2956 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 2957 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2958 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2959 | synchronized(mWindowMap) { |
| 2960 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2961 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2962 | 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] | 2963 | return; |
| 2964 | } |
| 2965 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2966 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | wtoken.groupId = groupId; |
| 2968 | wtoken.appFullscreen = fullscreen; |
| 2969 | wtoken.requestedOrientation = requestedOrientation; |
| 2970 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2971 | 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] | 2972 | mTokenMap.put(token.asBinder(), wtoken); |
| 2973 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | // Application tokens start out hidden. |
| 2976 | wtoken.hidden = true; |
| 2977 | wtoken.hiddenRequested = true; |
| 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 | //dump(); |
| 2980 | } |
| 2981 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | public void setAppGroupId(IBinder token, int groupId) { |
| 2984 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2985 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2986 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | synchronized(mWindowMap) { |
| 2990 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2991 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2992 | 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] | 2993 | return; |
| 2994 | } |
| 2995 | wtoken.groupId = groupId; |
| 2996 | } |
| 2997 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2998 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2999 | public int getOrientationFromWindowsLocked() { |
| 3000 | int pos = mWindows.size() - 1; |
| 3001 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3002 | WindowState wtoken = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3003 | pos--; |
| 3004 | if (wtoken.mAppToken != null) { |
| 3005 | // We hit an application window. so the orientation will be determined by the |
| 3006 | // app window. No point in continuing further. |
| 3007 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3008 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3009 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | continue; |
| 3011 | } |
| 3012 | int req = wtoken.mAttrs.screenOrientation; |
| 3013 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3014 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3015 | continue; |
| 3016 | } else { |
| 3017 | return req; |
| 3018 | } |
| 3019 | } |
| 3020 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3021 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3022 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3024 | int pos = mAppTokens.size() - 1; |
| 3025 | int curGroup = 0; |
| 3026 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3027 | boolean findingBehind = false; |
| 3028 | boolean haveGroup = false; |
| 3029 | boolean lastFullscreen = false; |
| 3030 | while (pos >= 0) { |
| 3031 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3032 | pos--; |
| 3033 | // if we're about to tear down this window and not seek for |
| 3034 | // the behind activity, don't use it for orientation |
| 3035 | if (!findingBehind |
| 3036 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3037 | continue; |
| 3038 | } |
| 3039 | |
| 3040 | if (!haveGroup) { |
| 3041 | // We ignore any hidden applications on the top. |
| 3042 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3043 | continue; |
| 3044 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3045 | haveGroup = true; |
| 3046 | curGroup = wtoken.groupId; |
| 3047 | lastOrientation = wtoken.requestedOrientation; |
| 3048 | } else if (curGroup != wtoken.groupId) { |
| 3049 | // If we have hit a new application group, and the bottom |
| 3050 | // of the previous group didn't explicitly say to use |
| 3051 | // the orientation behind it, and the last app was |
| 3052 | // full screen, then we'll stick with the |
| 3053 | // user's orientation. |
| 3054 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3055 | && lastFullscreen) { |
| 3056 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3058 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3059 | int or = wtoken.requestedOrientation; |
| 3060 | // If this application is fullscreen, and didn't explicitly say |
| 3061 | // to use the orientation behind it, then just take whatever |
| 3062 | // orientation it has and ignores whatever is under it. |
| 3063 | lastFullscreen = wtoken.appFullscreen; |
| 3064 | if (lastFullscreen |
| 3065 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3066 | return or; |
| 3067 | } |
| 3068 | // If this application has requested an explicit orientation, |
| 3069 | // then use it. |
| 3070 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3071 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3072 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3073 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3074 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3075 | return or; |
| 3076 | } |
| 3077 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3078 | } |
| 3079 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3080 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3083 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3084 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3085 | "updateOrientationFromAppTokens()")) { |
| 3086 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3087 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3088 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3089 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3090 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3091 | |
| 3092 | synchronized(mWindowMap) { |
| 3093 | if (updateOrientationFromAppTokensLocked()) { |
| 3094 | if (freezeThisOneIfNeeded != null) { |
| 3095 | AppWindowToken wtoken = findAppWindowToken( |
| 3096 | freezeThisOneIfNeeded); |
| 3097 | if (wtoken != null) { |
| 3098 | startAppFreezingScreenLocked(wtoken, |
| 3099 | ActivityInfo.CONFIG_ORIENTATION); |
| 3100 | } |
| 3101 | } |
| 3102 | config = computeNewConfigurationLocked(); |
| 3103 | |
| 3104 | } else if (currentConfig != null) { |
| 3105 | // No obvious action we need to take, but if our current |
| 3106 | // state mismatches the activity maanager's, update it |
| 3107 | mTempConfiguration.setToDefaults(); |
| 3108 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3109 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3110 | mWaitingForConfig = true; |
| 3111 | mLayoutNeeded = true; |
| 3112 | startFreezingDisplayLocked(); |
| 3113 | config = new Configuration(mTempConfiguration); |
| 3114 | } |
| 3115 | } |
| 3116 | } |
| 3117 | } |
| 3118 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3119 | Binder.restoreCallingIdentity(ident); |
| 3120 | return config; |
| 3121 | } |
| 3122 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3123 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3124 | * Determine the new desired orientation of the display, returning |
| 3125 | * a non-null new Configuration if it has changed from the current |
| 3126 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3127 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3128 | * SCREEN. This will typically be done for you if you call |
| 3129 | * sendNewConfiguration(). |
| 3130 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | * The orientation is computed from non-application windows first. If none of |
| 3132 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3133 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3134 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3135 | * android.os.IBinder) |
| 3136 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3137 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3138 | if (mDisplayFrozen) { |
| 3139 | // If the display is frozen, some activities may be in the middle |
| 3140 | // of restarting, and thus have removed their old window. If the |
| 3141 | // window has the flag to hide the lock screen, then the lock screen |
| 3142 | // can re-appear and inflict its own orientation on us. Keep the |
| 3143 | // orientation stable until this all settles down. |
| 3144 | return false; |
| 3145 | } |
| 3146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | long ident = Binder.clearCallingIdentity(); |
| 3149 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3150 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3151 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3153 | mForcedAppOrientation = req; |
| 3154 | //send a message to Policy indicating orientation change to take |
| 3155 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3156 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3157 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3158 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3159 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | } |
| 3161 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3162 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3163 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | } finally { |
| 3165 | Binder.restoreCallingIdentity(ident); |
| 3166 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3168 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3169 | int computeForcedAppOrientationLocked() { |
| 3170 | int req = getOrientationFromWindowsLocked(); |
| 3171 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3172 | req = getOrientationFromAppTokensLocked(); |
| 3173 | } |
| 3174 | return req; |
| 3175 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3176 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3177 | public void setNewConfiguration(Configuration config) { |
| 3178 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3179 | "setNewConfiguration()")) { |
| 3180 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3181 | } |
| 3182 | |
| 3183 | synchronized(mWindowMap) { |
| 3184 | mCurConfiguration = new Configuration(config); |
| 3185 | mWaitingForConfig = false; |
| 3186 | performLayoutAndPlaceSurfacesLocked(); |
| 3187 | } |
| 3188 | } |
| 3189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3191 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3192 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3193 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | synchronized(mWindowMap) { |
| 3197 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3198 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3199 | 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] | 3200 | return; |
| 3201 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3202 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3203 | wtoken.requestedOrientation = requestedOrientation; |
| 3204 | } |
| 3205 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | public int getAppOrientation(IApplicationToken token) { |
| 3208 | synchronized(mWindowMap) { |
| 3209 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3210 | if (wtoken == null) { |
| 3211 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3212 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3213 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | return wtoken.requestedOrientation; |
| 3215 | } |
| 3216 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3219 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3220 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3221 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | synchronized(mWindowMap) { |
| 3225 | boolean changed = false; |
| 3226 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3227 | 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] | 3228 | changed = mFocusedApp != null; |
| 3229 | mFocusedApp = null; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3230 | if (changed) { |
| 3231 | mInputMonitor.setFocusedAppLw(null); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3232 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | } else { |
| 3234 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3235 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3236 | 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] | 3237 | return; |
| 3238 | } |
| 3239 | changed = mFocusedApp != newFocus; |
| 3240 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3241 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3242 | if (changed) { |
| 3243 | mInputMonitor.setFocusedAppLw(newFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3244 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | if (moveFocusNow && changed) { |
| 3248 | final long origId = Binder.clearCallingIdentity(); |
| 3249 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3250 | Binder.restoreCallingIdentity(origId); |
| 3251 | } |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | public void prepareAppTransition(int transit) { |
| 3256 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3257 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3258 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3260 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3262 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | TAG, "Prepare app transition: transit=" + transit |
| 3264 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3265 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3266 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3267 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3269 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3270 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3271 | // Opening a new task always supersedes a close for the anim. |
| 3272 | mNextAppTransition = transit; |
| 3273 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3274 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3275 | // Opening a new activity always supersedes a close for the anim. |
| 3276 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | } |
| 3278 | mAppTransitionReady = false; |
| 3279 | mAppTransitionTimeout = false; |
| 3280 | mStartingIconInTransition = false; |
| 3281 | mSkipAppTransitionAnimation = false; |
| 3282 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3283 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3284 | 5000); |
| 3285 | } |
| 3286 | } |
| 3287 | } |
| 3288 | |
| 3289 | public int getPendingAppTransition() { |
| 3290 | return mNextAppTransition; |
| 3291 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3292 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3293 | public void overridePendingAppTransition(String packageName, |
| 3294 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3295 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3296 | mNextAppTransitionPackage = packageName; |
| 3297 | mNextAppTransitionEnter = enterAnim; |
| 3298 | mNextAppTransitionExit = exitAnim; |
| 3299 | } |
| 3300 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3302 | public void executeAppTransition() { |
| 3303 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3304 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3305 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3309 | if (DEBUG_APP_TRANSITIONS) { |
| 3310 | RuntimeException e = new RuntimeException("here"); |
| 3311 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3312 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3313 | + mNextAppTransition, e); |
| 3314 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3315 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | mAppTransitionReady = true; |
| 3317 | final long origId = Binder.clearCallingIdentity(); |
| 3318 | performLayoutAndPlaceSurfacesLocked(); |
| 3319 | Binder.restoreCallingIdentity(origId); |
| 3320 | } |
| 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3325 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3326 | IBinder transferFrom, boolean createIfNeeded) { |
| 3327 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3328 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3329 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3333 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3334 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3335 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3336 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3338 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3339 | 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] | 3340 | return; |
| 3341 | } |
| 3342 | |
| 3343 | // If the display is frozen, we won't do anything until the |
| 3344 | // actual window is displayed so there is no reason to put in |
| 3345 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3346 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | return; |
| 3348 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3350 | if (wtoken.startingData != null) { |
| 3351 | return; |
| 3352 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3353 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | if (transferFrom != null) { |
| 3355 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3356 | if (ttoken != null) { |
| 3357 | WindowState startingWindow = ttoken.startingWindow; |
| 3358 | if (startingWindow != null) { |
| 3359 | if (mStartingIconInTransition) { |
| 3360 | // In this case, the starting icon has already |
| 3361 | // been displayed, so start letting windows get |
| 3362 | // shown immediately without any more transitions. |
| 3363 | mSkipAppTransitionAnimation = true; |
| 3364 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3365 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3366 | "Moving existing starting from " + ttoken |
| 3367 | + " to " + wtoken); |
| 3368 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3369 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | // Transfer the starting window over to the new |
| 3371 | // token. |
| 3372 | wtoken.startingData = ttoken.startingData; |
| 3373 | wtoken.startingView = ttoken.startingView; |
| 3374 | wtoken.startingWindow = startingWindow; |
| 3375 | ttoken.startingData = null; |
| 3376 | ttoken.startingView = null; |
| 3377 | ttoken.startingWindow = null; |
| 3378 | ttoken.startingMoved = true; |
| 3379 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3380 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3382 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3383 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3384 | mWindows.remove(startingWindow); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3385 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | ttoken.windows.remove(startingWindow); |
| 3387 | ttoken.allAppWindows.remove(startingWindow); |
| 3388 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | // Propagate other interesting state between the |
| 3391 | // tokens. If the old token is displayed, we should |
| 3392 | // immediately force the new one to be displayed. If |
| 3393 | // it is animating, we need to move that animation to |
| 3394 | // the new one. |
| 3395 | if (ttoken.allDrawn) { |
| 3396 | wtoken.allDrawn = true; |
| 3397 | } |
| 3398 | if (ttoken.firstWindowDrawn) { |
| 3399 | wtoken.firstWindowDrawn = true; |
| 3400 | } |
| 3401 | if (!ttoken.hidden) { |
| 3402 | wtoken.hidden = false; |
| 3403 | wtoken.hiddenRequested = false; |
| 3404 | wtoken.willBeHidden = false; |
| 3405 | } |
| 3406 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3407 | wtoken.clientHidden = ttoken.clientHidden; |
| 3408 | wtoken.sendAppVisibilityToClients(); |
| 3409 | } |
| 3410 | if (ttoken.animation != null) { |
| 3411 | wtoken.animation = ttoken.animation; |
| 3412 | wtoken.animating = ttoken.animating; |
| 3413 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3414 | ttoken.animation = null; |
| 3415 | ttoken.animLayerAdjustment = 0; |
| 3416 | wtoken.updateLayers(); |
| 3417 | ttoken.updateLayers(); |
| 3418 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3420 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3421 | mLayoutNeeded = true; |
| 3422 | performLayoutAndPlaceSurfacesLocked(); |
| 3423 | Binder.restoreCallingIdentity(origId); |
| 3424 | return; |
| 3425 | } else if (ttoken.startingData != null) { |
| 3426 | // The previous app was getting ready to show a |
| 3427 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3428 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | "Moving pending starting from " + ttoken |
| 3430 | + " to " + wtoken); |
| 3431 | wtoken.startingData = ttoken.startingData; |
| 3432 | ttoken.startingData = null; |
| 3433 | ttoken.startingMoved = true; |
| 3434 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3435 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3436 | // want to process the message ASAP, before any other queued |
| 3437 | // messages. |
| 3438 | mH.sendMessageAtFrontOfQueue(m); |
| 3439 | return; |
| 3440 | } |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | // There is no existing starting window, and the caller doesn't |
| 3445 | // want us to create one, so that's it! |
| 3446 | if (!createIfNeeded) { |
| 3447 | return; |
| 3448 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3449 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3450 | // If this is a translucent or wallpaper window, then don't |
| 3451 | // show a starting window -- the current effect (a full-screen |
| 3452 | // opaque starting window that fades away to the real contents |
| 3453 | // when it is ready) does not work for this. |
| 3454 | if (theme != 0) { |
| 3455 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3456 | com.android.internal.R.styleable.Window); |
| 3457 | if (ent.array.getBoolean( |
| 3458 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3459 | return; |
| 3460 | } |
| 3461 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3462 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3463 | return; |
| 3464 | } |
| 3465 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3466 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3467 | return; |
| 3468 | } |
| 3469 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3471 | mStartingIconInTransition = true; |
| 3472 | wtoken.startingData = new StartingData( |
| 3473 | pkg, theme, nonLocalizedLabel, |
| 3474 | labelRes, icon); |
| 3475 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3476 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3477 | // want to process the message ASAP, before any other queued |
| 3478 | // messages. |
| 3479 | mH.sendMessageAtFrontOfQueue(m); |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | public void setAppWillBeHidden(IBinder token) { |
| 3484 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3485 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3486 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | AppWindowToken wtoken; |
| 3490 | |
| 3491 | synchronized(mWindowMap) { |
| 3492 | wtoken = findAppWindowToken(token); |
| 3493 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3494 | 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] | 3495 | return; |
| 3496 | } |
| 3497 | wtoken.willBeHidden = true; |
| 3498 | } |
| 3499 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3500 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3502 | boolean visible, int transit, boolean performLayout) { |
| 3503 | boolean delayed = false; |
| 3504 | |
| 3505 | if (wtoken.clientHidden == visible) { |
| 3506 | wtoken.clientHidden = !visible; |
| 3507 | wtoken.sendAppVisibilityToClients(); |
| 3508 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3510 | wtoken.willBeHidden = false; |
| 3511 | if (wtoken.hidden == visible) { |
| 3512 | final int N = wtoken.allAppWindows.size(); |
| 3513 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3514 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3515 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3516 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3517 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3519 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3520 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3521 | if (wtoken.animation == sDummyAnimation) { |
| 3522 | wtoken.animation = null; |
| 3523 | } |
| 3524 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3525 | changed = true; |
| 3526 | if (wtoken.animation != null) { |
| 3527 | delayed = runningAppAnimation = true; |
| 3528 | } |
| 3529 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3531 | for (int i=0; i<N; i++) { |
| 3532 | WindowState win = wtoken.allAppWindows.get(i); |
| 3533 | if (win == wtoken.startingWindow) { |
| 3534 | continue; |
| 3535 | } |
| 3536 | |
| 3537 | if (win.isAnimating()) { |
| 3538 | delayed = true; |
| 3539 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3540 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3541 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | //win.dump(" "); |
| 3543 | if (visible) { |
| 3544 | if (!win.isVisibleNow()) { |
| 3545 | if (!runningAppAnimation) { |
| 3546 | applyAnimationLocked(win, |
| 3547 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3548 | } |
| 3549 | changed = true; |
| 3550 | } |
| 3551 | } else if (win.isVisibleNow()) { |
| 3552 | if (!runningAppAnimation) { |
| 3553 | applyAnimationLocked(win, |
| 3554 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3555 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3556 | changed = true; |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3561 | if (!visible) { |
| 3562 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3563 | } else { |
| 3564 | // If we are being set visible, and the starting window is |
| 3565 | // not yet displayed, then make sure it doesn't get displayed. |
| 3566 | WindowState swin = wtoken.startingWindow; |
| 3567 | if (swin != null && (swin.mDrawPending |
| 3568 | || swin.mCommitDrawPending)) { |
| 3569 | swin.mPolicyVisibility = false; |
| 3570 | swin.mPolicyVisibilityAfterAnim = false; |
| 3571 | } |
| 3572 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3573 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3574 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3575 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3576 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3577 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3578 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3579 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3580 | if (performLayout) { |
| 3581 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3582 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3583 | } else { |
| 3584 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3585 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | if (wtoken.animation != null) { |
| 3590 | delayed = true; |
| 3591 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3592 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3593 | return delayed; |
| 3594 | } |
| 3595 | |
| 3596 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3597 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3598 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3599 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | AppWindowToken wtoken; |
| 3603 | |
| 3604 | synchronized(mWindowMap) { |
| 3605 | wtoken = findAppWindowToken(token); |
| 3606 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3607 | 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] | 3608 | return; |
| 3609 | } |
| 3610 | |
| 3611 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3612 | RuntimeException e = null; |
| 3613 | if (!HIDE_STACK_CRAWLS) { |
| 3614 | e = new RuntimeException(); |
| 3615 | e.fillInStackTrace(); |
| 3616 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3617 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | + "): mNextAppTransition=" + mNextAppTransition |
| 3619 | + " hidden=" + wtoken.hidden |
| 3620 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3621 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3622 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | // If we are preparing an app transition, then delay changing |
| 3624 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3625 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3626 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3627 | // Already in requested state, don't do anything more. |
| 3628 | if (wtoken.hiddenRequested != visible) { |
| 3629 | return; |
| 3630 | } |
| 3631 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3632 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3633 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3634 | TAG, "Setting dummy animation on: " + wtoken); |
| 3635 | wtoken.setDummyAnimation(); |
| 3636 | mOpeningApps.remove(wtoken); |
| 3637 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3638 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | wtoken.inPendingTransaction = true; |
| 3640 | if (visible) { |
| 3641 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3642 | wtoken.startingDisplayed = false; |
| 3643 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3644 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3645 | // If the token is currently hidden (should be the |
| 3646 | // common case), then we need to set up to wait for |
| 3647 | // its windows to be ready. |
| 3648 | if (wtoken.hidden) { |
| 3649 | wtoken.allDrawn = false; |
| 3650 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3651 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3652 | if (wtoken.clientHidden) { |
| 3653 | // In the case where we are making an app visible |
| 3654 | // but holding off for a transition, we still need |
| 3655 | // to tell the client to make its windows visible so |
| 3656 | // they get drawn. Otherwise, we will wait on |
| 3657 | // performing the transition until all windows have |
| 3658 | // been drawn, they never will be, and we are sad. |
| 3659 | wtoken.clientHidden = false; |
| 3660 | wtoken.sendAppVisibilityToClients(); |
| 3661 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | } |
| 3663 | } else { |
| 3664 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3665 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3666 | // If the token is currently visible (should be the |
| 3667 | // common case), then set up to wait for it to be hidden. |
| 3668 | if (!wtoken.hidden) { |
| 3669 | wtoken.waitingToHide = true; |
| 3670 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | } |
| 3672 | return; |
| 3673 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3674 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3675 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3676 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | wtoken.updateReportedVisibilityLocked(); |
| 3678 | Binder.restoreCallingIdentity(origId); |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3683 | boolean unfreezeSurfaceNow, boolean force) { |
| 3684 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3685 | 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] | 3686 | + " force=" + force); |
| 3687 | final int N = wtoken.allAppWindows.size(); |
| 3688 | boolean unfrozeWindows = false; |
| 3689 | for (int i=0; i<N; i++) { |
| 3690 | WindowState w = wtoken.allAppWindows.get(i); |
| 3691 | if (w.mAppFreezing) { |
| 3692 | w.mAppFreezing = false; |
| 3693 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3694 | w.mOrientationChanging = true; |
| 3695 | } |
| 3696 | unfrozeWindows = true; |
| 3697 | } |
| 3698 | } |
| 3699 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3700 | 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] | 3701 | wtoken.freezingScreen = false; |
| 3702 | mAppsFreezingScreen--; |
| 3703 | } |
| 3704 | if (unfreezeSurfaceNow) { |
| 3705 | if (unfrozeWindows) { |
| 3706 | mLayoutNeeded = true; |
| 3707 | performLayoutAndPlaceSurfacesLocked(); |
| 3708 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3709 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | } |
| 3711 | } |
| 3712 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3713 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3715 | int configChanges) { |
| 3716 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3717 | RuntimeException e = null; |
| 3718 | if (!HIDE_STACK_CRAWLS) { |
| 3719 | e = new RuntimeException(); |
| 3720 | e.fillInStackTrace(); |
| 3721 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3722 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3723 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3724 | + wtoken.freezingScreen, e); |
| 3725 | } |
| 3726 | if (!wtoken.hiddenRequested) { |
| 3727 | if (!wtoken.freezingScreen) { |
| 3728 | wtoken.freezingScreen = true; |
| 3729 | mAppsFreezingScreen++; |
| 3730 | if (mAppsFreezingScreen == 1) { |
| 3731 | startFreezingDisplayLocked(); |
| 3732 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3733 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3734 | 5000); |
| 3735 | } |
| 3736 | } |
| 3737 | final int N = wtoken.allAppWindows.size(); |
| 3738 | for (int i=0; i<N; i++) { |
| 3739 | WindowState w = wtoken.allAppWindows.get(i); |
| 3740 | w.mAppFreezing = true; |
| 3741 | } |
| 3742 | } |
| 3743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3745 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3746 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3747 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3748 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3752 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3753 | 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] | 3754 | return; |
| 3755 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3757 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3758 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3759 | 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] | 3760 | return; |
| 3761 | } |
| 3762 | final long origId = Binder.clearCallingIdentity(); |
| 3763 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3764 | Binder.restoreCallingIdentity(origId); |
| 3765 | } |
| 3766 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3767 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3768 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3769 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3770 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3771 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | synchronized(mWindowMap) { |
| 3775 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3776 | if (wtoken == null || wtoken.appToken == null) { |
| 3777 | return; |
| 3778 | } |
| 3779 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3780 | 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] | 3781 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3782 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3783 | Binder.restoreCallingIdentity(origId); |
| 3784 | } |
| 3785 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3786 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | public void removeAppToken(IBinder token) { |
| 3788 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3789 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3790 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | AppWindowToken wtoken = null; |
| 3794 | AppWindowToken startingToken = null; |
| 3795 | boolean delayed = false; |
| 3796 | |
| 3797 | final long origId = Binder.clearCallingIdentity(); |
| 3798 | synchronized(mWindowMap) { |
| 3799 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3800 | mTokenList.remove(basewtoken); |
| 3801 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3802 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3803 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3804 | wtoken.inPendingTransaction = false; |
| 3805 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3806 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | if (mClosingApps.contains(wtoken)) { |
| 3808 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3809 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3811 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3812 | delayed = true; |
| 3813 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3814 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3816 | + " animation=" + wtoken.animation |
| 3817 | + " animating=" + wtoken.animating); |
| 3818 | if (delayed) { |
| 3819 | // set the token aside because it has an active animation to be finished |
| 3820 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3821 | } else { |
| 3822 | // Make sure there is no animation running on this token, |
| 3823 | // so any windows associated with it will be removed as |
| 3824 | // soon as their animations are complete |
| 3825 | wtoken.animation = null; |
| 3826 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3827 | } |
| 3828 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3829 | if (mLastEnterAnimToken == wtoken) { |
| 3830 | mLastEnterAnimToken = null; |
| 3831 | mLastEnterAnimParams = null; |
| 3832 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | wtoken.removed = true; |
| 3834 | if (wtoken.startingData != null) { |
| 3835 | startingToken = wtoken; |
| 3836 | } |
| 3837 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3838 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3839 | 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] | 3840 | mFocusedApp = null; |
| 3841 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3842 | mInputMonitor.setFocusedAppLw(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | } |
| 3844 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3845 | 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] | 3846 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3847 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3848 | if (!delayed && wtoken != null) { |
| 3849 | wtoken.updateReportedVisibilityLocked(); |
| 3850 | } |
| 3851 | } |
| 3852 | Binder.restoreCallingIdentity(origId); |
| 3853 | |
| 3854 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3855 | 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] | 3856 | + startingToken + ": app token removed"); |
| 3857 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3858 | mH.sendMessage(m); |
| 3859 | } |
| 3860 | } |
| 3861 | |
| 3862 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3863 | final int NW = token.windows.size(); |
| 3864 | for (int i=0; i<NW; i++) { |
| 3865 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3866 | 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] | 3867 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3868 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3869 | int j = win.mChildWindows.size(); |
| 3870 | while (j > 0) { |
| 3871 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3872 | WindowState cwin = win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3873 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3874 | "Tmp removing child window " + cwin); |
| 3875 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3876 | } |
| 3877 | } |
| 3878 | return NW > 0; |
| 3879 | } |
| 3880 | |
| 3881 | void dumpAppTokensLocked() { |
| 3882 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3883 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | } |
| 3885 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3886 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | void dumpWindowsLocked() { |
| 3888 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3889 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | } |
| 3891 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3893 | private int findWindowOffsetLocked(int tokenPos) { |
| 3894 | final int NW = mWindows.size(); |
| 3895 | |
| 3896 | if (tokenPos >= mAppTokens.size()) { |
| 3897 | int i = NW; |
| 3898 | while (i > 0) { |
| 3899 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3900 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | if (win.getAppToken() != null) { |
| 3902 | return i+1; |
| 3903 | } |
| 3904 | } |
| 3905 | } |
| 3906 | |
| 3907 | while (tokenPos > 0) { |
| 3908 | // Find the first app token below the new position that has |
| 3909 | // a window displayed. |
| 3910 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3911 | 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] | 3912 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3913 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3914 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3915 | "Skipping token -- currently sending to bottom"); |
| 3916 | tokenPos--; |
| 3917 | continue; |
| 3918 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3919 | int i = wtoken.windows.size(); |
| 3920 | while (i > 0) { |
| 3921 | i--; |
| 3922 | WindowState win = wtoken.windows.get(i); |
| 3923 | int j = win.mChildWindows.size(); |
| 3924 | while (j > 0) { |
| 3925 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3926 | WindowState cwin = win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3927 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | for (int pos=NW-1; pos>=0; pos--) { |
| 3929 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3930 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3931 | "Found child win @" + (pos+1)); |
| 3932 | return pos+1; |
| 3933 | } |
| 3934 | } |
| 3935 | } |
| 3936 | } |
| 3937 | for (int pos=NW-1; pos>=0; pos--) { |
| 3938 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3939 | 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] | 3940 | return pos+1; |
| 3941 | } |
| 3942 | } |
| 3943 | } |
| 3944 | tokenPos--; |
| 3945 | } |
| 3946 | |
| 3947 | return 0; |
| 3948 | } |
| 3949 | |
| 3950 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3951 | final int NCW = win.mChildWindows.size(); |
| 3952 | boolean added = false; |
| 3953 | for (int j=0; j<NCW; j++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3954 | WindowState cwin = win.mChildWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3955 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3956 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3957 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3958 | mWindows.add(index, win); |
| 3959 | index++; |
| 3960 | added = true; |
| 3961 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3962 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3963 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | mWindows.add(index, cwin); |
| 3965 | index++; |
| 3966 | } |
| 3967 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3968 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3969 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3970 | mWindows.add(index, win); |
| 3971 | index++; |
| 3972 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3973 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3974 | return index; |
| 3975 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3976 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3977 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3978 | final int NW = token.windows.size(); |
| 3979 | for (int i=0; i<NW; i++) { |
| 3980 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3981 | } |
| 3982 | return index; |
| 3983 | } |
| 3984 | |
| 3985 | public void moveAppToken(int index, IBinder token) { |
| 3986 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3987 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3988 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3992 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3993 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3994 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3995 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3996 | 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] | 3997 | + token + " (" + wtoken + ")"); |
| 3998 | return; |
| 3999 | } |
| 4000 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4001 | 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] | 4002 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4003 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4005 | 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] | 4006 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4007 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4008 | 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] | 4009 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4010 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4011 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4013 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4014 | mLayoutNeeded = true; |
| 4015 | performLayoutAndPlaceSurfacesLocked(); |
| 4016 | } |
| 4017 | Binder.restoreCallingIdentity(origId); |
| 4018 | } |
| 4019 | } |
| 4020 | |
| 4021 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4022 | // XXX This should be done more efficiently! |
| 4023 | // (take advantage of the fact that both lists should be |
| 4024 | // ordered in the same way.) |
| 4025 | int N = tokens.size(); |
| 4026 | for (int i=0; i<N; i++) { |
| 4027 | IBinder token = tokens.get(i); |
| 4028 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4029 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4030 | 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] | 4031 | + token + " (" + wtoken + ")"); |
| 4032 | i--; |
| 4033 | N--; |
| 4034 | } |
| 4035 | } |
| 4036 | } |
| 4037 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4038 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4039 | boolean updateFocusAndLayout) { |
| 4040 | // First remove all of the windows from the list. |
| 4041 | tmpRemoveAppWindowsLocked(wtoken); |
| 4042 | |
| 4043 | // Where to start adding? |
| 4044 | int pos = findWindowOffsetLocked(tokenPos); |
| 4045 | |
| 4046 | // And now add them back at the correct place. |
| 4047 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4048 | |
| 4049 | if (updateFocusAndLayout) { |
| 4050 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4051 | assignLayersLocked(); |
| 4052 | } |
| 4053 | mLayoutNeeded = true; |
| 4054 | performLayoutAndPlaceSurfacesLocked(); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4058 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4059 | // First remove all of the windows from the list. |
| 4060 | final int N = tokens.size(); |
| 4061 | int i; |
| 4062 | for (i=0; i<N; i++) { |
| 4063 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4064 | if (token != null) { |
| 4065 | tmpRemoveAppWindowsLocked(token); |
| 4066 | } |
| 4067 | } |
| 4068 | |
| 4069 | // Where to start adding? |
| 4070 | int pos = findWindowOffsetLocked(tokenPos); |
| 4071 | |
| 4072 | // And now add them back at the correct place. |
| 4073 | for (i=0; i<N; i++) { |
| 4074 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4075 | if (token != null) { |
| 4076 | pos = reAddAppWindowsLocked(pos, token); |
| 4077 | } |
| 4078 | } |
| 4079 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4080 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4081 | assignLayersLocked(); |
| 4082 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | mLayoutNeeded = true; |
| 4084 | performLayoutAndPlaceSurfacesLocked(); |
| 4085 | |
| 4086 | //dump(); |
| 4087 | } |
| 4088 | |
| 4089 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4090 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4091 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4092 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | final long origId = Binder.clearCallingIdentity(); |
| 4096 | synchronized(mWindowMap) { |
| 4097 | removeAppTokensLocked(tokens); |
| 4098 | final int N = tokens.size(); |
| 4099 | for (int i=0; i<N; i++) { |
| 4100 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4101 | if (wt != null) { |
| 4102 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4103 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4104 | mToTopApps.remove(wt); |
| 4105 | mToBottomApps.remove(wt); |
| 4106 | mToTopApps.add(wt); |
| 4107 | wt.sendingToBottom = false; |
| 4108 | wt.sendingToTop = true; |
| 4109 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | } |
| 4111 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4112 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4113 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4114 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4115 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | } |
| 4117 | Binder.restoreCallingIdentity(origId); |
| 4118 | } |
| 4119 | |
| 4120 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4121 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4122 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4123 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | final long origId = Binder.clearCallingIdentity(); |
| 4127 | synchronized(mWindowMap) { |
| 4128 | removeAppTokensLocked(tokens); |
| 4129 | final int N = tokens.size(); |
| 4130 | int pos = 0; |
| 4131 | for (int i=0; i<N; i++) { |
| 4132 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4133 | if (wt != null) { |
| 4134 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4135 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4136 | mToTopApps.remove(wt); |
| 4137 | mToBottomApps.remove(wt); |
| 4138 | mToBottomApps.add(i, wt); |
| 4139 | wt.sendingToTop = false; |
| 4140 | wt.sendingToBottom = true; |
| 4141 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | pos++; |
| 4143 | } |
| 4144 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4145 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4146 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4147 | moveAppWindowsLocked(tokens, 0); |
| 4148 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | } |
| 4150 | Binder.restoreCallingIdentity(origId); |
| 4151 | } |
| 4152 | |
| 4153 | // ------------------------------------------------------------- |
| 4154 | // Misc IWindowSession methods |
| 4155 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4156 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4157 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4158 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4159 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4160 | // called before DevicePolicyManagerService has started. |
| 4161 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4162 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4163 | Context.DEVICE_POLICY_SERVICE); |
| 4164 | if (dpm != null) { |
| 4165 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4166 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4167 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4168 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4169 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4170 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4174 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4175 | != PackageManager.PERMISSION_GRANTED) { |
| 4176 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4177 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4178 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4179 | synchronized (mKeyguardTokenWatcher) { |
| 4180 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4181 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4185 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | != PackageManager.PERMISSION_GRANTED) { |
| 4187 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4188 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4190 | synchronized (mKeyguardTokenWatcher) { |
| 4191 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4192 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4193 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4194 | // If we are the last one to reenable the keyguard wait until |
| 4195 | // we have actually finished reenabling until returning. |
| 4196 | // It is possible that reenableKeyguard() can be called before |
| 4197 | // the previous disableKeyguard() is handled, in which case |
| 4198 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4199 | // be called. In that case mKeyguardDisabled will be false here |
| 4200 | // and we have nothing to wait for. |
| 4201 | while (mKeyguardDisabled) { |
| 4202 | try { |
| 4203 | mKeyguardTokenWatcher.wait(); |
| 4204 | } catch (InterruptedException e) { |
| 4205 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4206 | } |
| 4207 | } |
| 4208 | } |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | /** |
| 4213 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4214 | */ |
| 4215 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4216 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4217 | != PackageManager.PERMISSION_GRANTED) { |
| 4218 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4219 | } |
| 4220 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4221 | public void onKeyguardExitResult(boolean success) { |
| 4222 | try { |
| 4223 | callback.onKeyguardExitResult(success); |
| 4224 | } catch (RemoteException e) { |
| 4225 | // Client has died, we don't care. |
| 4226 | } |
| 4227 | } |
| 4228 | }); |
| 4229 | } |
| 4230 | |
| 4231 | public boolean inKeyguardRestrictedInputMode() { |
| 4232 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4233 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4234 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4235 | public void closeSystemDialogs(String reason) { |
| 4236 | synchronized(mWindowMap) { |
| 4237 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4238 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4239 | if (w.mSurface != null) { |
| 4240 | try { |
| 4241 | w.mClient.closeSystemDialogs(reason); |
| 4242 | } catch (RemoteException e) { |
| 4243 | } |
| 4244 | } |
| 4245 | } |
| 4246 | } |
| 4247 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4249 | static float fixScale(float scale) { |
| 4250 | if (scale < 0) scale = 0; |
| 4251 | else if (scale > 20) scale = 20; |
| 4252 | return Math.abs(scale); |
| 4253 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4254 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4255 | public void setAnimationScale(int which, float scale) { |
| 4256 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4257 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4258 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | if (scale < 0) scale = 0; |
| 4262 | else if (scale > 20) scale = 20; |
| 4263 | scale = Math.abs(scale); |
| 4264 | switch (which) { |
| 4265 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4266 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4267 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4269 | // Persist setting |
| 4270 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 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 | public void setAnimationScales(float[] scales) { |
| 4274 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4275 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4276 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4277 | } |
| 4278 | |
| 4279 | if (scales != null) { |
| 4280 | if (scales.length >= 1) { |
| 4281 | mWindowAnimationScale = fixScale(scales[0]); |
| 4282 | } |
| 4283 | if (scales.length >= 2) { |
| 4284 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4285 | } |
| 4286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | // Persist setting |
| 4289 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4290 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4292 | public float getAnimationScale(int which) { |
| 4293 | switch (which) { |
| 4294 | case 0: return mWindowAnimationScale; |
| 4295 | case 1: return mTransitionAnimationScale; |
| 4296 | } |
| 4297 | return 0; |
| 4298 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | public float[] getAnimationScales() { |
| 4301 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4302 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | public int getSwitchState(int sw) { |
| 4305 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4306 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4307 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4309 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4312 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4313 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4314 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4315 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4316 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4317 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4319 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4320 | public int getScancodeState(int sw) { |
| 4321 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4322 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4323 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4325 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4327 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4328 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4329 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4330 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4331 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4333 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4335 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4336 | public int getTrackballScancodeState(int sw) { |
| 4337 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4338 | "getTrackballScancodeState()")) { |
| 4339 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4340 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4341 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | public int getDPadScancodeState(int sw) { |
| 4345 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4346 | "getDPadScancodeState()")) { |
| 4347 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4348 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4349 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4350 | } |
| 4351 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4352 | public int getKeycodeState(int sw) { |
| 4353 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4354 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4355 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4356 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4357 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4359 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4360 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4361 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4362 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4363 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4364 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4365 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4367 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4368 | public int getTrackballKeycodeState(int sw) { |
| 4369 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4370 | "getTrackballKeycodeState()")) { |
| 4371 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4372 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4373 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4374 | } |
| 4375 | |
| 4376 | public int getDPadKeycodeState(int sw) { |
| 4377 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4378 | "getDPadKeycodeState()")) { |
| 4379 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4380 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4381 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4382 | } |
| 4383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4385 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4387 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4388 | public void enableScreenAfterBoot() { |
| 4389 | synchronized(mWindowMap) { |
| 4390 | if (mSystemBooted) { |
| 4391 | return; |
| 4392 | } |
| 4393 | mSystemBooted = true; |
| 4394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4396 | performEnableScreen(); |
| 4397 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4398 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4399 | public void enableScreenIfNeededLocked() { |
| 4400 | if (mDisplayEnabled) { |
| 4401 | return; |
| 4402 | } |
| 4403 | if (!mSystemBooted) { |
| 4404 | return; |
| 4405 | } |
| 4406 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4407 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4408 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4409 | public void performEnableScreen() { |
| 4410 | synchronized(mWindowMap) { |
| 4411 | if (mDisplayEnabled) { |
| 4412 | return; |
| 4413 | } |
| 4414 | if (!mSystemBooted) { |
| 4415 | return; |
| 4416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | // Don't enable the screen until all existing windows |
| 4419 | // have been drawn. |
| 4420 | final int N = mWindows.size(); |
| 4421 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4422 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4423 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4424 | return; |
| 4425 | } |
| 4426 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4427 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4428 | mDisplayEnabled = true; |
| 4429 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4430 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4431 | StringWriter sw = new StringWriter(); |
| 4432 | PrintWriter pw = new PrintWriter(sw); |
| 4433 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4434 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | } |
| 4436 | try { |
| 4437 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4438 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4439 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4440 | Parcel data = Parcel.obtain(); |
| 4441 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4442 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4443 | data, null, 0); |
| 4444 | data.recycle(); |
| 4445 | } |
| 4446 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4447 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | } |
| 4449 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4453 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4454 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4455 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4457 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4458 | public void setInTouchMode(boolean mode) { |
| 4459 | synchronized(mWindowMap) { |
| 4460 | mInTouchMode = mode; |
| 4461 | } |
| 4462 | } |
| 4463 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4464 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4465 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4467 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4468 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | } |
| 4470 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4471 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4472 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4473 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4474 | public void setRotationUnchecked(int rotation, |
| 4475 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4476 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4477 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4478 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4479 | long origId = Binder.clearCallingIdentity(); |
| 4480 | boolean changed; |
| 4481 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4482 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4483 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4484 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4485 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4486 | sendNewConfiguration(); |
| 4487 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4488 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | Binder.restoreCallingIdentity(origId); |
| 4490 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4491 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4492 | /** |
| 4493 | * Apply a new rotation to the screen, respecting the requests of |
| 4494 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4495 | * re-evaluate the desired rotation. |
| 4496 | * |
| 4497 | * Returns null if the rotation has been changed. In this case YOU |
| 4498 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4499 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4500 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4501 | boolean changed; |
| 4502 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4503 | rotation = mRequestedRotation; |
| 4504 | } else { |
| 4505 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4506 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4508 | 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] | 4509 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4510 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4511 | 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] | 4512 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4513 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4514 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4515 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4516 | "Rotation changed to " + rotation |
| 4517 | + " from " + mRotation |
| 4518 | + " (forceApp=" + mForcedAppOrientation |
| 4519 | + ", req=" + mRequestedRotation + ")"); |
| 4520 | mRotation = rotation; |
| 4521 | mWindowsFreezingScreen = true; |
| 4522 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4523 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4524 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4525 | mWaitingForConfig = true; |
| 4526 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4528 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4529 | mInputManager.setDisplayOrientation(0, rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4530 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4531 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4532 | } |
| 4533 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4534 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | if (w.mSurface != null) { |
| 4536 | w.mOrientationChanging = true; |
| 4537 | } |
| 4538 | } |
| 4539 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4540 | try { |
| 4541 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4542 | } catch (RemoteException e) { |
| 4543 | } |
| 4544 | } |
| 4545 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | return changed; |
| 4548 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4550 | public int getRotation() { |
| 4551 | return mRotation; |
| 4552 | } |
| 4553 | |
| 4554 | public int watchRotation(IRotationWatcher watcher) { |
| 4555 | final IBinder watcherBinder = watcher.asBinder(); |
| 4556 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4557 | public void binderDied() { |
| 4558 | synchronized (mWindowMap) { |
| 4559 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4560 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4561 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4562 | if (removed != null) { |
| 4563 | removed.asBinder().unlinkToDeath(this, 0); |
| 4564 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4565 | i--; |
| 4566 | } |
| 4567 | } |
| 4568 | } |
| 4569 | } |
| 4570 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4572 | synchronized (mWindowMap) { |
| 4573 | try { |
| 4574 | watcher.asBinder().linkToDeath(dr, 0); |
| 4575 | mRotationWatchers.add(watcher); |
| 4576 | } catch (RemoteException e) { |
| 4577 | // Client died, no cleanup needed. |
| 4578 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4579 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4580 | return mRotation; |
| 4581 | } |
| 4582 | } |
| 4583 | |
| 4584 | /** |
| 4585 | * Starts the view server on the specified port. |
| 4586 | * |
| 4587 | * @param port The port to listener to. |
| 4588 | * |
| 4589 | * @return True if the server was successfully started, false otherwise. |
| 4590 | * |
| 4591 | * @see com.android.server.ViewServer |
| 4592 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4593 | */ |
| 4594 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4595 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4596 | return false; |
| 4597 | } |
| 4598 | |
| 4599 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4600 | return false; |
| 4601 | } |
| 4602 | |
| 4603 | if (port < 1024) { |
| 4604 | return false; |
| 4605 | } |
| 4606 | |
| 4607 | if (mViewServer != null) { |
| 4608 | if (!mViewServer.isRunning()) { |
| 4609 | try { |
| 4610 | return mViewServer.start(); |
| 4611 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4612 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | } |
| 4614 | } |
| 4615 | return false; |
| 4616 | } |
| 4617 | |
| 4618 | try { |
| 4619 | mViewServer = new ViewServer(this, port); |
| 4620 | return mViewServer.start(); |
| 4621 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4622 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4623 | } |
| 4624 | return false; |
| 4625 | } |
| 4626 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4627 | private boolean isSystemSecure() { |
| 4628 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4629 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4630 | } |
| 4631 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4632 | /** |
| 4633 | * Stops the view server if it exists. |
| 4634 | * |
| 4635 | * @return True if the server stopped, false if it wasn't started or |
| 4636 | * couldn't be stopped. |
| 4637 | * |
| 4638 | * @see com.android.server.ViewServer |
| 4639 | */ |
| 4640 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4641 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4642 | return false; |
| 4643 | } |
| 4644 | |
| 4645 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4646 | return false; |
| 4647 | } |
| 4648 | |
| 4649 | if (mViewServer != null) { |
| 4650 | return mViewServer.stop(); |
| 4651 | } |
| 4652 | return false; |
| 4653 | } |
| 4654 | |
| 4655 | /** |
| 4656 | * Indicates whether the view server is running. |
| 4657 | * |
| 4658 | * @return True if the server is running, false otherwise. |
| 4659 | * |
| 4660 | * @see com.android.server.ViewServer |
| 4661 | */ |
| 4662 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4663 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4664 | return false; |
| 4665 | } |
| 4666 | |
| 4667 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4668 | return false; |
| 4669 | } |
| 4670 | |
| 4671 | return mViewServer != null && mViewServer.isRunning(); |
| 4672 | } |
| 4673 | |
| 4674 | /** |
| 4675 | * Lists all availble windows in the system. The listing is written in the |
| 4676 | * specified Socket's output stream with the following syntax: |
| 4677 | * windowHashCodeInHexadecimal windowName |
| 4678 | * Each line of the ouput represents a different window. |
| 4679 | * |
| 4680 | * @param client The remote client to send the listing to. |
| 4681 | * @return False if an error occured, true otherwise. |
| 4682 | */ |
| 4683 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4684 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | return false; |
| 4686 | } |
| 4687 | |
| 4688 | boolean result = true; |
| 4689 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4690 | WindowState[] windows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4691 | synchronized (mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4692 | //noinspection unchecked |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4693 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | } |
| 4695 | |
| 4696 | BufferedWriter out = null; |
| 4697 | |
| 4698 | // Any uncaught exception will crash the system process |
| 4699 | try { |
| 4700 | OutputStream clientStream = client.getOutputStream(); |
| 4701 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4702 | |
| 4703 | final int count = windows.length; |
| 4704 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4705 | final WindowState w = windows[i]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4707 | out.write(' '); |
| 4708 | out.append(w.mAttrs.getTitle()); |
| 4709 | out.write('\n'); |
| 4710 | } |
| 4711 | |
| 4712 | out.write("DONE.\n"); |
| 4713 | out.flush(); |
| 4714 | } catch (Exception e) { |
| 4715 | result = false; |
| 4716 | } finally { |
| 4717 | if (out != null) { |
| 4718 | try { |
| 4719 | out.close(); |
| 4720 | } catch (IOException e) { |
| 4721 | result = false; |
| 4722 | } |
| 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | return result; |
| 4727 | } |
| 4728 | |
| 4729 | /** |
| 4730 | * Sends a command to a target window. The result of the command, if any, will be |
| 4731 | * written in the output stream of the specified socket. |
| 4732 | * |
| 4733 | * The parameters must follow this syntax: |
| 4734 | * windowHashcode extra |
| 4735 | * |
| 4736 | * Where XX is the length in characeters of the windowTitle. |
| 4737 | * |
| 4738 | * The first parameter is the target window. The window with the specified hashcode |
| 4739 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4740 | * will be delivered to the target window and as parameters to the command itself. |
| 4741 | * |
| 4742 | * @param client The remote client to sent the result, if any, to. |
| 4743 | * @param command The command to execute. |
| 4744 | * @param parameters The command parameters. |
| 4745 | * |
| 4746 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4747 | * not indicate whether the command itself was successful. |
| 4748 | */ |
| 4749 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4750 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4751 | return false; |
| 4752 | } |
| 4753 | |
| 4754 | boolean success = true; |
| 4755 | Parcel data = null; |
| 4756 | Parcel reply = null; |
| 4757 | |
| 4758 | // Any uncaught exception will crash the system process |
| 4759 | try { |
| 4760 | // Find the hashcode of the window |
| 4761 | int index = parameters.indexOf(' '); |
| 4762 | if (index == -1) { |
| 4763 | index = parameters.length(); |
| 4764 | } |
| 4765 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4766 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4767 | |
| 4768 | // Extract the command's parameter after the window description |
| 4769 | if (index < parameters.length()) { |
| 4770 | parameters = parameters.substring(index + 1); |
| 4771 | } else { |
| 4772 | parameters = ""; |
| 4773 | } |
| 4774 | |
| 4775 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4776 | if (window == null) { |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
| 4780 | data = Parcel.obtain(); |
| 4781 | data.writeInterfaceToken("android.view.IWindow"); |
| 4782 | data.writeString(command); |
| 4783 | data.writeString(parameters); |
| 4784 | data.writeInt(1); |
| 4785 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4786 | |
| 4787 | reply = Parcel.obtain(); |
| 4788 | |
| 4789 | final IBinder binder = window.mClient.asBinder(); |
| 4790 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4791 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4792 | |
| 4793 | reply.readException(); |
| 4794 | |
| 4795 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4796 | 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] | 4797 | success = false; |
| 4798 | } finally { |
| 4799 | if (data != null) { |
| 4800 | data.recycle(); |
| 4801 | } |
| 4802 | if (reply != null) { |
| 4803 | reply.recycle(); |
| 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | return success; |
| 4808 | } |
| 4809 | |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4810 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 4811 | synchronized(mWindowMap) { |
| 4812 | mWindowChangeListeners.add(listener); |
| 4813 | } |
| 4814 | } |
| 4815 | |
| 4816 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 4817 | synchronized(mWindowMap) { |
| 4818 | mWindowChangeListeners.remove(listener); |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | private void notifyWindowsChanged() { |
| 4823 | WindowChangeListener[] windowChangeListeners; |
| 4824 | synchronized(mWindowMap) { |
| 4825 | if(mWindowChangeListeners.isEmpty()) { |
| 4826 | return; |
| 4827 | } |
| 4828 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 4829 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 4830 | } |
| 4831 | int N = windowChangeListeners.length; |
| 4832 | for(int i = 0; i < N; i++) { |
| 4833 | windowChangeListeners[i].windowsChanged(); |
| 4834 | } |
| 4835 | } |
| 4836 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 4837 | private void notifyFocusChanged() { |
| 4838 | WindowChangeListener[] windowChangeListeners; |
| 4839 | synchronized(mWindowMap) { |
| 4840 | if(mWindowChangeListeners.isEmpty()) { |
| 4841 | return; |
| 4842 | } |
| 4843 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 4844 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 4845 | } |
| 4846 | int N = windowChangeListeners.length; |
| 4847 | for(int i = 0; i < N; i++) { |
| 4848 | windowChangeListeners[i].focusChanged(); |
| 4849 | } |
| 4850 | } |
| 4851 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4852 | private WindowState findWindow(int hashCode) { |
| 4853 | if (hashCode == -1) { |
| 4854 | return getFocusedWindow(); |
| 4855 | } |
| 4856 | |
| 4857 | synchronized (mWindowMap) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4858 | final ArrayList<WindowState> windows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4859 | final int count = windows.size(); |
| 4860 | |
| 4861 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4862 | WindowState w = windows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4863 | if (System.identityHashCode(w) == hashCode) { |
| 4864 | return w; |
| 4865 | } |
| 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | return null; |
| 4870 | } |
| 4871 | |
| 4872 | /* |
| 4873 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4874 | * that to config-changed listeners if appropriate. |
| 4875 | */ |
| 4876 | void sendNewConfiguration() { |
| 4877 | try { |
| 4878 | mActivityManager.updateConfiguration(null); |
| 4879 | } catch (RemoteException e) { |
| 4880 | } |
| 4881 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | public Configuration computeNewConfiguration() { |
| 4884 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4885 | return computeNewConfigurationLocked(); |
| 4886 | } |
| 4887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4888 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4889 | Configuration computeNewConfigurationLocked() { |
| 4890 | Configuration config = new Configuration(); |
| 4891 | if (!computeNewConfigurationLocked(config)) { |
| 4892 | return null; |
| 4893 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4894 | return config; |
| 4895 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4896 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4897 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4898 | if (mDisplay == null) { |
| 4899 | return false; |
| 4900 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4901 | |
| 4902 | mInputManager.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 4903 | |
| 4904 | // Use the effective "visual" dimensions based on current rotation |
| 4905 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 4906 | || mRotation == Surface.ROTATION_270); |
| 4907 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 4908 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 4909 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4910 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4911 | if (dw < dh) { |
| 4912 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4913 | } else if (dw > dh) { |
| 4914 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4915 | } |
| 4916 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4917 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4918 | DisplayMetrics dm = new DisplayMetrics(); |
| 4919 | mDisplay.getMetrics(dm); |
| 4920 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4921 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4922 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4923 | // Note we only do this once because at this point we don't |
| 4924 | // expect the screen to change in this way at runtime, and want |
| 4925 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4926 | int longSize = dw; |
| 4927 | int shortSize = dh; |
| 4928 | if (longSize < shortSize) { |
| 4929 | int tmp = longSize; |
| 4930 | longSize = shortSize; |
| 4931 | shortSize = tmp; |
| 4932 | } |
| 4933 | longSize = (int)(longSize/dm.density); |
| 4934 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4935 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4936 | // These semi-magic numbers define our compatibility modes for |
| 4937 | // applications with different screens. Don't change unless you |
| 4938 | // make sure to test lots and lots of apps! |
| 4939 | if (longSize < 470) { |
| 4940 | // This is shorter than an HVGA normal density screen (which |
| 4941 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4942 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4943 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4944 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 4945 | // What size is this screen screen? |
| 4946 | if (longSize >= 800 && shortSize >= 600) { |
| 4947 | // SVGA or larger screens at medium density are the point |
| 4948 | // at which we consider it to be an extra large screen. |
| 4949 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 4950 | } else if (longSize >= 640 && shortSize >= 480) { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4951 | // VGA or larger screens at medium density are the point |
| 4952 | // at which we consider it to be a large screen. |
| 4953 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4954 | } else { |
| 4955 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4956 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4957 | // If this screen is wider than normal HVGA, or taller |
| 4958 | // than FWVGA, then for old apps we want to run in size |
| 4959 | // compatibility mode. |
| 4960 | if (shortSize > 321 || longSize > 570) { |
| 4961 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4962 | } |
| 4963 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4964 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4965 | // Is this a long screen? |
| 4966 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4967 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4968 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4969 | } else { |
| 4970 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4971 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4972 | } |
| 4973 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4974 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4975 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4976 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4977 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4978 | mPolicy.adjustConfigurationLw(config); |
| 4979 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4980 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 4981 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4982 | // ------------------------------------------------------------- |
| 4983 | // Input Events and Focus Management |
| 4984 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4985 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4986 | InputMonitor mInputMonitor = new InputMonitor(); |
| 4987 | |
| 4988 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 4989 | * is kept in sync with changes in window focus, visibility, registration, and |
| 4990 | * other relevant Window Manager state transitions. */ |
| 4991 | final class InputMonitor { |
| 4992 | // Current window with input focus for keys and other non-touch events. May be null. |
| 4993 | private WindowState mInputFocus; |
| 4994 | |
| 4995 | // When true, prevents input dispatch from proceeding until set to false again. |
| 4996 | private boolean mInputDispatchFrozen; |
| 4997 | |
| 4998 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 4999 | private boolean mInputDispatchEnabled = true; |
| 5000 | |
| 5001 | // Temporary list of windows information to provide to the input dispatcher. |
| 5002 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5003 | |
| 5004 | // Temporary input application object to provide to the input dispatcher. |
| 5005 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5006 | |
| 5007 | /* Notifies the window manager about a broken input channel. |
| 5008 | * |
| 5009 | * Called by the InputManager. |
| 5010 | */ |
| 5011 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5012 | synchronized (mWindowMap) { |
| 5013 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5014 | if (windowState == null) { |
| 5015 | return; // irrelevant |
| 5016 | } |
| 5017 | |
| 5018 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5019 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5020 | } |
| 5021 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5022 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5023 | /* Notifies the window manager about an input channel that is not responding. |
| 5024 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5025 | * return a new timeout in nanoseconds. |
| 5026 | * |
| 5027 | * Called by the InputManager. |
| 5028 | */ |
| 5029 | public long notifyInputChannelANR(InputChannel inputChannel) { |
| 5030 | AppWindowToken token; |
| 5031 | synchronized (mWindowMap) { |
| 5032 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5033 | if (windowState == null) { |
| 5034 | return -2; // irrelevant, abort dispatching (-2) |
| 5035 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5036 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5037 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5038 | + windowState.mAttrs.getTitle()); |
| 5039 | token = windowState.mAppToken; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5040 | } |
| 5041 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5042 | return notifyANRInternal(token); |
| 5043 | } |
| 5044 | |
| 5045 | /* Notifies the window manager about an input channel spontaneously recovering from ANR |
| 5046 | * by successfully delivering the event that originally timed out. |
| 5047 | * |
| 5048 | * Called by the InputManager. |
| 5049 | */ |
| 5050 | public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) { |
| 5051 | // Nothing to do just now. |
| 5052 | // Just wait for the user to dismiss the ANR dialog. |
| 5053 | } |
| 5054 | |
| 5055 | /* Notifies the window manager about an application that is not responding |
| 5056 | * in general rather than with respect to a particular input channel. |
| 5057 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5058 | * return a new timeout in nanoseconds. |
| 5059 | * |
| 5060 | * Called by the InputManager. |
| 5061 | */ |
| 5062 | public long notifyANR(Object token) { |
| 5063 | AppWindowToken appWindowToken = (AppWindowToken) token; |
| 5064 | |
| 5065 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5066 | + appWindowToken.stringName); |
| 5067 | return notifyANRInternal(appWindowToken); |
| 5068 | } |
| 5069 | |
| 5070 | private long notifyANRInternal(AppWindowToken token) { |
| 5071 | if (token != null && token.appToken != null) { |
| 5072 | try { |
| 5073 | // Notify the activity manager about the timeout and let it decide whether |
| 5074 | // to abort dispatching or keep waiting. |
| 5075 | boolean abort = token.appToken.keyDispatchingTimedOut(); |
| 5076 | if (! abort) { |
| 5077 | // The activity manager declined to abort dispatching. |
| 5078 | // Wait a bit longer and timeout again later. |
| 5079 | return token.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5080 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5081 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5082 | } |
| 5083 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5084 | return -2; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5085 | } |
| 5086 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5087 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5088 | synchronized (mWindowMap) { |
| 5089 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5090 | } |
| 5091 | } |
| 5092 | |
| 5093 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5094 | int windowCount = mWindows.size(); |
| 5095 | for (int i = 0; i < windowCount; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5096 | WindowState windowState = mWindows.get(i); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5097 | if (windowState.mInputChannel == inputChannel) { |
| 5098 | return windowState; |
| 5099 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5102 | return null; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5103 | } |
| 5104 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5105 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5106 | public void updateInputWindowsLw() { |
| 5107 | // Populate the input window list with information about all of the windows that |
| 5108 | // could potentially receive input. |
| 5109 | // As an optimization, we could try to prune the list of windows but this turns |
| 5110 | // out to be difficult because only the native code knows for sure which window |
| 5111 | // currently has touch focus. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5112 | final ArrayList<WindowState> windows = mWindows; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5113 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5114 | for (int i = N - 1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5115 | final WindowState child = windows.get(i); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5116 | if (child.mInputChannel == null || child.mRemoved) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5117 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5118 | continue; |
| 5119 | } |
| 5120 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5121 | final int flags = child.mAttrs.flags; |
| 5122 | final int type = child.mAttrs.type; |
| 5123 | |
| 5124 | final boolean hasFocus = (child == mInputFocus); |
| 5125 | final boolean isVisible = child.isVisibleLw(); |
| 5126 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5127 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| 5128 | |
| 5129 | // Add a window to our list of input windows. |
| 5130 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5131 | inputWindow.inputChannel = child.mInputChannel; |
| 5132 | inputWindow.layoutParamsFlags = flags; |
| 5133 | inputWindow.layoutParamsType = type; |
| 5134 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5135 | inputWindow.visible = isVisible; |
| 5136 | inputWindow.hasFocus = hasFocus; |
| 5137 | inputWindow.hasWallpaper = hasWallpaper; |
| 5138 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 5139 | inputWindow.ownerPid = child.mSession.mPid; |
| 5140 | inputWindow.ownerUid = child.mSession.mUid; |
| 5141 | |
| 5142 | final Rect frame = child.mFrame; |
| 5143 | inputWindow.frameLeft = frame.left; |
| 5144 | inputWindow.frameTop = frame.top; |
| 5145 | |
| 5146 | switch (child.mTouchableInsets) { |
| 5147 | default: |
| 5148 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5149 | inputWindow.touchableAreaLeft = frame.left; |
| 5150 | inputWindow.touchableAreaTop = frame.top; |
| 5151 | inputWindow.touchableAreaRight = frame.right; |
| 5152 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5153 | break; |
| 5154 | |
| 5155 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5156 | Rect inset = child.mGivenContentInsets; |
| 5157 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5158 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5159 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5160 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5161 | break; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5162 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5163 | |
| 5164 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5165 | Rect inset = child.mGivenVisibleInsets; |
| 5166 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5167 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5168 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5169 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5170 | break; |
| 5171 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5172 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5173 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5174 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5175 | // Send windows to native code. |
| 5176 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5177 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5178 | // Clear the list in preparation for the next round. |
| 5179 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5180 | mTempInputWindows.clear(); |
| 5181 | } |
| 5182 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5183 | /* Provides feedback for a virtual key down. */ |
| 5184 | public void virtualKeyDownFeedback() { |
| 5185 | synchronized (mWindowMap) { |
| 5186 | mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5187 | } |
| 5188 | } |
| 5189 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5190 | /* Notifies that an app switch key (BACK / HOME) has just been pressed. |
| 5191 | * This essentially starts a .5 second timeout for the application to process |
| 5192 | * subsequent input events while waiting for the app switch to occur. If it takes longer |
| 5193 | * than this, the pending events will be dropped. |
| 5194 | */ |
| 5195 | public void notifyAppSwitchComing() { |
| 5196 | // TODO Not implemented yet. Should go in the native side. |
| 5197 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5198 | |
| 5199 | /* Notifies that the lid switch changed state. */ |
| 5200 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5201 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5202 | } |
| 5203 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5204 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5205 | * processing as soon as the key has been read from the device. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5206 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5207 | int policyFlags, boolean isScreenOn) { |
| 5208 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5209 | keyCode, down, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | /* Provides an opportunity for the window manager policy to process a key before |
| 5213 | * ordinary dispatch. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5214 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5215 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5216 | int policyFlags) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5217 | WindowState windowState = getWindowStateForInputChannel(focus); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5218 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5219 | keyCode, metaState, repeatCount, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | /* Called when the current input focus changes. |
| 5223 | * Layer assignment is assumed to be complete by the time this is called. |
| 5224 | */ |
| 5225 | public void setInputFocusLw(WindowState newWindow) { |
| 5226 | if (DEBUG_INPUT) { |
| 5227 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5228 | } |
| 5229 | |
| 5230 | if (newWindow != mInputFocus) { |
| 5231 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 5232 | // If the new input focus is an error window or appears above the current |
| 5233 | // input focus, preempt any pending synchronous dispatch so that we can |
| 5234 | // start delivering events to the new input focus as soon as possible. |
| 5235 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5236 | if (DEBUG_INPUT) { |
| 5237 | Slog.v(TAG, "New SYSTEM_ERROR window; resetting state"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5238 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5239 | preemptInputDispatchLw(); |
| 5240 | } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) { |
| 5241 | if (DEBUG_INPUT) { |
| 5242 | Slog.v(TAG, "Transferring focus to new window at higher layer: " |
| 5243 | + "old win layer=" + mInputFocus.mLayer |
| 5244 | + ", new win layer=" + newWindow.mLayer); |
| 5245 | } |
| 5246 | preemptInputDispatchLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5247 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5248 | |
| 5249 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5250 | // This is to protect against bugs if someone pauses dispatching but |
| 5251 | // forgets to resume. |
| 5252 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5253 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5254 | |
| 5255 | mInputFocus = newWindow; |
| 5256 | updateInputWindowsLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5257 | } |
| 5258 | } |
| 5259 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5260 | /* Tells the dispatcher to stop waiting for its current synchronous event targets. |
| 5261 | * Essentially, just makes those dispatches asynchronous so a new dispatch cycle |
| 5262 | * can begin. |
| 5263 | */ |
| 5264 | private void preemptInputDispatchLw() { |
| 5265 | mInputManager.preemptInputDispatch(); |
| 5266 | } |
| 5267 | |
| 5268 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5269 | // Focused app has changed. |
| 5270 | if (newApp == null) { |
| 5271 | mInputManager.setFocusedApplication(null); |
| 5272 | } else { |
| 5273 | mTempInputApplication.name = newApp.toString(); |
| 5274 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5275 | newApp.inputDispatchingTimeoutNanos; |
| 5276 | mTempInputApplication.token = newApp; |
| 5277 | |
| 5278 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5279 | } |
| 5280 | } |
| 5281 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5282 | public void pauseDispatchingLw(WindowToken window) { |
| 5283 | if (! window.paused) { |
| 5284 | if (DEBUG_INPUT) { |
| 5285 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5286 | } |
| 5287 | |
| 5288 | window.paused = true; |
| 5289 | updateInputWindowsLw(); |
| 5290 | } |
| 5291 | } |
| 5292 | |
| 5293 | public void resumeDispatchingLw(WindowToken window) { |
| 5294 | if (window.paused) { |
| 5295 | if (DEBUG_INPUT) { |
| 5296 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5297 | } |
| 5298 | |
| 5299 | window.paused = false; |
| 5300 | updateInputWindowsLw(); |
| 5301 | } |
| 5302 | } |
| 5303 | |
| 5304 | public void freezeInputDispatchingLw() { |
| 5305 | if (! mInputDispatchFrozen) { |
| 5306 | if (DEBUG_INPUT) { |
| 5307 | Slog.v(TAG, "Freezing input dispatching"); |
| 5308 | } |
| 5309 | |
| 5310 | mInputDispatchFrozen = true; |
| 5311 | updateInputDispatchModeLw(); |
| 5312 | } |
| 5313 | } |
| 5314 | |
| 5315 | public void thawInputDispatchingLw() { |
| 5316 | if (mInputDispatchFrozen) { |
| 5317 | if (DEBUG_INPUT) { |
| 5318 | Slog.v(TAG, "Thawing input dispatching"); |
| 5319 | } |
| 5320 | |
| 5321 | mInputDispatchFrozen = false; |
| 5322 | updateInputDispatchModeLw(); |
| 5323 | } |
| 5324 | } |
| 5325 | |
| 5326 | public void setEventDispatchingLw(boolean enabled) { |
| 5327 | if (mInputDispatchEnabled != enabled) { |
| 5328 | if (DEBUG_INPUT) { |
| 5329 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5330 | } |
| 5331 | |
| 5332 | mInputDispatchEnabled = enabled; |
| 5333 | updateInputDispatchModeLw(); |
| 5334 | } |
| 5335 | } |
| 5336 | |
| 5337 | private void updateInputDispatchModeLw() { |
| 5338 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5339 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5340 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | public void pauseKeyDispatching(IBinder _token) { |
| 5343 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5344 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5345 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | synchronized (mWindowMap) { |
| 5349 | WindowToken token = mTokenMap.get(_token); |
| 5350 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5351 | mInputMonitor.pauseDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5352 | } |
| 5353 | } |
| 5354 | } |
| 5355 | |
| 5356 | public void resumeKeyDispatching(IBinder _token) { |
| 5357 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5358 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5359 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | synchronized (mWindowMap) { |
| 5363 | WindowToken token = mTokenMap.get(_token); |
| 5364 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5365 | mInputMonitor.resumeDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5366 | } |
| 5367 | } |
| 5368 | } |
| 5369 | |
| 5370 | public void setEventDispatching(boolean enabled) { |
| 5371 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5372 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5373 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | synchronized (mWindowMap) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5377 | mInputMonitor.setEventDispatchingLw(enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5378 | } |
| 5379 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | /** |
| 5382 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5383 | * |
| 5384 | * @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] | 5385 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5386 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5387 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5388 | */ |
| 5389 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5390 | long downTime = ev.getDownTime(); |
| 5391 | long eventTime = ev.getEventTime(); |
| 5392 | |
| 5393 | int action = ev.getAction(); |
| 5394 | int code = ev.getKeyCode(); |
| 5395 | int repeatCount = ev.getRepeatCount(); |
| 5396 | int metaState = ev.getMetaState(); |
| 5397 | int deviceId = ev.getDeviceId(); |
| 5398 | int scancode = ev.getScanCode(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5399 | int source = ev.getSource(); |
| 5400 | |
| 5401 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5402 | source = InputDevice.SOURCE_KEYBOARD; |
| 5403 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5404 | |
| 5405 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5406 | if (downTime == 0) downTime = eventTime; |
| 5407 | |
| 5408 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5409 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5410 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5411 | final int pid = Binder.getCallingPid(); |
| 5412 | final int uid = Binder.getCallingUid(); |
| 5413 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5414 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5415 | final int result = mInputManager.injectKeyEvent(newEvent, |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5416 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5417 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5418 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5419 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | /** |
| 5423 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5424 | * |
| 5425 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5426 | * {@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] | 5427 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5428 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5429 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5430 | */ |
| 5431 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5432 | final int pid = Binder.getCallingPid(); |
| 5433 | final int uid = Binder.getCallingUid(); |
| 5434 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5435 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5436 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5437 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5438 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5439 | } |
| 5440 | |
| 5441 | final int result = mInputManager.injectMotionEvent(newEvent, |
| 5442 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5443 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5444 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5445 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5446 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5447 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5448 | /** |
| 5449 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5450 | * |
| 5451 | * @param ev A motion event describing the trackball action. (As noted in |
| 5452 | * {@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] | 5453 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5454 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5455 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5456 | */ |
| 5457 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5458 | final int pid = Binder.getCallingPid(); |
| 5459 | final int uid = Binder.getCallingUid(); |
| 5460 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5461 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5462 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5463 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5464 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5465 | } |
| 5466 | |
| 5467 | final int result = mInputManager.injectMotionEvent(newEvent, |
| 5468 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5469 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5470 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5471 | return reportInjectionResult(result); |
| 5472 | } |
| 5473 | |
| 5474 | private boolean reportInjectionResult(int result) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5475 | switch (result) { |
| 5476 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5477 | Slog.w(TAG, "Input event injection permission denied."); |
| 5478 | throw new SecurityException( |
| 5479 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5480 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| 5481 | Slog.v(TAG, "Input event injection succeeded."); |
| 5482 | return true; |
| 5483 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5484 | Slog.w(TAG, "Input event injection timed out."); |
| 5485 | return false; |
| 5486 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5487 | default: |
| 5488 | Slog.w(TAG, "Input event injection failed."); |
| 5489 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5490 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5491 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | private WindowState getFocusedWindow() { |
| 5494 | synchronized (mWindowMap) { |
| 5495 | return getFocusedWindowLocked(); |
| 5496 | } |
| 5497 | } |
| 5498 | |
| 5499 | private WindowState getFocusedWindowLocked() { |
| 5500 | return mCurrentFocus; |
| 5501 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5503 | public boolean detectSafeMode() { |
| 5504 | mSafeMode = mPolicy.detectSafeMode(); |
| 5505 | return mSafeMode; |
| 5506 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5507 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5508 | public void systemReady() { |
| 5509 | mPolicy.systemReady(); |
| 5510 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5511 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5512 | // ------------------------------------------------------------- |
| 5513 | // Client Session State |
| 5514 | // ------------------------------------------------------------- |
| 5515 | |
| 5516 | private final class Session extends IWindowSession.Stub |
| 5517 | implements IBinder.DeathRecipient { |
| 5518 | final IInputMethodClient mClient; |
| 5519 | final IInputContext mInputContext; |
| 5520 | final int mUid; |
| 5521 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5522 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5523 | SurfaceSession mSurfaceSession; |
| 5524 | int mNumWindow = 0; |
| 5525 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5527 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 5528 | mClient = client; |
| 5529 | mInputContext = inputContext; |
| 5530 | mUid = Binder.getCallingUid(); |
| 5531 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5532 | StringBuilder sb = new StringBuilder(); |
| 5533 | sb.append("Session{"); |
| 5534 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5535 | sb.append(" uid "); |
| 5536 | sb.append(mUid); |
| 5537 | sb.append("}"); |
| 5538 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5539 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5540 | synchronized (mWindowMap) { |
| 5541 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 5542 | IBinder b = ServiceManager.getService( |
| 5543 | Context.INPUT_METHOD_SERVICE); |
| 5544 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 5545 | } |
| 5546 | } |
| 5547 | long ident = Binder.clearCallingIdentity(); |
| 5548 | try { |
| 5549 | // Note: it is safe to call in to the input method manager |
| 5550 | // here because we are not holding our lock. |
| 5551 | if (mInputMethodManager != null) { |
| 5552 | mInputMethodManager.addClient(client, inputContext, |
| 5553 | mUid, mPid); |
| 5554 | } else { |
| 5555 | client.setUsingInputMethod(false); |
| 5556 | } |
| 5557 | client.asBinder().linkToDeath(this, 0); |
| 5558 | } catch (RemoteException e) { |
| 5559 | // The caller has died, so we can just forget about this. |
| 5560 | try { |
| 5561 | if (mInputMethodManager != null) { |
| 5562 | mInputMethodManager.removeClient(client); |
| 5563 | } |
| 5564 | } catch (RemoteException ee) { |
| 5565 | } |
| 5566 | } finally { |
| 5567 | Binder.restoreCallingIdentity(ident); |
| 5568 | } |
| 5569 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5571 | @Override |
| 5572 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 5573 | throws RemoteException { |
| 5574 | try { |
| 5575 | return super.onTransact(code, data, reply, flags); |
| 5576 | } catch (RuntimeException e) { |
| 5577 | // Log all 'real' exceptions thrown to the caller |
| 5578 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5579 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | } |
| 5581 | throw e; |
| 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | public void binderDied() { |
| 5586 | // Note: it is safe to call in to the input method manager |
| 5587 | // here because we are not holding our lock. |
| 5588 | try { |
| 5589 | if (mInputMethodManager != null) { |
| 5590 | mInputMethodManager.removeClient(mClient); |
| 5591 | } |
| 5592 | } catch (RemoteException e) { |
| 5593 | } |
| 5594 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5595 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5596 | mClientDead = true; |
| 5597 | killSessionLocked(); |
| 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5602 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 5603 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 5604 | outInputChannel); |
| 5605 | } |
| 5606 | |
| 5607 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5608 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5609 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5610 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5612 | public void remove(IWindow window) { |
| 5613 | removeWindow(this, window); |
| 5614 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5615 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5616 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 5617 | int requestedWidth, int requestedHeight, int viewFlags, |
| 5618 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5619 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5620 | return relayoutWindow(this, window, attrs, |
| 5621 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5622 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5623 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5625 | public void setTransparentRegion(IWindow window, Region region) { |
| 5626 | setTransparentRegionWindow(this, window, region); |
| 5627 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5629 | public void setInsets(IWindow window, int touchableInsets, |
| 5630 | Rect contentInsets, Rect visibleInsets) { |
| 5631 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 5632 | visibleInsets); |
| 5633 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5634 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5635 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 5636 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 5637 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5638 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5640 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | TAG, "IWindow finishDrawing called for " + window); |
| 5642 | finishDrawingWindow(this, window); |
| 5643 | } |
| 5644 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5645 | public void setInTouchMode(boolean mode) { |
| 5646 | synchronized(mWindowMap) { |
| 5647 | mInTouchMode = mode; |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | public boolean getInTouchMode() { |
| 5652 | synchronized(mWindowMap) { |
| 5653 | return mInTouchMode; |
| 5654 | } |
| 5655 | } |
| 5656 | |
| 5657 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 5658 | boolean always) { |
| 5659 | synchronized(mWindowMap) { |
| 5660 | long ident = Binder.clearCallingIdentity(); |
| 5661 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5662 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5663 | windowForClientLocked(this, window, true), |
| 5664 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | } finally { |
| 5666 | Binder.restoreCallingIdentity(ident); |
| 5667 | } |
| 5668 | } |
| 5669 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5670 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5671 | 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] | 5672 | synchronized(mWindowMap) { |
| 5673 | long ident = Binder.clearCallingIdentity(); |
| 5674 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5675 | setWindowWallpaperPositionLocked( |
| 5676 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5677 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 5678 | } finally { |
| 5679 | Binder.restoreCallingIdentity(ident); |
| 5680 | } |
| 5681 | } |
| 5682 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5683 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 5684 | public void wallpaperOffsetsComplete(IBinder window) { |
| 5685 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 5686 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5687 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5688 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 5689 | int z, Bundle extras, boolean sync) { |
| 5690 | synchronized(mWindowMap) { |
| 5691 | long ident = Binder.clearCallingIdentity(); |
| 5692 | try { |
| 5693 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5694 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5695 | action, x, y, z, extras, sync); |
| 5696 | } finally { |
| 5697 | Binder.restoreCallingIdentity(ident); |
| 5698 | } |
| 5699 | } |
| 5700 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5701 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5702 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 5703 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 5704 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5705 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5706 | void windowAddedLocked() { |
| 5707 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5708 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5709 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 5710 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5711 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5712 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5713 | mSessions.add(this); |
| 5714 | } |
| 5715 | mNumWindow++; |
| 5716 | } |
| 5717 | |
| 5718 | void windowRemovedLocked() { |
| 5719 | mNumWindow--; |
| 5720 | killSessionLocked(); |
| 5721 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5722 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5723 | void killSessionLocked() { |
| 5724 | if (mNumWindow <= 0 && mClientDead) { |
| 5725 | mSessions.remove(this); |
| 5726 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5727 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5728 | TAG, "Last window removed from " + this |
| 5729 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5730 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5731 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5732 | try { |
| 5733 | mSurfaceSession.kill(); |
| 5734 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5735 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5736 | + mSurfaceSession + " in session " + this |
| 5737 | + ": " + e.toString()); |
| 5738 | } |
| 5739 | mSurfaceSession = null; |
| 5740 | } |
| 5741 | } |
| 5742 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5743 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5744 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5745 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 5746 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 5747 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | @Override |
| 5751 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5752 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | } |
| 5754 | } |
| 5755 | |
| 5756 | // ------------------------------------------------------------- |
| 5757 | // Client Window State |
| 5758 | // ------------------------------------------------------------- |
| 5759 | |
| 5760 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 5761 | final Session mSession; |
| 5762 | final IWindow mClient; |
| 5763 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5764 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5765 | AppWindowToken mAppToken; |
| 5766 | AppWindowToken mTargetAppToken; |
| 5767 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 5768 | final DeathRecipient mDeathRecipient; |
| 5769 | final WindowState mAttachedWindow; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5770 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | final int mBaseLayer; |
| 5772 | final int mSubLayer; |
| 5773 | final boolean mLayoutAttached; |
| 5774 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5775 | final boolean mIsWallpaper; |
| 5776 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | int mViewVisibility; |
| 5778 | boolean mPolicyVisibility = true; |
| 5779 | boolean mPolicyVisibilityAfterAnim = true; |
| 5780 | boolean mAppFreezing; |
| 5781 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5782 | boolean mReportDestroySurface; |
| 5783 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5784 | boolean mAttachedHidden; // is our parent window hidden? |
| 5785 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 5786 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5787 | int mRequestedWidth; |
| 5788 | int mRequestedHeight; |
| 5789 | int mLastRequestedWidth; |
| 5790 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | int mLayer; |
| 5792 | int mAnimLayer; |
| 5793 | int mLastLayer; |
| 5794 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 5795 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 5796 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5798 | int mLayoutSeq = -1; |
| 5799 | |
| 5800 | Configuration mConfiguration = null; |
| 5801 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5802 | // Actual frame shown on-screen (may be modified by animation) |
| 5803 | final Rect mShownFrame = new Rect(); |
| 5804 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5805 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5806 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 5807 | * Set when we have changed the size of the surface, to know that |
| 5808 | * we must tell them application to resize (and thus redraw itself). |
| 5809 | */ |
| 5810 | boolean mSurfaceResized; |
| 5811 | |
| 5812 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5813 | * Insets that determine the actually visible area |
| 5814 | */ |
| 5815 | final Rect mVisibleInsets = new Rect(); |
| 5816 | final Rect mLastVisibleInsets = new Rect(); |
| 5817 | boolean mVisibleInsetsChanged; |
| 5818 | |
| 5819 | /** |
| 5820 | * Insets that are covered by system windows |
| 5821 | */ |
| 5822 | final Rect mContentInsets = new Rect(); |
| 5823 | final Rect mLastContentInsets = new Rect(); |
| 5824 | boolean mContentInsetsChanged; |
| 5825 | |
| 5826 | /** |
| 5827 | * Set to true if we are waiting for this window to receive its |
| 5828 | * given internal insets before laying out other windows based on it. |
| 5829 | */ |
| 5830 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5831 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5832 | /** |
| 5833 | * These are the content insets that were given during layout for |
| 5834 | * this window, to be applied to windows behind it. |
| 5835 | */ |
| 5836 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5838 | /** |
| 5839 | * These are the visible insets that were given during layout for |
| 5840 | * this window, to be applied to windows behind it. |
| 5841 | */ |
| 5842 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5843 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5844 | /** |
| 5845 | * Flag indicating whether the touchable region should be adjusted by |
| 5846 | * the visible insets; if false the area outside the visible insets is |
| 5847 | * NOT touchable, so we must use those to adjust the frame during hit |
| 5848 | * tests. |
| 5849 | */ |
| 5850 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5851 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5852 | // Current transformation being applied. |
| 5853 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 5854 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 5855 | float mHScale=1, mVScale=1; |
| 5856 | float mLastHScale=1, mLastVScale=1; |
| 5857 | final Matrix mTmpMatrix = new Matrix(); |
| 5858 | |
| 5859 | // "Real" frame that the application sees. |
| 5860 | final Rect mFrame = new Rect(); |
| 5861 | final Rect mLastFrame = new Rect(); |
| 5862 | |
| 5863 | final Rect mContainingFrame = new Rect(); |
| 5864 | final Rect mDisplayFrame = new Rect(); |
| 5865 | final Rect mContentFrame = new Rect(); |
| 5866 | final Rect mVisibleFrame = new Rect(); |
| 5867 | |
| 5868 | float mShownAlpha = 1; |
| 5869 | float mAlpha = 1; |
| 5870 | float mLastAlpha = 1; |
| 5871 | |
| 5872 | // Set to true if, when the window gets displayed, it should perform |
| 5873 | // an enter animation. |
| 5874 | boolean mEnterAnimationPending; |
| 5875 | |
| 5876 | // Currently running animation. |
| 5877 | boolean mAnimating; |
| 5878 | boolean mLocalAnimating; |
| 5879 | Animation mAnimation; |
| 5880 | boolean mAnimationIsEntrance; |
| 5881 | boolean mHasTransformation; |
| 5882 | boolean mHasLocalTransformation; |
| 5883 | final Transformation mTransformation = new Transformation(); |
| 5884 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5885 | // If a window showing a wallpaper: the requested offset for the |
| 5886 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 5887 | float mWallpaperX = -1; |
| 5888 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5889 | |
| 5890 | // If a window showing a wallpaper: what fraction of the offset |
| 5891 | // range corresponds to a full virtual screen. |
| 5892 | float mWallpaperXStep = -1; |
| 5893 | float mWallpaperYStep = -1; |
| 5894 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5895 | // Wallpaper windows: pixels offset based on above variables. |
| 5896 | int mXOffset; |
| 5897 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5898 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | // This is set after IWindowSession.relayout() has been called at |
| 5900 | // least once for the window. It allows us to detect the situation |
| 5901 | // where we don't yet have a surface, but should have one soon, so |
| 5902 | // we can give the window focus before waiting for the relayout. |
| 5903 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5904 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5905 | // This is set after the Surface has been created but before the |
| 5906 | // window has been drawn. During this time the surface is hidden. |
| 5907 | boolean mDrawPending; |
| 5908 | |
| 5909 | // This is set after the window has finished drawing for the first |
| 5910 | // time but before its surface is shown. The surface will be |
| 5911 | // displayed when the next layout is run. |
| 5912 | boolean mCommitDrawPending; |
| 5913 | |
| 5914 | // This is set during the time after the window's drawing has been |
| 5915 | // committed, and before its surface is actually shown. It is used |
| 5916 | // to delay showing the surface until all windows in a token are ready |
| 5917 | // to be shown. |
| 5918 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5920 | // Set when the window has been shown in the screen the first time. |
| 5921 | boolean mHasDrawn; |
| 5922 | |
| 5923 | // Currently running an exit animation? |
| 5924 | boolean mExiting; |
| 5925 | |
| 5926 | // Currently on the mDestroySurface list? |
| 5927 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5929 | // Completely remove from window manager after exit animation? |
| 5930 | boolean mRemoveOnExit; |
| 5931 | |
| 5932 | // Set when the orientation is changing and this window has not yet |
| 5933 | // been updated for the new orientation. |
| 5934 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5935 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5936 | // Is this window now (or just being) removed? |
| 5937 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5938 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 5939 | // For debugging, this is the last information given to the surface flinger. |
| 5940 | boolean mSurfaceShown; |
| 5941 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 5942 | int mSurfaceLayer; |
| 5943 | float mSurfaceAlpha; |
| 5944 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5945 | // Input channel |
| 5946 | InputChannel mInputChannel; |
| 5947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | WindowState(Session s, IWindow c, WindowToken token, |
| 5949 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 5950 | int viewVisibility) { |
| 5951 | mSession = s; |
| 5952 | mClient = c; |
| 5953 | mToken = token; |
| 5954 | mAttrs.copyFrom(a); |
| 5955 | mViewVisibility = viewVisibility; |
| 5956 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 5957 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5958 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5959 | TAG, "Window " + this + " client=" + c.asBinder() |
| 5960 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 5961 | try { |
| 5962 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 5963 | } catch (RemoteException e) { |
| 5964 | mDeathRecipient = null; |
| 5965 | mAttachedWindow = null; |
| 5966 | mLayoutAttached = false; |
| 5967 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5968 | mIsWallpaper = false; |
| 5969 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | mBaseLayer = 0; |
| 5971 | mSubLayer = 0; |
| 5972 | return; |
| 5973 | } |
| 5974 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5976 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 5977 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 5978 | // The multiplier here is to reserve space for multiple |
| 5979 | // windows in the same type layer. |
| 5980 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 5981 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 5982 | + TYPE_LAYER_OFFSET; |
| 5983 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 5984 | mAttachedWindow = attachedWindow; |
| 5985 | mAttachedWindow.mChildWindows.add(this); |
| 5986 | mLayoutAttached = mAttrs.type != |
| 5987 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 5988 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 5989 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5990 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 5991 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | } else { |
| 5993 | // The multiplier here is to reserve space for multiple |
| 5994 | // windows in the same type layer. |
| 5995 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 5996 | * TYPE_LAYER_MULTIPLIER |
| 5997 | + TYPE_LAYER_OFFSET; |
| 5998 | mSubLayer = 0; |
| 5999 | mAttachedWindow = null; |
| 6000 | mLayoutAttached = false; |
| 6001 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6002 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6003 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6004 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6005 | } |
| 6006 | |
| 6007 | WindowState appWin = this; |
| 6008 | while (appWin.mAttachedWindow != null) { |
| 6009 | appWin = mAttachedWindow; |
| 6010 | } |
| 6011 | WindowToken appToken = appWin.mToken; |
| 6012 | while (appToken.appWindowToken == null) { |
| 6013 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6014 | if (parent == null || appToken == parent) { |
| 6015 | break; |
| 6016 | } |
| 6017 | appToken = parent; |
| 6018 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6019 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6020 | mAppToken = appToken.appWindowToken; |
| 6021 | |
| 6022 | mSurface = null; |
| 6023 | mRequestedWidth = 0; |
| 6024 | mRequestedHeight = 0; |
| 6025 | mLastRequestedWidth = 0; |
| 6026 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6027 | mXOffset = 0; |
| 6028 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6029 | mLayer = 0; |
| 6030 | mAnimLayer = 0; |
| 6031 | mLastLayer = 0; |
| 6032 | } |
| 6033 | |
| 6034 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6035 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | TAG, "Attaching " + this + " token=" + mToken |
| 6037 | + ", list=" + mToken.windows); |
| 6038 | mSession.windowAddedLocked(); |
| 6039 | } |
| 6040 | |
| 6041 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6042 | mHaveFrame = true; |
| 6043 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6044 | final Rect container = mContainingFrame; |
| 6045 | container.set(pf); |
| 6046 | |
| 6047 | final Rect display = mDisplayFrame; |
| 6048 | display.set(df); |
| 6049 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6050 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6051 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6052 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6053 | display.intersect(mCompatibleScreenFrame); |
| 6054 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | final int pw = container.right - container.left; |
| 6058 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6059 | |
| 6060 | int w,h; |
| 6061 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6062 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6063 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6064 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6065 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6066 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6068 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6069 | final Rect content = mContentFrame; |
| 6070 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6071 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6072 | final Rect visible = mVisibleFrame; |
| 6073 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6074 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6075 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6076 | final int fw = frame.width(); |
| 6077 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6079 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6080 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6081 | |
| 6082 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6083 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6084 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6085 | |
| 6086 | //System.out.println("Out: " + mFrame); |
| 6087 | |
| 6088 | // Now make sure the window fits in the overall display. |
| 6089 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6090 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6091 | // Make sure the content and visible frames are inside of the |
| 6092 | // final window frame. |
| 6093 | if (content.left < frame.left) content.left = frame.left; |
| 6094 | if (content.top < frame.top) content.top = frame.top; |
| 6095 | if (content.right > frame.right) content.right = frame.right; |
| 6096 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6097 | if (visible.left < frame.left) visible.left = frame.left; |
| 6098 | if (visible.top < frame.top) visible.top = frame.top; |
| 6099 | if (visible.right > frame.right) visible.right = frame.right; |
| 6100 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6102 | final Rect contentInsets = mContentInsets; |
| 6103 | contentInsets.left = content.left-frame.left; |
| 6104 | contentInsets.top = content.top-frame.top; |
| 6105 | contentInsets.right = frame.right-content.right; |
| 6106 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6107 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6108 | final Rect visibleInsets = mVisibleInsets; |
| 6109 | visibleInsets.left = visible.left-frame.left; |
| 6110 | visibleInsets.top = visible.top-frame.top; |
| 6111 | visibleInsets.right = frame.right-visible.right; |
| 6112 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6113 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6114 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6115 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6116 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6117 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6118 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6119 | if (localLOGV) { |
| 6120 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6121 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6122 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6123 | + mRequestedWidth + ", mRequestedheight=" |
| 6124 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6125 | + "): frame=" + mFrame.toShortString() |
| 6126 | + " ci=" + contentInsets.toShortString() |
| 6127 | + " vi=" + visibleInsets.toShortString()); |
| 6128 | //} |
| 6129 | } |
| 6130 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6131 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6132 | public Rect getFrameLw() { |
| 6133 | return mFrame; |
| 6134 | } |
| 6135 | |
| 6136 | public Rect getShownFrameLw() { |
| 6137 | return mShownFrame; |
| 6138 | } |
| 6139 | |
| 6140 | public Rect getDisplayFrameLw() { |
| 6141 | return mDisplayFrame; |
| 6142 | } |
| 6143 | |
| 6144 | public Rect getContentFrameLw() { |
| 6145 | return mContentFrame; |
| 6146 | } |
| 6147 | |
| 6148 | public Rect getVisibleFrameLw() { |
| 6149 | return mVisibleFrame; |
| 6150 | } |
| 6151 | |
| 6152 | public boolean getGivenInsetsPendingLw() { |
| 6153 | return mGivenInsetsPending; |
| 6154 | } |
| 6155 | |
| 6156 | public Rect getGivenContentInsetsLw() { |
| 6157 | return mGivenContentInsets; |
| 6158 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6160 | public Rect getGivenVisibleInsetsLw() { |
| 6161 | return mGivenVisibleInsets; |
| 6162 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | public WindowManager.LayoutParams getAttrs() { |
| 6165 | return mAttrs; |
| 6166 | } |
| 6167 | |
| 6168 | public int getSurfaceLayer() { |
| 6169 | return mLayer; |
| 6170 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6172 | public IApplicationToken getAppToken() { |
| 6173 | return mAppToken != null ? mAppToken.appToken : null; |
| 6174 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6175 | |
| 6176 | public long getInputDispatchingTimeoutNanos() { |
| 6177 | return mAppToken != null |
| 6178 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6179 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6180 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6181 | |
| 6182 | public boolean hasAppShownWindows() { |
| 6183 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6184 | } |
| 6185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6187 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | TAG, "Setting animation in " + this + ": " + anim); |
| 6189 | mAnimating = false; |
| 6190 | mLocalAnimating = false; |
| 6191 | mAnimation = anim; |
| 6192 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6193 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6194 | } |
| 6195 | |
| 6196 | public void clearAnimation() { |
| 6197 | if (mAnimation != null) { |
| 6198 | mAnimating = true; |
| 6199 | mLocalAnimating = false; |
| 6200 | mAnimation = null; |
| 6201 | } |
| 6202 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6203 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6204 | Surface createSurfaceLocked() { |
| 6205 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6206 | mReportDestroySurface = false; |
| 6207 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6208 | mDrawPending = true; |
| 6209 | mCommitDrawPending = false; |
| 6210 | mReadyToShow = false; |
| 6211 | if (mAppToken != null) { |
| 6212 | mAppToken.allDrawn = false; |
| 6213 | } |
| 6214 | |
| 6215 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6216 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6217 | flags |= Surface.PUSH_BUFFERS; |
| 6218 | } |
| 6219 | |
| 6220 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6221 | flags |= Surface.SECURE; |
| 6222 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6223 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | TAG, "Creating surface in session " |
| 6225 | + mSession.mSurfaceSession + " window " + this |
| 6226 | + " w=" + mFrame.width() |
| 6227 | + " h=" + mFrame.height() + " format=" |
| 6228 | + mAttrs.format + " flags=" + flags); |
| 6229 | |
| 6230 | int w = mFrame.width(); |
| 6231 | int h = mFrame.height(); |
| 6232 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6233 | // for a scaled surface, we always want the requested |
| 6234 | // size. |
| 6235 | w = mRequestedWidth; |
| 6236 | h = mRequestedHeight; |
| 6237 | } |
| 6238 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6239 | // Something is wrong and SurfaceFlinger will not like this, |
| 6240 | // try to revert to sane values |
| 6241 | if (w <= 0) w = 1; |
| 6242 | if (h <= 0) h = 1; |
| 6243 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6244 | mSurfaceShown = false; |
| 6245 | mSurfaceLayer = 0; |
| 6246 | mSurfaceAlpha = 1; |
| 6247 | mSurfaceX = 0; |
| 6248 | mSurfaceY = 0; |
| 6249 | mSurfaceW = w; |
| 6250 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | try { |
| 6252 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6253 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6254 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6255 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6256 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6257 | + mSurface + " IN SESSION " |
| 6258 | + mSession.mSurfaceSession |
| 6259 | + ": pid=" + mSession.mPid + " format=" |
| 6260 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6261 | + Integer.toHexString(flags) |
| 6262 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6264 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6265 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6266 | return null; |
| 6267 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6268 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6269 | return null; |
| 6270 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6271 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6272 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6273 | TAG, "Got surface: " + mSurface |
| 6274 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6275 | + ", animLayer=" + mAnimLayer); |
| 6276 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6277 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6278 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6279 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6280 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6281 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6282 | } |
| 6283 | Surface.openTransaction(); |
| 6284 | try { |
| 6285 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6286 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6287 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6288 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6289 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6290 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6291 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | mSurface.hide(); |
| 6293 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6294 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6295 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6296 | Surface.SURFACE_DITHER); |
| 6297 | } |
| 6298 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6299 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6300 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6301 | } |
| 6302 | mLastHidden = true; |
| 6303 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6304 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6305 | Surface.closeTransaction(); |
| 6306 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6307 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | TAG, "Created surface " + this); |
| 6309 | } |
| 6310 | return mSurface; |
| 6311 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | void destroySurfaceLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6314 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6315 | mAppToken.startingDisplayed = false; |
| 6316 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6318 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6319 | mDrawPending = false; |
| 6320 | mCommitDrawPending = false; |
| 6321 | mReadyToShow = false; |
| 6322 | |
| 6323 | int i = mChildWindows.size(); |
| 6324 | while (i > 0) { |
| 6325 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6326 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6327 | c.mAttachedHidden = true; |
| 6328 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6329 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6330 | if (mReportDestroySurface) { |
| 6331 | mReportDestroySurface = false; |
| 6332 | mSurfacePendingDestroy = true; |
| 6333 | try { |
| 6334 | mClient.dispatchGetNewSurface(); |
| 6335 | // We'll really destroy on the next time around. |
| 6336 | return; |
| 6337 | } catch (RemoteException e) { |
| 6338 | } |
| 6339 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6340 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6342 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6343 | RuntimeException e = null; |
| 6344 | if (!HIDE_STACK_CRAWLS) { |
| 6345 | e = new RuntimeException(); |
| 6346 | e.fillInStackTrace(); |
| 6347 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6348 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6349 | + mSurface + ", session " + mSession, e); |
| 6350 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6352 | RuntimeException e = null; |
| 6353 | if (!HIDE_STACK_CRAWLS) { |
| 6354 | e = new RuntimeException(); |
| 6355 | e.fillInStackTrace(); |
| 6356 | } |
| 6357 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6358 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6359 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6361 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6362 | + " surface " + mSurface + " session " + mSession |
| 6363 | + ": " + e.toString()); |
| 6364 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6365 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6366 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6368 | } |
| 6369 | } |
| 6370 | |
| 6371 | boolean finishDrawingLocked() { |
| 6372 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6373 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6374 | TAG, "finishDrawingLocked: " + mSurface); |
| 6375 | mCommitDrawPending = true; |
| 6376 | mDrawPending = false; |
| 6377 | return true; |
| 6378 | } |
| 6379 | return false; |
| 6380 | } |
| 6381 | |
| 6382 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6383 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6384 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6385 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6386 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | } |
| 6388 | mCommitDrawPending = false; |
| 6389 | mReadyToShow = true; |
| 6390 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6391 | final AppWindowToken atoken = mAppToken; |
| 6392 | if (atoken == null || atoken.allDrawn || starting) { |
| 6393 | performShowLocked(); |
| 6394 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6395 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6396 | } |
| 6397 | |
| 6398 | // This must be called while inside a transaction. |
| 6399 | boolean performShowLocked() { |
| 6400 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6401 | RuntimeException e = null; |
| 6402 | if (!HIDE_STACK_CRAWLS) { |
| 6403 | e = new RuntimeException(); |
| 6404 | e.fillInStackTrace(); |
| 6405 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6406 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6407 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6408 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6409 | } |
| 6410 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6411 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 6412 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6413 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6414 | + " during animation: policyVis=" + mPolicyVisibility |
| 6415 | + " attHidden=" + mAttachedHidden |
| 6416 | + " tok.hiddenRequested=" |
| 6417 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6418 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6420 | + " animating=" + mAnimating |
| 6421 | + " tok animating=" |
| 6422 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6423 | if (!showSurfaceRobustlyLocked(this)) { |
| 6424 | return false; |
| 6425 | } |
| 6426 | mLastAlpha = -1; |
| 6427 | mHasDrawn = true; |
| 6428 | mLastHidden = false; |
| 6429 | mReadyToShow = false; |
| 6430 | enableScreenIfNeededLocked(); |
| 6431 | |
| 6432 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | int i = mChildWindows.size(); |
| 6435 | while (i > 0) { |
| 6436 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6437 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6438 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6439 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6440 | if (c.mSurface != null) { |
| 6441 | c.performShowLocked(); |
| 6442 | // It hadn't been shown, which means layout not |
| 6443 | // performed on it, so now we want to make sure to |
| 6444 | // do a layout. If called from within the transaction |
| 6445 | // loop, this will cause it to restart with a new |
| 6446 | // layout. |
| 6447 | mLayoutNeeded = true; |
| 6448 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6449 | } |
| 6450 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6453 | && mAppToken != null) { |
| 6454 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6455 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6456 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6457 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6458 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6459 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6460 | // If this initial window is animating, stop it -- we |
| 6461 | // will do an animation to reveal it from behind the |
| 6462 | // starting window, so there is no need for it to also |
| 6463 | // be doing its own stuff. |
| 6464 | if (mAnimation != null) { |
| 6465 | mAnimation = null; |
| 6466 | // Make sure we clean up the animation. |
| 6467 | mAnimating = true; |
| 6468 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6469 | mFinishedStarting.add(mAppToken); |
| 6470 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6471 | } |
| 6472 | mAppToken.updateReportedVisibilityLocked(); |
| 6473 | } |
| 6474 | } |
| 6475 | return true; |
| 6476 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6477 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6478 | // This must be called while inside a transaction. Returns true if |
| 6479 | // there is more animation to run. |
| 6480 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6481 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6484 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6485 | mHasTransformation = true; |
| 6486 | mHasLocalTransformation = true; |
| 6487 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6488 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6489 | TAG, "Starting animation in " + this + |
| 6490 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6491 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6492 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6493 | mAnimation.setStartTime(currentTime); |
| 6494 | mLocalAnimating = true; |
| 6495 | mAnimating = true; |
| 6496 | } |
| 6497 | mTransformation.clear(); |
| 6498 | final boolean more = mAnimation.getTransformation( |
| 6499 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6500 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6501 | TAG, "Stepped animation in " + this + |
| 6502 | ": more=" + more + ", xform=" + mTransformation); |
| 6503 | if (more) { |
| 6504 | // we're not done! |
| 6505 | return true; |
| 6506 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6507 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | TAG, "Finished animation in " + this + |
| 6509 | " @ " + currentTime); |
| 6510 | mAnimation = null; |
| 6511 | //WindowManagerService.this.dump(); |
| 6512 | } |
| 6513 | mHasLocalTransformation = false; |
| 6514 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6515 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6516 | // When our app token is animating, we kind-of pretend like |
| 6517 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6518 | // part of this check means that we will only do this if |
| 6519 | // our window is not currently exiting, or it is not |
| 6520 | // locally animating itself. The idea being that one that |
| 6521 | // is exiting and doing a local animation should be removed |
| 6522 | // once that animation is done. |
| 6523 | mAnimating = true; |
| 6524 | mHasTransformation = true; |
| 6525 | mTransformation.clear(); |
| 6526 | return false; |
| 6527 | } else if (mHasTransformation) { |
| 6528 | // Little trick to get through the path below to act like |
| 6529 | // we have finished an animation. |
| 6530 | mAnimating = true; |
| 6531 | } else if (isAnimating()) { |
| 6532 | mAnimating = true; |
| 6533 | } |
| 6534 | } else if (mAnimation != null) { |
| 6535 | // If the display is frozen, and there is a pending animation, |
| 6536 | // clear it and make sure we run the cleanup code. |
| 6537 | mAnimating = true; |
| 6538 | mLocalAnimating = true; |
| 6539 | mAnimation = null; |
| 6540 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6541 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6542 | if (!mAnimating && !mLocalAnimating) { |
| 6543 | return false; |
| 6544 | } |
| 6545 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6546 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6547 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6548 | + ", reportedVisible=" |
| 6549 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6550 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6551 | mAnimating = false; |
| 6552 | mLocalAnimating = false; |
| 6553 | mAnimation = null; |
| 6554 | mAnimLayer = mLayer; |
| 6555 | if (mIsImWindow) { |
| 6556 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6557 | } else if (mIsWallpaper) { |
| 6558 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6559 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6560 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6561 | + " anim layer: " + mAnimLayer); |
| 6562 | mHasTransformation = false; |
| 6563 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6564 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 6565 | if (DEBUG_VISIBILITY) { |
| 6566 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 6567 | + mPolicyVisibilityAfterAnim); |
| 6568 | } |
| 6569 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6570 | if (!mPolicyVisibility) { |
| 6571 | if (mCurrentFocus == this) { |
| 6572 | mFocusMayChange = true; |
| 6573 | } |
| 6574 | // Window is no longer visible -- make sure if we were waiting |
| 6575 | // for it to be displayed before enabling the display, that |
| 6576 | // we allow the display to be enabled now. |
| 6577 | enableScreenIfNeededLocked(); |
| 6578 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 6579 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6580 | mTransformation.clear(); |
| 6581 | if (mHasDrawn |
| 6582 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6583 | && mAppToken != null |
| 6584 | && mAppToken.firstWindowDrawn |
| 6585 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6586 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6587 | + mToken + ": first real window done animating"); |
| 6588 | mFinishedStarting.add(mAppToken); |
| 6589 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6590 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6592 | finishExit(); |
| 6593 | |
| 6594 | if (mAppToken != null) { |
| 6595 | mAppToken.updateReportedVisibilityLocked(); |
| 6596 | } |
| 6597 | |
| 6598 | return false; |
| 6599 | } |
| 6600 | |
| 6601 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6602 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | TAG, "finishExit in " + this |
| 6604 | + ": exiting=" + mExiting |
| 6605 | + " remove=" + mRemoveOnExit |
| 6606 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6608 | final int N = mChildWindows.size(); |
| 6609 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6610 | mChildWindows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6611 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6612 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6613 | if (!mExiting) { |
| 6614 | return; |
| 6615 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6616 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6617 | if (isWindowAnimating()) { |
| 6618 | return; |
| 6619 | } |
| 6620 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6621 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6622 | TAG, "Exit animation finished in " + this |
| 6623 | + ": remove=" + mRemoveOnExit); |
| 6624 | if (mSurface != null) { |
| 6625 | mDestroySurface.add(this); |
| 6626 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6627 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6628 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6629 | try { |
| 6630 | mSurface.hide(); |
| 6631 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6632 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | } |
| 6634 | mLastHidden = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6635 | } |
| 6636 | mExiting = false; |
| 6637 | if (mRemoveOnExit) { |
| 6638 | mPendingRemove.add(this); |
| 6639 | mRemoveOnExit = false; |
| 6640 | } |
| 6641 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6642 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6643 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 6644 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 6645 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 6646 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 6647 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 6648 | return true; |
| 6649 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6650 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6651 | void computeShownFrameLocked() { |
| 6652 | final boolean selfTransformation = mHasLocalTransformation; |
| 6653 | Transformation attachedTransformation = |
| 6654 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 6655 | ? mAttachedWindow.mTransformation : null; |
| 6656 | Transformation appTransformation = |
| 6657 | (mAppToken != null && mAppToken.hasTransformation) |
| 6658 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6659 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6660 | // Wallpapers are animated based on the "real" window they |
| 6661 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6662 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 6663 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6664 | if (mWallpaperTarget.mHasLocalTransformation && |
| 6665 | mWallpaperTarget.mAnimation != null && |
| 6666 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6667 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6668 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6669 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6670 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6671 | } |
| 6672 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6673 | mWallpaperTarget.mAppToken.hasTransformation && |
| 6674 | mWallpaperTarget.mAppToken.animation != null && |
| 6675 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6676 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6677 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6678 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6679 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6680 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6681 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6682 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6683 | if (selfTransformation || attachedTransformation != null |
| 6684 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6685 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6686 | final Rect frame = mFrame; |
| 6687 | final float tmpFloats[] = mTmpFloats; |
| 6688 | final Matrix tmpMatrix = mTmpMatrix; |
| 6689 | |
| 6690 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6691 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6692 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6693 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6694 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6695 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6696 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6697 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6698 | } |
| 6699 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6700 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6701 | } |
| 6702 | |
| 6703 | // "convert" it into SurfaceFlinger's format |
| 6704 | // (a 2x2 matrix + an offset) |
| 6705 | // Here we must not transform the position of the surface |
| 6706 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6707 | //Slog.i(TAG, "Transform: " + matrix); |
| 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 | tmpMatrix.getValues(tmpFloats); |
| 6710 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 6711 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 6712 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 6713 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6714 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 6715 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6716 | int w = frame.width(); |
| 6717 | int h = frame.height(); |
| 6718 | mShownFrame.set(x, y, x+w, y+h); |
| 6719 | |
| 6720 | // Now set the alpha... but because our current hardware |
| 6721 | // can't do alpha transformation on a non-opaque surface, |
| 6722 | // turn it off if we are running an animation that is also |
| 6723 | // transforming since it is more important to have that |
| 6724 | // animation be smooth. |
| 6725 | mShownAlpha = mAlpha; |
| 6726 | if (!mLimitedAlphaCompositing |
| 6727 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 6728 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 6729 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6730 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6731 | if (selfTransformation) { |
| 6732 | mShownAlpha *= mTransformation.getAlpha(); |
| 6733 | } |
| 6734 | if (attachedTransformation != null) { |
| 6735 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 6736 | } |
| 6737 | if (appTransformation != null) { |
| 6738 | mShownAlpha *= appTransformation.getAlpha(); |
| 6739 | } |
| 6740 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6741 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6742 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6743 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6744 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6745 | TAG, "Continuing animation in " + this + |
| 6746 | ": " + mShownFrame + |
| 6747 | ", alpha=" + mTransformation.getAlpha()); |
| 6748 | return; |
| 6749 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6750 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6751 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6752 | if (mXOffset != 0 || mYOffset != 0) { |
| 6753 | mShownFrame.offset(mXOffset, mYOffset); |
| 6754 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6755 | mShownAlpha = mAlpha; |
| 6756 | mDsDx = 1; |
| 6757 | mDtDx = 0; |
| 6758 | mDsDy = 0; |
| 6759 | mDtDy = 1; |
| 6760 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6762 | /** |
| 6763 | * Is this window visible? It is not visible if there is no |
| 6764 | * surface, or we are in the process of running an exit animation |
| 6765 | * that will remove the surface, or its app token has been hidden. |
| 6766 | */ |
| 6767 | public boolean isVisibleLw() { |
| 6768 | final AppWindowToken atoken = mAppToken; |
| 6769 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6770 | && (atoken == null || !atoken.hiddenRequested) |
| 6771 | && !mExiting && !mDestroying; |
| 6772 | } |
| 6773 | |
| 6774 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6775 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 6776 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 6777 | * things like window flags that impact the keyguard. |
| 6778 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 6779 | * for this "hidden behind keyguard" state rather than overloading |
| 6780 | * mPolicyVisibility. Ungh. |
| 6781 | */ |
| 6782 | public boolean isVisibleOrBehindKeyguardLw() { |
| 6783 | final AppWindowToken atoken = mAppToken; |
| 6784 | return mSurface != null && !mAttachedHidden |
| 6785 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6786 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6787 | && !mExiting && !mDestroying; |
| 6788 | } |
| 6789 | |
| 6790 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | * Is this window visible, ignoring its app token? It is not visible |
| 6792 | * if there is no surface, or we are in the process of running an exit animation |
| 6793 | * that will remove the surface. |
| 6794 | */ |
| 6795 | public boolean isWinVisibleLw() { |
| 6796 | final AppWindowToken atoken = mAppToken; |
| 6797 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6798 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 6799 | && !mExiting && !mDestroying; |
| 6800 | } |
| 6801 | |
| 6802 | /** |
| 6803 | * The same as isVisible(), but follows the current hidden state of |
| 6804 | * the associated app token, not the pending requested hidden state. |
| 6805 | */ |
| 6806 | boolean isVisibleNow() { |
| 6807 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6808 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6809 | } |
| 6810 | |
| 6811 | /** |
| 6812 | * Same as isVisible(), but we also count it as visible between the |
| 6813 | * call to IWindowSession.add() and the first relayout(). |
| 6814 | */ |
| 6815 | boolean isVisibleOrAdding() { |
| 6816 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6817 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6818 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 6819 | && mPolicyVisibility && !mAttachedHidden |
| 6820 | && (atoken == null || !atoken.hiddenRequested) |
| 6821 | && !mExiting && !mDestroying; |
| 6822 | } |
| 6823 | |
| 6824 | /** |
| 6825 | * Is this window currently on-screen? It is on-screen either if it |
| 6826 | * is visible or it is currently running an animation before no longer |
| 6827 | * being visible. |
| 6828 | */ |
| 6829 | boolean isOnScreen() { |
| 6830 | final AppWindowToken atoken = mAppToken; |
| 6831 | if (atoken != null) { |
| 6832 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6833 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6834 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6835 | } else { |
| 6836 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6837 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6838 | } |
| 6839 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6840 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6841 | /** |
| 6842 | * Like isOnScreen(), but we don't return true if the window is part |
| 6843 | * of a transition that has not yet been started. |
| 6844 | */ |
| 6845 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6846 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 6847 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6848 | return false; |
| 6849 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6851 | final boolean animating = atoken != null |
| 6852 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6853 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6854 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 6855 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6856 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | /** Is the window or its container currently animating? */ |
| 6860 | boolean isAnimating() { |
| 6861 | final WindowState attached = mAttachedWindow; |
| 6862 | final AppWindowToken atoken = mAppToken; |
| 6863 | return mAnimation != null |
| 6864 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6865 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | (atoken.animation != null |
| 6867 | || atoken.inPendingTransaction)); |
| 6868 | } |
| 6869 | |
| 6870 | /** Is this window currently animating? */ |
| 6871 | boolean isWindowAnimating() { |
| 6872 | return mAnimation != null; |
| 6873 | } |
| 6874 | |
| 6875 | /** |
| 6876 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 6877 | * been drawn. |
| 6878 | */ |
| 6879 | public boolean isDisplayedLw() { |
| 6880 | final AppWindowToken atoken = mAppToken; |
| 6881 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6882 | && !mDrawPending && !mCommitDrawPending |
| 6883 | && ((!mAttachedHidden && |
| 6884 | (atoken == null || !atoken.hiddenRequested)) |
| 6885 | || mAnimating); |
| 6886 | } |
| 6887 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6888 | /** |
| 6889 | * Returns true if the window has a surface that it has drawn a |
| 6890 | * complete UI in to. |
| 6891 | */ |
| 6892 | public boolean isDrawnLw() { |
| 6893 | final AppWindowToken atoken = mAppToken; |
| 6894 | return mSurface != null && !mDestroying |
| 6895 | && !mDrawPending && !mCommitDrawPending; |
| 6896 | } |
| 6897 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6898 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 6899 | boolean shownFrame, boolean onlyOpaque) { |
| 6900 | if (mSurface == null) { |
| 6901 | return false; |
| 6902 | } |
| 6903 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 6904 | return false; |
| 6905 | } |
| 6906 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 6907 | return false; |
| 6908 | } |
| 6909 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6910 | |
| 6911 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 6912 | return frame.left <= mCompatibleScreenFrame.left && |
| 6913 | frame.top <= mCompatibleScreenFrame.top && |
| 6914 | frame.right >= mCompatibleScreenFrame.right && |
| 6915 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 6916 | } else { |
| 6917 | return frame.left <= 0 && frame.top <= 0 |
| 6918 | && frame.right >= screenWidth |
| 6919 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6920 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6921 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6922 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6923 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 6924 | * Return true if the window is opaque and fully drawn. This indicates |
| 6925 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6926 | */ |
| 6927 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 6928 | return (mAttrs.format == PixelFormat.OPAQUE |
| 6929 | || mAttrs.type == TYPE_WALLPAPER) |
| 6930 | && mSurface != null && mAnimation == null |
| 6931 | && (mAppToken == null || mAppToken.animation == null) |
| 6932 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6933 | } |
| 6934 | |
| 6935 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 6936 | return |
| 6937 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6938 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 6939 | // only if it's visible |
| 6940 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6941 | // and only if the application fills the compatible screen |
| 6942 | mFrame.left <= mCompatibleScreenFrame.left && |
| 6943 | mFrame.top <= mCompatibleScreenFrame.top && |
| 6944 | mFrame.right >= mCompatibleScreenFrame.right && |
| 6945 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6946 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6947 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6948 | } |
| 6949 | |
| 6950 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 6951 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6952 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | } |
| 6954 | |
| 6955 | void removeLocked() { |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6956 | disposeInputChannel(); |
| 6957 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6958 | if (mAttachedWindow != null) { |
| 6959 | mAttachedWindow.mChildWindows.remove(this); |
| 6960 | } |
| 6961 | destroySurfaceLocked(); |
| 6962 | mSession.windowRemovedLocked(); |
| 6963 | try { |
| 6964 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 6965 | } catch (RuntimeException e) { |
| 6966 | // Ignore if it has already been removed (usually because |
| 6967 | // we are doing this as part of processing a death note.) |
| 6968 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6969 | } |
| 6970 | |
| 6971 | void disposeInputChannel() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6972 | if (mInputChannel != null) { |
| 6973 | mInputManager.unregisterInputChannel(mInputChannel); |
| 6974 | |
| 6975 | mInputChannel.dispose(); |
| 6976 | mInputChannel = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6977 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | } |
| 6979 | |
| 6980 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 6981 | public void binderDied() { |
| 6982 | try { |
| 6983 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6984 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6985 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6986 | if (win != null) { |
| 6987 | removeWindowLocked(mSession, win); |
| 6988 | } |
| 6989 | } |
| 6990 | } catch (IllegalArgumentException ex) { |
| 6991 | // This will happen if the window has already been |
| 6992 | // removed. |
| 6993 | } |
| 6994 | } |
| 6995 | } |
| 6996 | |
| 6997 | /** Returns true if this window desires key events. */ |
| 6998 | public final boolean canReceiveKeys() { |
| 6999 | return isVisibleOrAdding() |
| 7000 | && (mViewVisibility == View.VISIBLE) |
| 7001 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7002 | } |
| 7003 | |
| 7004 | public boolean hasDrawnLw() { |
| 7005 | return mHasDrawn; |
| 7006 | } |
| 7007 | |
| 7008 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7009 | return showLw(doAnimation, true); |
| 7010 | } |
| 7011 | |
| 7012 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7013 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7014 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7015 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7016 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7017 | if (doAnimation) { |
| 7018 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7019 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7020 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7021 | doAnimation = false; |
| 7022 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7023 | // Check for the case where we are currently visible and |
| 7024 | // not animating; we do not want to do animation at such a |
| 7025 | // point to become visible when we already are. |
| 7026 | doAnimation = false; |
| 7027 | } |
| 7028 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7029 | mPolicyVisibility = true; |
| 7030 | mPolicyVisibilityAfterAnim = true; |
| 7031 | if (doAnimation) { |
| 7032 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7033 | } |
| 7034 | if (requestAnim) { |
| 7035 | requestAnimationLocked(0); |
| 7036 | } |
| 7037 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7038 | } |
| 7039 | |
| 7040 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7041 | return hideLw(doAnimation, true); |
| 7042 | } |
| 7043 | |
| 7044 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7045 | if (doAnimation) { |
| 7046 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7047 | doAnimation = false; |
| 7048 | } |
| 7049 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7050 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7051 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7052 | if (!current) { |
| 7053 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7054 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7055 | if (doAnimation) { |
| 7056 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7057 | if (mAnimation == null) { |
| 7058 | doAnimation = false; |
| 7059 | } |
| 7060 | } |
| 7061 | if (doAnimation) { |
| 7062 | mPolicyVisibilityAfterAnim = false; |
| 7063 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7064 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7065 | mPolicyVisibilityAfterAnim = false; |
| 7066 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7067 | // Window is no longer visible -- make sure if we were waiting |
| 7068 | // for it to be displayed before enabling the display, that |
| 7069 | // we allow the display to be enabled now. |
| 7070 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7071 | if (mCurrentFocus == this) { |
| 7072 | mFocusMayChange = true; |
| 7073 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7074 | } |
| 7075 | if (requestAnim) { |
| 7076 | requestAnimationLocked(0); |
| 7077 | } |
| 7078 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7079 | } |
| 7080 | |
| 7081 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7082 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7083 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7084 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7085 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7086 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7087 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7088 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7089 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7090 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7091 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7092 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7093 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7094 | } |
| 7095 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7096 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7097 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7098 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7099 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7100 | pw.print("="); pw.print(mAnimLayer); |
| 7101 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7102 | if (mSurface != null) { |
| 7103 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7104 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7105 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7106 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7107 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7108 | pw.print(","); pw.print(mSurfaceY); |
| 7109 | pw.print(") "); pw.print(mSurfaceW); |
| 7110 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7111 | } |
| 7112 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7113 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7114 | if (mAppToken != null) { |
| 7115 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7116 | } |
| 7117 | if (mTargetAppToken != null) { |
| 7118 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7119 | } |
| 7120 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7121 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7122 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7123 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7124 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7125 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7126 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7127 | pw.print(mPolicyVisibility); |
| 7128 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7129 | pw.print(mPolicyVisibilityAfterAnim); |
| 7130 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7131 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7132 | if (!mRelayoutCalled) { |
| 7133 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7134 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7135 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7136 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7137 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7138 | if (mXOffset != 0 || mYOffset != 0) { |
| 7139 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7140 | pw.print(" y="); pw.println(mYOffset); |
| 7141 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7142 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7143 | mGivenContentInsets.printShortString(pw); |
| 7144 | pw.print(" mGivenVisibleInsets="); |
| 7145 | mGivenVisibleInsets.printShortString(pw); |
| 7146 | pw.println(); |
| 7147 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7148 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7149 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7150 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7151 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7152 | pw.print(prefix); pw.print("mShownFrame="); |
| 7153 | mShownFrame.printShortString(pw); |
| 7154 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7155 | pw.println(); |
| 7156 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7157 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7158 | pw.println(); |
| 7159 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7160 | mContainingFrame.printShortString(pw); |
| 7161 | pw.print(" mDisplayFrame="); |
| 7162 | mDisplayFrame.printShortString(pw); |
| 7163 | pw.println(); |
| 7164 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7165 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7166 | pw.println(); |
| 7167 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7168 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7169 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7170 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7171 | pw.println(); |
| 7172 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7173 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7174 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7175 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7176 | } |
| 7177 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7178 | || mAnimation != null) { |
| 7179 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7180 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7181 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7182 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7183 | } |
| 7184 | if (mHasTransformation || mHasLocalTransformation) { |
| 7185 | pw.print(prefix); pw.print("XForm: has="); |
| 7186 | pw.print(mHasTransformation); |
| 7187 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7188 | pw.print(" "); mTransformation.printShortString(pw); |
| 7189 | pw.println(); |
| 7190 | } |
| 7191 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7192 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7193 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7194 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7195 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7196 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7197 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7198 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7199 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7200 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7201 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7202 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7203 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7204 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7205 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7206 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7207 | if (mHScale != 1 || mVScale != 1) { |
| 7208 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7209 | pw.print(" mVScale="); pw.println(mVScale); |
| 7210 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7211 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7212 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7213 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7214 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7215 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7216 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7217 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7218 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7219 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7220 | |
| 7221 | String makeInputChannelName() { |
| 7222 | return Integer.toHexString(System.identityHashCode(this)) |
| 7223 | + " " + mAttrs.getTitle(); |
| 7224 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7225 | |
| 7226 | @Override |
| 7227 | public String toString() { |
| 7228 | return "Window{" |
| 7229 | + Integer.toHexString(System.identityHashCode(this)) |
| 7230 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7231 | } |
| 7232 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7233 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7234 | // ------------------------------------------------------------- |
| 7235 | // Window Token State |
| 7236 | // ------------------------------------------------------------- |
| 7237 | |
| 7238 | class WindowToken { |
| 7239 | // The actual token. |
| 7240 | final IBinder token; |
| 7241 | |
| 7242 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7243 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | // Set if this token was explicitly added by a client, so should |
| 7246 | // not be removed when all windows are removed. |
| 7247 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7248 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7249 | // For printing. |
| 7250 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | // If this is an AppWindowToken, this is non-null. |
| 7253 | AppWindowToken appWindowToken; |
| 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 | // All of the windows associated with this token. |
| 7256 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7257 | |
| 7258 | // Is key dispatching paused for this token? |
| 7259 | boolean paused = false; |
| 7260 | |
| 7261 | // Should this token's windows be hidden? |
| 7262 | boolean hidden; |
| 7263 | |
| 7264 | // Temporary for finding which tokens no longer have visible windows. |
| 7265 | boolean hasVisible; |
| 7266 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7267 | // Set to true when this token is in a pending transaction where it |
| 7268 | // will be shown. |
| 7269 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7270 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7271 | // Set to true when this token is in a pending transaction where it |
| 7272 | // will be hidden. |
| 7273 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7274 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7275 | // Set to true when this token is in a pending transaction where its |
| 7276 | // windows will be put to the bottom of the list. |
| 7277 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7278 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7279 | // Set to true when this token is in a pending transaction where its |
| 7280 | // windows will be put to the top of the list. |
| 7281 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7283 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7284 | token = _token; |
| 7285 | windowType = type; |
| 7286 | explicit = _explicit; |
| 7287 | } |
| 7288 | |
| 7289 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7290 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7291 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7292 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7293 | pw.print(" hidden="); pw.print(hidden); |
| 7294 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7295 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7296 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7297 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7298 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7299 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7300 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7301 | } |
| 7302 | |
| 7303 | @Override |
| 7304 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7305 | if (stringName == null) { |
| 7306 | StringBuilder sb = new StringBuilder(); |
| 7307 | sb.append("WindowToken{"); |
| 7308 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7309 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7310 | stringName = sb.toString(); |
| 7311 | } |
| 7312 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7313 | } |
| 7314 | }; |
| 7315 | |
| 7316 | class AppWindowToken extends WindowToken { |
| 7317 | // Non-null only for application tokens. |
| 7318 | final IApplicationToken appToken; |
| 7319 | |
| 7320 | // All of the windows and child windows that are included in this |
| 7321 | // application token. Note this list is NOT sorted! |
| 7322 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7323 | |
| 7324 | int groupId = -1; |
| 7325 | boolean appFullscreen; |
| 7326 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7327 | |
| 7328 | // The input dispatching timeout for this application token in nanoseconds. |
| 7329 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7330 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7331 | // These are used for determining when all windows associated with |
| 7332 | // an activity have been drawn, so they can be made visible together |
| 7333 | // at the same time. |
| 7334 | int lastTransactionSequence = mTransactionSequence-1; |
| 7335 | int numInterestingWindows; |
| 7336 | int numDrawnWindows; |
| 7337 | boolean inPendingTransaction; |
| 7338 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7340 | // Is this token going to be hidden in a little while? If so, it |
| 7341 | // won't be taken into account for setting the screen orientation. |
| 7342 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | // Is this window's surface needed? This is almost like hidden, except |
| 7345 | // it will sometimes be true a little earlier: when the token has |
| 7346 | // been shown, but is still waiting for its app transition to execute |
| 7347 | // before making its windows shown. |
| 7348 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | // Have we told the window clients to hide themselves? |
| 7351 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7352 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7353 | // Last visibility state we reported to the app token. |
| 7354 | boolean reportedVisible; |
| 7355 | |
| 7356 | // Set to true when the token has been removed from the window mgr. |
| 7357 | boolean removed; |
| 7358 | |
| 7359 | // Have we been asked to have this token keep the screen frozen? |
| 7360 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7361 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7362 | boolean animating; |
| 7363 | Animation animation; |
| 7364 | boolean hasTransformation; |
| 7365 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7366 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | // Offset to the window of all layers in the token, for use by |
| 7368 | // AppWindowToken animations. |
| 7369 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7370 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7371 | // Information about an application starting window if displayed. |
| 7372 | StartingData startingData; |
| 7373 | WindowState startingWindow; |
| 7374 | View startingView; |
| 7375 | boolean startingDisplayed; |
| 7376 | boolean startingMoved; |
| 7377 | boolean firstWindowDrawn; |
| 7378 | |
| 7379 | AppWindowToken(IApplicationToken _token) { |
| 7380 | super(_token.asBinder(), |
| 7381 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7382 | appWindowToken = this; |
| 7383 | appToken = _token; |
| 7384 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7386 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7387 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | TAG, "Setting animation in " + this + ": " + anim); |
| 7389 | animation = anim; |
| 7390 | animating = false; |
| 7391 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7392 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7393 | int zorder = anim.getZAdjustment(); |
| 7394 | int adj = 0; |
| 7395 | if (zorder == Animation.ZORDER_TOP) { |
| 7396 | adj = TYPE_LAYER_OFFSET; |
| 7397 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7398 | adj = -TYPE_LAYER_OFFSET; |
| 7399 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7400 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7401 | if (animLayerAdjustment != adj) { |
| 7402 | animLayerAdjustment = adj; |
| 7403 | updateLayers(); |
| 7404 | } |
| 7405 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7406 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7407 | public void setDummyAnimation() { |
| 7408 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7409 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7410 | TAG, "Setting dummy animation in " + this); |
| 7411 | animation = sDummyAnimation; |
| 7412 | } |
| 7413 | } |
| 7414 | |
| 7415 | public void clearAnimation() { |
| 7416 | if (animation != null) { |
| 7417 | animation = null; |
| 7418 | animating = true; |
| 7419 | } |
| 7420 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7421 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7422 | void updateLayers() { |
| 7423 | final int N = allAppWindows.size(); |
| 7424 | final int adj = animLayerAdjustment; |
| 7425 | for (int i=0; i<N; i++) { |
| 7426 | WindowState w = allAppWindows.get(i); |
| 7427 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7428 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7429 | + w.mAnimLayer); |
| 7430 | if (w == mInputMethodTarget) { |
| 7431 | setInputMethodAnimLayerAdjustment(adj); |
| 7432 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7433 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7434 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7435 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7436 | } |
| 7437 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7438 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7439 | void sendAppVisibilityToClients() { |
| 7440 | final int N = allAppWindows.size(); |
| 7441 | for (int i=0; i<N; i++) { |
| 7442 | WindowState win = allAppWindows.get(i); |
| 7443 | if (win == startingWindow && clientHidden) { |
| 7444 | // Don't hide the starting window. |
| 7445 | continue; |
| 7446 | } |
| 7447 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7448 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7449 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 7450 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 7451 | } catch (RemoteException e) { |
| 7452 | } |
| 7453 | } |
| 7454 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7456 | void showAllWindowsLocked() { |
| 7457 | final int NW = allAppWindows.size(); |
| 7458 | for (int i=0; i<NW; i++) { |
| 7459 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7460 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7461 | "performing show on: " + w); |
| 7462 | w.performShowLocked(); |
| 7463 | } |
| 7464 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7466 | // This must be called while inside a transaction. |
| 7467 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7468 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7469 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7471 | if (animation == sDummyAnimation) { |
| 7472 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7473 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7474 | // when it is really time to animate, this will be set to |
| 7475 | // a real animation and the next call will execute normally. |
| 7476 | return false; |
| 7477 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7478 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7479 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7480 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7481 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7482 | TAG, "Starting animation in " + this + |
| 7483 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7484 | + " scale=" + mTransitionAnimationScale |
| 7485 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7486 | animation.initialize(dw, dh, dw, dh); |
| 7487 | animation.setStartTime(currentTime); |
| 7488 | animating = true; |
| 7489 | } |
| 7490 | transformation.clear(); |
| 7491 | final boolean more = animation.getTransformation( |
| 7492 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7493 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7494 | TAG, "Stepped animation in " + this + |
| 7495 | ": more=" + more + ", xform=" + transformation); |
| 7496 | if (more) { |
| 7497 | // we're done! |
| 7498 | hasTransformation = true; |
| 7499 | return true; |
| 7500 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7501 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7502 | TAG, "Finished animation in " + this + |
| 7503 | " @ " + currentTime); |
| 7504 | animation = null; |
| 7505 | } |
| 7506 | } else if (animation != null) { |
| 7507 | // If the display is frozen, and there is a pending animation, |
| 7508 | // clear it and make sure we run the cleanup code. |
| 7509 | animating = true; |
| 7510 | animation = null; |
| 7511 | } |
| 7512 | |
| 7513 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7514 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7515 | if (!animating) { |
| 7516 | return false; |
| 7517 | } |
| 7518 | |
| 7519 | clearAnimation(); |
| 7520 | animating = false; |
| 7521 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7522 | moveInputMethodWindowsIfNeededLocked(true); |
| 7523 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7524 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7525 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | TAG, "Animation done in " + this |
| 7527 | + ": reportedVisible=" + reportedVisible); |
| 7528 | |
| 7529 | transformation.clear(); |
| 7530 | if (animLayerAdjustment != 0) { |
| 7531 | animLayerAdjustment = 0; |
| 7532 | updateLayers(); |
| 7533 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7535 | final int N = windows.size(); |
| 7536 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7537 | windows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7538 | } |
| 7539 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7540 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7541 | return false; |
| 7542 | } |
| 7543 | |
| 7544 | void updateReportedVisibilityLocked() { |
| 7545 | if (appToken == null) { |
| 7546 | return; |
| 7547 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7548 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7549 | int numInteresting = 0; |
| 7550 | int numVisible = 0; |
| 7551 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7552 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7553 | 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] | 7554 | final int N = allAppWindows.size(); |
| 7555 | for (int i=0; i<N; i++) { |
| 7556 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 7557 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 7558 | || win.mViewVisibility != View.VISIBLE |
| 7559 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | continue; |
| 7561 | } |
| 7562 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7563 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7564 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7566 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7567 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7568 | + " pv=" + win.mPolicyVisibility |
| 7569 | + " dp=" + win.mDrawPending |
| 7570 | + " cdp=" + win.mCommitDrawPending |
| 7571 | + " ah=" + win.mAttachedHidden |
| 7572 | + " th=" |
| 7573 | + (win.mAppToken != null |
| 7574 | ? win.mAppToken.hiddenRequested : false) |
| 7575 | + " a=" + win.mAnimating); |
| 7576 | } |
| 7577 | } |
| 7578 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7579 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7580 | if (!win.isAnimating()) { |
| 7581 | numVisible++; |
| 7582 | } |
| 7583 | nowGone = false; |
| 7584 | } else if (win.isAnimating()) { |
| 7585 | nowGone = false; |
| 7586 | } |
| 7587 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7589 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7590 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7591 | + numInteresting + " visible=" + numVisible); |
| 7592 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7593 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7594 | TAG, "Visibility changed in " + this |
| 7595 | + ": vis=" + nowVisible); |
| 7596 | reportedVisible = nowVisible; |
| 7597 | Message m = mH.obtainMessage( |
| 7598 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7599 | nowVisible ? 1 : 0, |
| 7600 | nowGone ? 1 : 0, |
| 7601 | this); |
| 7602 | mH.sendMessage(m); |
| 7603 | } |
| 7604 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7605 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7606 | WindowState findMainWindow() { |
| 7607 | int j = windows.size(); |
| 7608 | while (j > 0) { |
| 7609 | j--; |
| 7610 | WindowState win = windows.get(j); |
| 7611 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7612 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7613 | return win; |
| 7614 | } |
| 7615 | } |
| 7616 | return null; |
| 7617 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7618 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7619 | void dump(PrintWriter pw, String prefix) { |
| 7620 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7621 | if (appToken != null) { |
| 7622 | pw.print(prefix); pw.println("app=true"); |
| 7623 | } |
| 7624 | if (allAppWindows.size() > 0) { |
| 7625 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7626 | } |
| 7627 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7628 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7629 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7630 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7631 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7632 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7633 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7634 | if (paused || freezingScreen) { |
| 7635 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7636 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7637 | } |
| 7638 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7639 | || inPendingTransaction || allDrawn) { |
| 7640 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7641 | pw.print(numInterestingWindows); |
| 7642 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7643 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7644 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7645 | } |
| 7646 | if (animating || animation != null) { |
| 7647 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7648 | pw.print(" animation="); pw.println(animation); |
| 7649 | } |
| 7650 | if (animLayerAdjustment != 0) { |
| 7651 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7652 | } |
| 7653 | if (hasTransformation) { |
| 7654 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7655 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7656 | pw.println(); |
| 7657 | } |
| 7658 | if (startingData != null || removed || firstWindowDrawn) { |
| 7659 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7660 | pw.print(" removed="); pw.print(removed); |
| 7661 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7662 | } |
| 7663 | if (startingWindow != null || startingView != null |
| 7664 | || startingDisplayed || startingMoved) { |
| 7665 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7666 | pw.print(" startingView="); pw.print(startingView); |
| 7667 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7668 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7669 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | @Override |
| 7673 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7674 | if (stringName == null) { |
| 7675 | StringBuilder sb = new StringBuilder(); |
| 7676 | sb.append("AppWindowToken{"); |
| 7677 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7678 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7679 | stringName = sb.toString(); |
| 7680 | } |
| 7681 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7682 | } |
| 7683 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7685 | // ------------------------------------------------------------- |
| 7686 | // DummyAnimation |
| 7687 | // ------------------------------------------------------------- |
| 7688 | |
| 7689 | // This is an animation that does nothing: it just immediately finishes |
| 7690 | // itself every time it is called. It is used as a stub animation in cases |
| 7691 | // where we want to synchronize multiple things that may be animating. |
| 7692 | static final class DummyAnimation extends Animation { |
| 7693 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 7694 | return false; |
| 7695 | } |
| 7696 | } |
| 7697 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7698 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7699 | // ------------------------------------------------------------- |
| 7700 | // Async Handler |
| 7701 | // ------------------------------------------------------------- |
| 7702 | |
| 7703 | static final class StartingData { |
| 7704 | final String pkg; |
| 7705 | final int theme; |
| 7706 | final CharSequence nonLocalizedLabel; |
| 7707 | final int labelRes; |
| 7708 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7709 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7710 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 7711 | int _labelRes, int _icon) { |
| 7712 | pkg = _pkg; |
| 7713 | theme = _theme; |
| 7714 | nonLocalizedLabel = _nonLocalizedLabel; |
| 7715 | labelRes = _labelRes; |
| 7716 | icon = _icon; |
| 7717 | } |
| 7718 | } |
| 7719 | |
| 7720 | private final class H extends Handler { |
| 7721 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7722 | public static final int REPORT_LOSING_FOCUS = 3; |
| 7723 | public static final int ANIMATE = 4; |
| 7724 | public static final int ADD_STARTING = 5; |
| 7725 | public static final int REMOVE_STARTING = 6; |
| 7726 | public static final int FINISHED_STARTING = 7; |
| 7727 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7728 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 7729 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 7730 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7731 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7732 | public static final int FORCE_GC = 15; |
| 7733 | public static final int ENABLE_SCREEN = 16; |
| 7734 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7735 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7736 | public static final int REPORT_WINDOWS_CHANGE = 19; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7738 | private Session mLastReportedHold; |
| 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 | public H() { |
| 7741 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7742 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7743 | @Override |
| 7744 | public void handleMessage(Message msg) { |
| 7745 | switch (msg.what) { |
| 7746 | case REPORT_FOCUS_CHANGE: { |
| 7747 | WindowState lastFocus; |
| 7748 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | synchronized(mWindowMap) { |
| 7751 | lastFocus = mLastFocus; |
| 7752 | newFocus = mCurrentFocus; |
| 7753 | if (lastFocus == newFocus) { |
| 7754 | // Focus is not changing, so nothing to do. |
| 7755 | return; |
| 7756 | } |
| 7757 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7758 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7759 | // + " to " + newFocus); |
| 7760 | if (newFocus != null && lastFocus != null |
| 7761 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7762 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7763 | mLosingFocus.add(lastFocus); |
| 7764 | lastFocus = null; |
| 7765 | } |
| 7766 | } |
| 7767 | |
| 7768 | if (lastFocus != newFocus) { |
| 7769 | //System.out.println("Changing focus from " + lastFocus |
| 7770 | // + " to " + newFocus); |
| 7771 | if (newFocus != null) { |
| 7772 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7773 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7774 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7775 | } catch (RemoteException e) { |
| 7776 | // Ignore if process has died. |
| 7777 | } |
| 7778 | } |
| 7779 | |
| 7780 | if (lastFocus != null) { |
| 7781 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7782 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7784 | } catch (RemoteException e) { |
| 7785 | // Ignore if process has died. |
| 7786 | } |
| 7787 | } |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7788 | notifyFocusChanged(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7789 | } |
| 7790 | } break; |
| 7791 | |
| 7792 | case REPORT_LOSING_FOCUS: { |
| 7793 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7794 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7795 | synchronized(mWindowMap) { |
| 7796 | losers = mLosingFocus; |
| 7797 | mLosingFocus = new ArrayList<WindowState>(); |
| 7798 | } |
| 7799 | |
| 7800 | final int N = losers.size(); |
| 7801 | for (int i=0; i<N; i++) { |
| 7802 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7803 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7804 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7805 | } catch (RemoteException e) { |
| 7806 | // Ignore if process has died. |
| 7807 | } |
| 7808 | } |
| 7809 | } break; |
| 7810 | |
| 7811 | case ANIMATE: { |
| 7812 | synchronized(mWindowMap) { |
| 7813 | mAnimationPending = false; |
| 7814 | performLayoutAndPlaceSurfacesLocked(); |
| 7815 | } |
| 7816 | } break; |
| 7817 | |
| 7818 | case ADD_STARTING: { |
| 7819 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7820 | final StartingData sd = wtoken.startingData; |
| 7821 | |
| 7822 | if (sd == null) { |
| 7823 | // Animation has been canceled... do nothing. |
| 7824 | return; |
| 7825 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7826 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7827 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7828 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7829 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7830 | View view = null; |
| 7831 | try { |
| 7832 | view = mPolicy.addStartingWindow( |
| 7833 | wtoken.token, sd.pkg, |
| 7834 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 7835 | sd.icon); |
| 7836 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7837 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7838 | } |
| 7839 | |
| 7840 | if (view != null) { |
| 7841 | boolean abort = false; |
| 7842 | |
| 7843 | synchronized(mWindowMap) { |
| 7844 | if (wtoken.removed || wtoken.startingData == null) { |
| 7845 | // If the window was successfully added, then |
| 7846 | // we need to remove it. |
| 7847 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7848 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7849 | "Aborted starting " + wtoken |
| 7850 | + ": removed=" + wtoken.removed |
| 7851 | + " startingData=" + wtoken.startingData); |
| 7852 | wtoken.startingWindow = null; |
| 7853 | wtoken.startingData = null; |
| 7854 | abort = true; |
| 7855 | } |
| 7856 | } else { |
| 7857 | wtoken.startingView = view; |
| 7858 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7859 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7860 | "Added starting " + wtoken |
| 7861 | + ": startingWindow=" |
| 7862 | + wtoken.startingWindow + " startingView=" |
| 7863 | + wtoken.startingView); |
| 7864 | } |
| 7865 | |
| 7866 | if (abort) { |
| 7867 | try { |
| 7868 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7869 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7870 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7871 | } |
| 7872 | } |
| 7873 | } |
| 7874 | } break; |
| 7875 | |
| 7876 | case REMOVE_STARTING: { |
| 7877 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7878 | IBinder token = null; |
| 7879 | View view = null; |
| 7880 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7881 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7882 | + wtoken + ": startingWindow=" |
| 7883 | + wtoken.startingWindow + " startingView=" |
| 7884 | + wtoken.startingView); |
| 7885 | if (wtoken.startingWindow != null) { |
| 7886 | view = wtoken.startingView; |
| 7887 | token = wtoken.token; |
| 7888 | wtoken.startingData = null; |
| 7889 | wtoken.startingView = null; |
| 7890 | wtoken.startingWindow = null; |
| 7891 | } |
| 7892 | } |
| 7893 | if (view != null) { |
| 7894 | try { |
| 7895 | mPolicy.removeStartingWindow(token, view); |
| 7896 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7897 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7898 | } |
| 7899 | } |
| 7900 | } break; |
| 7901 | |
| 7902 | case FINISHED_STARTING: { |
| 7903 | IBinder token = null; |
| 7904 | View view = null; |
| 7905 | while (true) { |
| 7906 | synchronized (mWindowMap) { |
| 7907 | final int N = mFinishedStarting.size(); |
| 7908 | if (N <= 0) { |
| 7909 | break; |
| 7910 | } |
| 7911 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7912 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7913 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7914 | "Finished starting " + wtoken |
| 7915 | + ": startingWindow=" + wtoken.startingWindow |
| 7916 | + " startingView=" + wtoken.startingView); |
| 7917 | |
| 7918 | if (wtoken.startingWindow == null) { |
| 7919 | continue; |
| 7920 | } |
| 7921 | |
| 7922 | view = wtoken.startingView; |
| 7923 | token = wtoken.token; |
| 7924 | wtoken.startingData = null; |
| 7925 | wtoken.startingView = null; |
| 7926 | wtoken.startingWindow = null; |
| 7927 | } |
| 7928 | |
| 7929 | try { |
| 7930 | mPolicy.removeStartingWindow(token, view); |
| 7931 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7932 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7933 | } |
| 7934 | } |
| 7935 | } break; |
| 7936 | |
| 7937 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7938 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7939 | |
| 7940 | boolean nowVisible = msg.arg1 != 0; |
| 7941 | boolean nowGone = msg.arg2 != 0; |
| 7942 | |
| 7943 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7944 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7945 | TAG, "Reporting visible in " + wtoken |
| 7946 | + " visible=" + nowVisible |
| 7947 | + " gone=" + nowGone); |
| 7948 | if (nowVisible) { |
| 7949 | wtoken.appToken.windowsVisible(); |
| 7950 | } else { |
| 7951 | wtoken.appToken.windowsGone(); |
| 7952 | } |
| 7953 | } catch (RemoteException ex) { |
| 7954 | } |
| 7955 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7956 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7957 | case WINDOW_FREEZE_TIMEOUT: { |
| 7958 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7959 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7960 | int i = mWindows.size(); |
| 7961 | while (i > 0) { |
| 7962 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7963 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7964 | if (w.mOrientationChanging) { |
| 7965 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7966 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7967 | } |
| 7968 | } |
| 7969 | performLayoutAndPlaceSurfacesLocked(); |
| 7970 | } |
| 7971 | break; |
| 7972 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7973 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | case HOLD_SCREEN_CHANGED: { |
| 7975 | Session oldHold; |
| 7976 | Session newHold; |
| 7977 | synchronized (mWindowMap) { |
| 7978 | oldHold = mLastReportedHold; |
| 7979 | newHold = (Session)msg.obj; |
| 7980 | mLastReportedHold = newHold; |
| 7981 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7983 | if (oldHold != newHold) { |
| 7984 | try { |
| 7985 | if (oldHold != null) { |
| 7986 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 7987 | "window", |
| 7988 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7989 | } |
| 7990 | if (newHold != null) { |
| 7991 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 7992 | "window", |
| 7993 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7994 | } |
| 7995 | } catch (RemoteException e) { |
| 7996 | } |
| 7997 | } |
| 7998 | break; |
| 7999 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | case APP_TRANSITION_TIMEOUT: { |
| 8002 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8003 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8004 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8005 | "*** APP TRANSITION TIMEOUT"); |
| 8006 | mAppTransitionReady = true; |
| 8007 | mAppTransitionTimeout = true; |
| 8008 | performLayoutAndPlaceSurfacesLocked(); |
| 8009 | } |
| 8010 | } |
| 8011 | break; |
| 8012 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8013 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8014 | case PERSIST_ANIMATION_SCALE: { |
| 8015 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8016 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8017 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8018 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8019 | break; |
| 8020 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8021 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8022 | case FORCE_GC: { |
| 8023 | synchronized(mWindowMap) { |
| 8024 | if (mAnimationPending) { |
| 8025 | // If we are animating, don't do the gc now but |
| 8026 | // delay a bit so we don't interrupt the animation. |
| 8027 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8028 | 2000); |
| 8029 | return; |
| 8030 | } |
| 8031 | // If we are currently rotating the display, it will |
| 8032 | // schedule a new message when done. |
| 8033 | if (mDisplayFrozen) { |
| 8034 | return; |
| 8035 | } |
| 8036 | mFreezeGcPending = 0; |
| 8037 | } |
| 8038 | Runtime.getRuntime().gc(); |
| 8039 | break; |
| 8040 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8041 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8042 | case ENABLE_SCREEN: { |
| 8043 | performEnableScreen(); |
| 8044 | break; |
| 8045 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8046 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8047 | case APP_FREEZE_TIMEOUT: { |
| 8048 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8049 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8050 | int i = mAppTokens.size(); |
| 8051 | while (i > 0) { |
| 8052 | i--; |
| 8053 | AppWindowToken tok = mAppTokens.get(i); |
| 8054 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8055 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8056 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8057 | } |
| 8058 | } |
| 8059 | } |
| 8060 | break; |
| 8061 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8062 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8063 | case SEND_NEW_CONFIGURATION: { |
| 8064 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8065 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8066 | break; |
| 8067 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8068 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8069 | case REPORT_WINDOWS_CHANGE: { |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8070 | if (mWindowsChanged) { |
| 8071 | synchronized (mWindowMap) { |
| 8072 | mWindowsChanged = false; |
| 8073 | } |
| 8074 | notifyWindowsChanged(); |
| 8075 | } |
| 8076 | break; |
| 8077 | } |
| 8078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8079 | } |
| 8080 | } |
| 8081 | } |
| 8082 | |
| 8083 | // ------------------------------------------------------------- |
| 8084 | // IWindowManager API |
| 8085 | // ------------------------------------------------------------- |
| 8086 | |
| 8087 | public IWindowSession openSession(IInputMethodClient client, |
| 8088 | IInputContext inputContext) { |
| 8089 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8090 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8091 | Session session = new Session(client, inputContext); |
| 8092 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8093 | } |
| 8094 | |
| 8095 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8096 | synchronized (mWindowMap) { |
| 8097 | // The focus for the client is the window immediately below |
| 8098 | // where we would place the input method window. |
| 8099 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8100 | WindowState imFocus; |
| 8101 | if (idx > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8102 | imFocus = mWindows.get(idx-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8103 | if (imFocus != null) { |
| 8104 | if (imFocus.mSession.mClient != null && |
| 8105 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8106 | return true; |
| 8107 | } |
| 8108 | } |
| 8109 | } |
| 8110 | } |
| 8111 | return false; |
| 8112 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8113 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8114 | // ------------------------------------------------------------- |
| 8115 | // Internals |
| 8116 | // ------------------------------------------------------------- |
| 8117 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8118 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8119 | boolean throwOnError) { |
| 8120 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8121 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8122 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8123 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8124 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8125 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8126 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8127 | TAG, "Looking up client " + client + ": " + win); |
| 8128 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8129 | RuntimeException ex = new IllegalArgumentException( |
| 8130 | "Requested window " + client + " does not exist"); |
| 8131 | if (throwOnError) { |
| 8132 | throw ex; |
| 8133 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8134 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8135 | return null; |
| 8136 | } |
| 8137 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8138 | RuntimeException ex = new IllegalArgumentException( |
| 8139 | "Requested window " + client + " is in session " + |
| 8140 | win.mSession + ", not " + session); |
| 8141 | if (throwOnError) { |
| 8142 | throw ex; |
| 8143 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8144 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | return null; |
| 8146 | } |
| 8147 | |
| 8148 | return win; |
| 8149 | } |
| 8150 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8151 | final void rebuildAppWindowListLocked() { |
| 8152 | int NW = mWindows.size(); |
| 8153 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8154 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8155 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8156 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8157 | // First remove all existing app windows. |
| 8158 | i=0; |
| 8159 | while (i < NW) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8160 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8161 | if (w.mAppToken != null) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8162 | WindowState win = mWindows.remove(i); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8163 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8164 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8165 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8166 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8167 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8168 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8169 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8170 | && lastWallpaper == i-1) { |
| 8171 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8172 | } |
| 8173 | i++; |
| 8174 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8175 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8176 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8177 | // so skip them before adding app tokens. |
| 8178 | lastWallpaper++; |
| 8179 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8180 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8181 | // First add all of the exiting app tokens... these are no longer |
| 8182 | // in the main app list, but still have windows shown. We put them |
| 8183 | // in the back because now that the animation is over we no longer |
| 8184 | // will care about them. |
| 8185 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8186 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8187 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8188 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8189 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8190 | // And add in the still active app tokens in Z order. |
| 8191 | NT = mAppTokens.size(); |
| 8192 | for (int j=0; j<NT; j++) { |
| 8193 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8194 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8195 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8196 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8197 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8198 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8199 | + " windows but added " + i); |
| 8200 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8201 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8202 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8203 | private final void assignLayersLocked() { |
| 8204 | int N = mWindows.size(); |
| 8205 | int curBaseLayer = 0; |
| 8206 | int curLayer = 0; |
| 8207 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8208 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8209 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8210 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8211 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8212 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8213 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8214 | w.mLayer = curLayer; |
| 8215 | } else { |
| 8216 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8217 | w.mLayer = curLayer; |
| 8218 | } |
| 8219 | if (w.mTargetAppToken != null) { |
| 8220 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8221 | } else if (w.mAppToken != null) { |
| 8222 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8223 | } else { |
| 8224 | w.mAnimLayer = w.mLayer; |
| 8225 | } |
| 8226 | if (w.mIsImWindow) { |
| 8227 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8228 | } else if (w.mIsWallpaper) { |
| 8229 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8230 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8231 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8232 | + w.mAnimLayer); |
| 8233 | //System.out.println( |
| 8234 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8235 | } |
| 8236 | } |
| 8237 | |
| 8238 | private boolean mInLayout = false; |
| 8239 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8240 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8241 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8242 | throw new RuntimeException("Recursive call!"); |
| 8243 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8244 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8245 | return; |
| 8246 | } |
| 8247 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8248 | if (mWaitingForConfig) { |
| 8249 | // Our configuration has changed (most likely rotation), but we |
| 8250 | // don't yet have the complete configuration to report to |
| 8251 | // applications. Don't do any window layout until we have it. |
| 8252 | return; |
| 8253 | } |
| 8254 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8255 | boolean recoveringMemory = false; |
| 8256 | if (mForceRemoves != null) { |
| 8257 | recoveringMemory = true; |
| 8258 | // Wait a little it for things to settle down, and off we go. |
| 8259 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8260 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8261 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | removeWindowInnerLocked(ws.mSession, ws); |
| 8263 | } |
| 8264 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8265 | 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] | 8266 | Object tmp = new Object(); |
| 8267 | synchronized (tmp) { |
| 8268 | try { |
| 8269 | tmp.wait(250); |
| 8270 | } catch (InterruptedException e) { |
| 8271 | } |
| 8272 | } |
| 8273 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8274 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8275 | mInLayout = true; |
| 8276 | try { |
| 8277 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8278 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8279 | int i = mPendingRemove.size()-1; |
| 8280 | if (i >= 0) { |
| 8281 | while (i >= 0) { |
| 8282 | WindowState w = mPendingRemove.get(i); |
| 8283 | removeWindowInnerLocked(w.mSession, w); |
| 8284 | i--; |
| 8285 | } |
| 8286 | mPendingRemove.clear(); |
| 8287 | |
| 8288 | mInLayout = false; |
| 8289 | assignLayersLocked(); |
| 8290 | mLayoutNeeded = true; |
| 8291 | performLayoutAndPlaceSurfacesLocked(); |
| 8292 | |
| 8293 | } else { |
| 8294 | mInLayout = false; |
| 8295 | if (mLayoutNeeded) { |
| 8296 | requestAnimationLocked(0); |
| 8297 | } |
| 8298 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8299 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8300 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8301 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8302 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8303 | } catch (RuntimeException e) { |
| 8304 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8305 | 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] | 8306 | } |
| 8307 | } |
| 8308 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8309 | private final int performLayoutLockedInner() { |
| 8310 | if (!mLayoutNeeded) { |
| 8311 | return 0; |
| 8312 | } |
| 8313 | |
| 8314 | mLayoutNeeded = false; |
| 8315 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8316 | final int dw = mDisplay.getWidth(); |
| 8317 | final int dh = mDisplay.getHeight(); |
| 8318 | |
| 8319 | final int N = mWindows.size(); |
| 8320 | int i; |
| 8321 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8322 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8323 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8324 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8325 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8326 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8327 | int seq = mLayoutSeq+1; |
| 8328 | if (seq < 0) seq = 0; |
| 8329 | mLayoutSeq = seq; |
| 8330 | |
| 8331 | // First perform layout of any root windows (not attached |
| 8332 | // to another window). |
| 8333 | int topAttached = -1; |
| 8334 | for (i = N-1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8335 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8336 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8337 | // Don't do layout of a window if it is not visible, or |
| 8338 | // soon won't be visible, to avoid wasting time and funky |
| 8339 | // changes while a window is animating away. |
| 8340 | final AppWindowToken atoken = win.mAppToken; |
| 8341 | final boolean gone = win.mViewVisibility == View.GONE |
| 8342 | || !win.mRelayoutCalled |
| 8343 | || win.mRootToken.hidden |
| 8344 | || (atoken != null && atoken.hiddenRequested) |
| 8345 | || win.mAttachedHidden |
| 8346 | || win.mExiting || win.mDestroying; |
| 8347 | |
| 8348 | if (!win.mLayoutAttached) { |
| 8349 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 8350 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8351 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 8352 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 8353 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8354 | + win.mRelayoutCalled + " hidden=" |
| 8355 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8356 | + (atoken != null && atoken.hiddenRequested) |
| 8357 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8358 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8359 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8360 | // If this view is GONE, then skip it -- keep the current |
| 8361 | // frame, and let the caller know so they can ignore it |
| 8362 | // if they want. (We do the normal layout for INVISIBLE |
| 8363 | // windows, since that means "perform layout as normal, |
| 8364 | // just don't display"). |
| 8365 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8366 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8367 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8368 | win.mLayoutSeq = seq; |
| 8369 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8370 | + win.mFrame + " mContainingFrame=" |
| 8371 | + win.mContainingFrame + " mDisplayFrame=" |
| 8372 | + win.mDisplayFrame); |
| 8373 | } else { |
| 8374 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8375 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8376 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8377 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8378 | |
| 8379 | // Now perform layout of attached windows, which usually |
| 8380 | // depend on the position of the window they are attached to. |
| 8381 | // XXX does not deal with windows that are attached to windows |
| 8382 | // that are themselves attached. |
| 8383 | for (i = topAttached; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8384 | WindowState win = mWindows.get(i); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8385 | |
| 8386 | // If this view is GONE, then skip it -- keep the current |
| 8387 | // frame, and let the caller know so they can ignore it |
| 8388 | // if they want. (We do the normal layout for INVISIBLE |
| 8389 | // windows, since that means "perform layout as normal, |
| 8390 | // just don't display"). |
| 8391 | if (win.mLayoutAttached) { |
| 8392 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 8393 | + " mHaveFrame=" + win.mHaveFrame |
| 8394 | + " mViewVisibility=" + win.mViewVisibility |
| 8395 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 8396 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8397 | || !win.mHaveFrame) { |
| 8398 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8399 | win.mLayoutSeq = seq; |
| 8400 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8401 | + win.mFrame + " mContainingFrame=" |
| 8402 | + win.mContainingFrame + " mDisplayFrame=" |
| 8403 | + win.mDisplayFrame); |
| 8404 | } |
| 8405 | } |
| 8406 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8407 | |
| 8408 | // Window frames may have changed. Tell the input dispatcher about it. |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8409 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8410 | |
| 8411 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8412 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8413 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8414 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 8415 | boolean recoveringMemory) { |
| Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 8416 | if (mDisplay == null) { |
| 8417 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 8418 | return; |
| 8419 | } |
| 8420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8421 | final long currentTime = SystemClock.uptimeMillis(); |
| 8422 | final int dw = mDisplay.getWidth(); |
| 8423 | final int dh = mDisplay.getHeight(); |
| 8424 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8425 | int i; |
| 8426 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8427 | if (mFocusMayChange) { |
| 8428 | mFocusMayChange = false; |
| 8429 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 8430 | } |
| 8431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | if (mFxSession == null) { |
| 8433 | mFxSession = new SurfaceSession(); |
| 8434 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8435 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8436 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8437 | |
| 8438 | // Initialize state of exiting tokens. |
| 8439 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8440 | mExitingTokens.get(i).hasVisible = false; |
| 8441 | } |
| 8442 | |
| 8443 | // Initialize state of exiting applications. |
| 8444 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8445 | mExitingAppTokens.get(i).hasVisible = false; |
| 8446 | } |
| 8447 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8448 | boolean orientationChangeComplete = true; |
| 8449 | Session holdScreen = null; |
| 8450 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 8451 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8452 | boolean focusDisplayed = false; |
| 8453 | boolean animating = false; |
| 8454 | |
| 8455 | Surface.openTransaction(); |
| 8456 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8457 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8458 | int repeats = 0; |
| 8459 | int changes = 0; |
| 8460 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8461 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8462 | repeats++; |
| 8463 | if (repeats > 6) { |
| 8464 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 8465 | mLayoutNeeded = false; |
| 8466 | break; |
| 8467 | } |
| 8468 | |
| 8469 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 8470 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 8471 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 8472 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 8473 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 8474 | assignLayersLocked(); |
| 8475 | mLayoutNeeded = true; |
| 8476 | } |
| 8477 | } |
| 8478 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 8479 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 8480 | if (updateOrientationFromAppTokensLocked()) { |
| 8481 | mLayoutNeeded = true; |
| 8482 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 8483 | } |
| 8484 | } |
| 8485 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 8486 | mLayoutNeeded = true; |
| 8487 | } |
| 8488 | } |
| 8489 | |
| 8490 | // FIRST LOOP: Perform a layout, if needed. |
| 8491 | if (repeats < 4) { |
| 8492 | changes = performLayoutLockedInner(); |
| 8493 | if (changes != 0) { |
| 8494 | continue; |
| 8495 | } |
| 8496 | } else { |
| 8497 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 8498 | changes = 0; |
| 8499 | } |
| 8500 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8501 | final int transactionSequence = ++mTransactionSequence; |
| 8502 | |
| 8503 | // Update animations of all applications, including those |
| 8504 | // associated with exiting/removed apps |
| 8505 | boolean tokensAnimating = false; |
| 8506 | final int NAT = mAppTokens.size(); |
| 8507 | for (i=0; i<NAT; i++) { |
| 8508 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8509 | tokensAnimating = true; |
| 8510 | } |
| 8511 | } |
| 8512 | final int NEAT = mExitingAppTokens.size(); |
| 8513 | for (i=0; i<NEAT; i++) { |
| 8514 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8515 | tokensAnimating = true; |
| 8516 | } |
| 8517 | } |
| 8518 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8519 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 8520 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8521 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8522 | + transactionSequence + " tokensAnimating=" |
| 8523 | + tokensAnimating); |
| 8524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8525 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8526 | |
| 8527 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8528 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8529 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8530 | |
| 8531 | mPolicy.beginAnimationLw(dw, dh); |
| 8532 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8533 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8535 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8536 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8537 | |
| 8538 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8539 | |
| 8540 | if (w.mSurface != null) { |
| 8541 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8542 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 8543 | if ((w.mAttrs.flags |
| 8544 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8545 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8546 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8547 | wallpaperMayChange = true; |
| 8548 | } |
| 8549 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8550 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8551 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8552 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 8553 | animating = true; |
| 8554 | //w.dump(" "); |
| 8555 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8556 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 8557 | wallpaperMayChange = true; |
| 8558 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8559 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8560 | if (mPolicy.doesForceHide(w, attrs)) { |
| 8561 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8562 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8563 | "Animation done that could impact force hide: " |
| 8564 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8565 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8566 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8567 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 8568 | forceHiding = true; |
| 8569 | } |
| 8570 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 8571 | boolean changed; |
| 8572 | if (forceHiding) { |
| 8573 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8574 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8575 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8576 | } else { |
| 8577 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8578 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8579 | "Now policy shown: " + w); |
| 8580 | if (changed) { |
| 8581 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8582 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8583 | // Assume we will need to animate. If |
| 8584 | // we don't (because the wallpaper will |
| 8585 | // stay with the lock screen), then we will |
| 8586 | // clean up later. |
| 8587 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 8588 | if (a != null) { |
| 8589 | w.setAnimation(a); |
| 8590 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8591 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8592 | if (mCurrentFocus == null || |
| 8593 | mCurrentFocus.mLayer < w.mLayer) { |
| 8594 | // We are showing on to of the current |
| 8595 | // focus, so re-evaluate focus to make |
| 8596 | // sure it is correct. |
| 8597 | mFocusMayChange = true; |
| 8598 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8599 | } |
| 8600 | } |
| 8601 | if (changed && (attrs.flags |
| 8602 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 8603 | wallpaperMayChange = true; |
| 8604 | } |
| 8605 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8607 | mPolicy.animatingWindowLw(w, attrs); |
| 8608 | } |
| 8609 | |
| 8610 | final AppWindowToken atoken = w.mAppToken; |
| 8611 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 8612 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 8613 | atoken.lastTransactionSequence = transactionSequence; |
| 8614 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8615 | atoken.startingDisplayed = false; |
| 8616 | } |
| 8617 | if ((w.isOnScreen() || w.mAttrs.type |
| 8618 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8619 | && !w.mExiting && !w.mDestroying) { |
| 8620 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8621 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8622 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8623 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8624 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8625 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8626 | + " pv=" + w.mPolicyVisibility |
| 8627 | + " dp=" + w.mDrawPending |
| 8628 | + " cdp=" + w.mCommitDrawPending |
| 8629 | + " ah=" + w.mAttachedHidden |
| 8630 | + " th=" + atoken.hiddenRequested |
| 8631 | + " a=" + w.mAnimating); |
| 8632 | } |
| 8633 | } |
| 8634 | if (w != atoken.startingWindow) { |
| 8635 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 8636 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8637 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8639 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8640 | "tokenMayBeDrawn: " + atoken |
| 8641 | + " freezingScreen=" + atoken.freezingScreen |
| 8642 | + " mAppFreezing=" + w.mAppFreezing); |
| 8643 | tokenMayBeDrawn = true; |
| 8644 | } |
| 8645 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8646 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8647 | atoken.startingDisplayed = true; |
| 8648 | } |
| 8649 | } |
| 8650 | } else if (w.mReadyToShow) { |
| 8651 | w.performShowLocked(); |
| 8652 | } |
| 8653 | } |
| 8654 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8655 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8656 | |
| 8657 | if (tokenMayBeDrawn) { |
| 8658 | // See if any windows have been drawn, so they (and others |
| 8659 | // associated with them) can now be shown. |
| 8660 | final int NT = mTokenList.size(); |
| 8661 | for (i=0; i<NT; i++) { |
| 8662 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 8663 | if (wtoken == null) { |
| 8664 | continue; |
| 8665 | } |
| 8666 | if (wtoken.freezingScreen) { |
| 8667 | int numInteresting = wtoken.numInterestingWindows; |
| 8668 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8669 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8670 | "allDrawn: " + wtoken |
| 8671 | + " interesting=" + numInteresting |
| 8672 | + " drawn=" + wtoken.numDrawnWindows); |
| 8673 | wtoken.showAllWindowsLocked(); |
| 8674 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 8675 | orientationChangeComplete = true; |
| 8676 | } |
| 8677 | } else if (!wtoken.allDrawn) { |
| 8678 | int numInteresting = wtoken.numInterestingWindows; |
| 8679 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8680 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8681 | "allDrawn: " + wtoken |
| 8682 | + " interesting=" + numInteresting |
| 8683 | + " drawn=" + wtoken.numDrawnWindows); |
| 8684 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8685 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8686 | |
| 8687 | // We can now show all of the drawn windows! |
| 8688 | if (!mOpeningApps.contains(wtoken)) { |
| 8689 | wtoken.showAllWindowsLocked(); |
| 8690 | } |
| 8691 | } |
| 8692 | } |
| 8693 | } |
| 8694 | } |
| 8695 | |
| 8696 | // If we are ready to perform an app transition, check through |
| 8697 | // all of the app tokens to be shown and see if they are ready |
| 8698 | // to go. |
| 8699 | if (mAppTransitionReady) { |
| 8700 | int NN = mOpeningApps.size(); |
| 8701 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8702 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8703 | "Checking " + NN + " opening apps (frozen=" |
| 8704 | + mDisplayFrozen + " timeout=" |
| 8705 | + mAppTransitionTimeout + ")..."); |
| 8706 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8707 | // If the display isn't frozen, wait to do anything until |
| 8708 | // all of the apps are ready. Otherwise just go because |
| 8709 | // we'll unfreeze the display when everyone is ready. |
| 8710 | for (i=0; i<NN && goodToGo; i++) { |
| 8711 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8712 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8713 | "Check opening app" + wtoken + ": allDrawn=" |
| 8714 | + wtoken.allDrawn + " startingDisplayed=" |
| 8715 | + wtoken.startingDisplayed); |
| 8716 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8717 | && !wtoken.startingMoved) { |
| 8718 | goodToGo = false; |
| 8719 | } |
| 8720 | } |
| 8721 | } |
| 8722 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8723 | 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] | 8724 | int transit = mNextAppTransition; |
| 8725 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8726 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8727 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8728 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8729 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8730 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8731 | mAppTransitionTimeout = false; |
| 8732 | mStartingIconInTransition = false; |
| 8733 | mSkipAppTransitionAnimation = false; |
| 8734 | |
| 8735 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8736 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8737 | // If there are applications waiting to come to the |
| 8738 | // top of the stack, now is the time to move their windows. |
| 8739 | // (Note that we don't do apps going to the bottom |
| 8740 | // here -- we want to keep their windows in the old |
| 8741 | // Z-order until the animation completes.) |
| 8742 | if (mToTopApps.size() > 0) { |
| 8743 | NN = mAppTokens.size(); |
| 8744 | for (i=0; i<NN; i++) { |
| 8745 | AppWindowToken wtoken = mAppTokens.get(i); |
| 8746 | if (wtoken.sendingToTop) { |
| 8747 | wtoken.sendingToTop = false; |
| 8748 | moveAppWindowsLocked(wtoken, NN, false); |
| 8749 | } |
| 8750 | } |
| 8751 | mToTopApps.clear(); |
| 8752 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8753 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8754 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8755 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8756 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8757 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8758 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8759 | // The top-most window will supply the layout params, |
| 8760 | // and we will determine it below. |
| 8761 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8762 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8763 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8764 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8765 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8766 | "New wallpaper target=" + mWallpaperTarget |
| 8767 | + ", lower target=" + mLowerWallpaperTarget |
| 8768 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8769 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8770 | // Do a first pass through the tokens for two |
| 8771 | // things: |
| 8772 | // (1) Determine if both the closing and opening |
| 8773 | // app token sets are wallpaper targets, in which |
| 8774 | // case special animations are needed |
| 8775 | // (since the wallpaper needs to stay static |
| 8776 | // behind them). |
| 8777 | // (2) Find the layout params of the top-most |
| 8778 | // application window in the tokens, which is |
| 8779 | // what will control the animation theme. |
| 8780 | final int NC = mClosingApps.size(); |
| 8781 | NN = NC + mOpeningApps.size(); |
| 8782 | for (i=0; i<NN; i++) { |
| 8783 | AppWindowToken wtoken; |
| 8784 | int mode; |
| 8785 | if (i < NC) { |
| 8786 | wtoken = mClosingApps.get(i); |
| 8787 | mode = 1; |
| 8788 | } else { |
| 8789 | wtoken = mOpeningApps.get(i-NC); |
| 8790 | mode = 2; |
| 8791 | } |
| 8792 | if (mLowerWallpaperTarget != null) { |
| 8793 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 8794 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 8795 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8796 | } |
| 8797 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8798 | if (wtoken.appFullscreen) { |
| 8799 | WindowState ws = wtoken.findMainWindow(); |
| 8800 | if (ws != null) { |
| 8801 | // If this is a compatibility mode |
| 8802 | // window, we will always use its anim. |
| 8803 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8804 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8805 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8806 | bestAnimLayer = Integer.MAX_VALUE; |
| 8807 | } else if (ws.mLayer > bestAnimLayer) { |
| 8808 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8809 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8810 | bestAnimLayer = ws.mLayer; |
| 8811 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8812 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8813 | } |
| 8814 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8815 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8816 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8817 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8818 | "Wallpaper animation!"); |
| 8819 | switch (transit) { |
| 8820 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 8821 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 8822 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 8823 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 8824 | break; |
| 8825 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 8826 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 8827 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 8828 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 8829 | break; |
| 8830 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8831 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8832 | "New transit: " + transit); |
| 8833 | } else if (oldWallpaper != null) { |
| 8834 | // We are transitioning from an activity with |
| 8835 | // a wallpaper to one without. |
| 8836 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8837 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8838 | "New transit away from wallpaper: " + transit); |
| 8839 | } else if (mWallpaperTarget != null) { |
| 8840 | // We are transitioning from an activity without |
| 8841 | // a wallpaper to now showing the wallpaper |
| 8842 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8843 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8844 | "New transit into wallpaper: " + transit); |
| 8845 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8846 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8847 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 8848 | mLastEnterAnimToken = animToken; |
| 8849 | mLastEnterAnimParams = animLp; |
| 8850 | } else if (mLastEnterAnimParams != null) { |
| 8851 | animLp = mLastEnterAnimParams; |
| 8852 | mLastEnterAnimToken = null; |
| 8853 | mLastEnterAnimParams = null; |
| 8854 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8855 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8856 | // If all closing windows are obscured, then there is |
| 8857 | // no need to do an animation. This is the case, for |
| 8858 | // example, when this transition is being done behind |
| 8859 | // the lock screen. |
| 8860 | if (!mPolicy.allowAppAnimationsLw()) { |
| 8861 | animLp = null; |
| 8862 | } |
| 8863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8864 | NN = mOpeningApps.size(); |
| 8865 | for (i=0; i<NN; i++) { |
| 8866 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8867 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8868 | "Now opening app" + wtoken); |
| 8869 | wtoken.reportedVisible = false; |
| 8870 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8871 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8872 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8873 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8874 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8875 | wtoken.showAllWindowsLocked(); |
| 8876 | } |
| 8877 | NN = mClosingApps.size(); |
| 8878 | for (i=0; i<NN; i++) { |
| 8879 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8880 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8881 | "Now closing app" + wtoken); |
| 8882 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8883 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8884 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8885 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8886 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8887 | // Force the allDrawn flag, because we want to start |
| 8888 | // this guy's animations regardless of whether it's |
| 8889 | // gotten drawn. |
| 8890 | wtoken.allDrawn = true; |
| 8891 | } |
| 8892 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 8893 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8894 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8895 | mOpeningApps.clear(); |
| 8896 | mClosingApps.clear(); |
| 8897 | |
| 8898 | // This has changed the visibility of windows, so perform |
| 8899 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8900 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8901 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 8902 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 8903 | assignLayersLocked(); |
| 8904 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8905 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8906 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8907 | } |
| 8908 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8909 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8910 | int adjResult = 0; |
| 8911 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8912 | if (!animating && mAppTransitionRunning) { |
| 8913 | // We have finished the animation of an app transition. To do |
| 8914 | // this, we have delayed a lot of operations like showing and |
| 8915 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 8916 | // reflects the correct Z-order, but the window list may now |
| 8917 | // be out of sync with it. So here we will just rebuild the |
| 8918 | // entire app window list. Fun! |
| 8919 | mAppTransitionRunning = false; |
| 8920 | // Clear information about apps that were moving. |
| 8921 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8922 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8923 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8924 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8925 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8926 | moveInputMethodWindowsIfNeededLocked(false); |
| 8927 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 8928 | // Since the window list has been rebuilt, focus might |
| 8929 | // have to be recomputed since the actual order of windows |
| 8930 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8931 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8932 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8933 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8934 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8935 | // At this point, there was a window with a wallpaper that |
| 8936 | // was force hiding other windows behind it, but now it |
| 8937 | // is going away. This may be simple -- just animate |
| 8938 | // away the wallpaper and its window -- or it may be |
| 8939 | // hard -- the wallpaper now needs to be shown behind |
| 8940 | // something that was hidden. |
| 8941 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8942 | if (mLowerWallpaperTarget != null |
| 8943 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8944 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8945 | "wallpaperForceHiding changed with lower=" |
| 8946 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8947 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8948 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 8949 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 8950 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 8951 | // The lower target has become hidden before we |
| 8952 | // actually started the animation... let's completely |
| 8953 | // re-evaluate everything. |
| 8954 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8955 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8956 | } |
| 8957 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8958 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8959 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8960 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8961 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8962 | + " NEW: " + mWallpaperTarget |
| 8963 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8964 | if (mLowerWallpaperTarget == null) { |
| 8965 | // Whoops, we don't need a special wallpaper animation. |
| 8966 | // Clear them out. |
| 8967 | forceHiding = false; |
| 8968 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8969 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8970 | if (w.mSurface != null) { |
| 8971 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 8972 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8973 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8974 | forceHiding = true; |
| 8975 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 8976 | if (!w.mAnimating) { |
| 8977 | // We set the animation above so it |
| 8978 | // is not yet running. |
| 8979 | w.clearAnimation(); |
| 8980 | } |
| 8981 | } |
| 8982 | } |
| 8983 | } |
| 8984 | } |
| 8985 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8986 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8987 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8988 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8989 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8990 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8991 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8992 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8993 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8994 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8995 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8996 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8997 | assignLayersLocked(); |
| 8998 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8999 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9000 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9001 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9002 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9003 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9004 | if (mFocusMayChange) { |
| 9005 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9006 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9007 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9008 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9009 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9010 | } |
| 9011 | |
| 9012 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9013 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9014 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9015 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9016 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9017 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9018 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9019 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9020 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9021 | |
| 9022 | // THIRD LOOP: Update the surfaces of all windows. |
| 9023 | |
| 9024 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9025 | |
| 9026 | boolean obscured = false; |
| 9027 | boolean blurring = false; |
| 9028 | boolean dimming = false; |
| 9029 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9030 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9031 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9032 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9033 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9034 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9035 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9036 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9037 | |
| 9038 | boolean displayed = false; |
| 9039 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9040 | final int attrFlags = attrs.flags; |
| 9041 | |
| 9042 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9043 | // XXX NOTE: The logic here could be improved. We have |
| 9044 | // the decision about whether to resize a window separated |
| 9045 | // from whether to hide the surface. This can cause us to |
| 9046 | // resize a surface even if we are going to hide it. You |
| 9047 | // can see this by (1) holding device in landscape mode on |
| 9048 | // home screen; (2) tapping browser icon (device will rotate |
| 9049 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9050 | // in step 2 but then immediately hidden, causing us to |
| 9051 | // have to resize and then redraw it again in step 3. It |
| 9052 | // would be nice to figure out how to avoid this, but it is |
| 9053 | // difficult because we do need to resize surfaces in some |
| 9054 | // cases while they are hidden such as when first showing a |
| 9055 | // window. |
| 9056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9057 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9058 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9059 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9060 | + ": new=" + w.mShownFrame + ", old=" |
| 9061 | + w.mLastShownFrame); |
| 9062 | |
| 9063 | boolean resize; |
| 9064 | int width, height; |
| 9065 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9066 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9067 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9068 | // for a scaled surface, we just want to use |
| 9069 | // the requested size. |
| 9070 | width = w.mRequestedWidth; |
| 9071 | height = w.mRequestedHeight; |
| 9072 | w.mLastRequestedWidth = width; |
| 9073 | w.mLastRequestedHeight = height; |
| 9074 | w.mLastShownFrame.set(w.mShownFrame); |
| 9075 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9076 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9077 | "POS " + w.mShownFrame.left |
| 9078 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9079 | w.mSurfaceX = w.mShownFrame.left; |
| 9080 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9081 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9082 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9083 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9084 | if (!recoveringMemory) { |
| 9085 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9086 | } |
| 9087 | } |
| 9088 | } else { |
| 9089 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9090 | width = w.mShownFrame.width(); |
| 9091 | height = w.mShownFrame.height(); |
| 9092 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9093 | } |
| 9094 | |
| 9095 | if (resize) { |
| 9096 | if (width < 1) width = 1; |
| 9097 | if (height < 1) height = 1; |
| 9098 | if (w.mSurface != null) { |
| 9099 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9100 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9101 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9102 | + w.mShownFrame.top + " SIZE " |
| 9103 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9104 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9105 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9106 | w.mSurfaceW = width; |
| 9107 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9108 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9109 | w.mSurfaceX = w.mShownFrame.left; |
| 9110 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9111 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9112 | w.mShownFrame.top); |
| 9113 | } catch (RuntimeException e) { |
| 9114 | // If something goes wrong with the surface (such |
| 9115 | // as running out of memory), don't take down the |
| 9116 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9117 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9118 | + "size=(" + width + "x" + height |
| 9119 | + "), pos=(" + w.mShownFrame.left |
| 9120 | + "," + w.mShownFrame.top + ")", e); |
| 9121 | if (!recoveringMemory) { |
| 9122 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9123 | } |
| 9124 | } |
| 9125 | } |
| 9126 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9127 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9128 | w.mContentInsetsChanged = |
| 9129 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9130 | w.mVisibleInsetsChanged = |
| 9131 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9132 | boolean configChanged = |
| 9133 | w.mConfiguration != mCurConfiguration |
| 9134 | && (w.mConfiguration == null |
| 9135 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9136 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9137 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9138 | + mCurConfiguration); |
| 9139 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9140 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9141 | + ": configChanged=" + configChanged |
| 9142 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9143 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9144 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9145 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9146 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9147 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9148 | w.mLastFrame.set(w.mFrame); |
| 9149 | w.mLastContentInsets.set(w.mContentInsets); |
| 9150 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9151 | // If the screen is currently frozen, then keep |
| 9152 | // it frozen until this window draws at its new |
| 9153 | // orientation. |
| 9154 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9155 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9156 | "Resizing while display frozen: " + w); |
| 9157 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9158 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9159 | mWindowsFreezingScreen = true; |
| 9160 | // XXX should probably keep timeout from |
| 9161 | // when we first froze the display. |
| 9162 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9163 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9164 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9165 | } |
| 9166 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9167 | // If the orientation is changing, then we need to |
| 9168 | // hold off on unfreezing the display until this |
| 9169 | // window has been redrawn; to do that, we need |
| 9170 | // to go through the process of getting informed |
| 9171 | // by the application when it has finished drawing. |
| 9172 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9173 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9174 | "Orientation start waiting for draw in " |
| 9175 | + w + ", surface " + w.mSurface); |
| 9176 | w.mDrawPending = true; |
| 9177 | w.mCommitDrawPending = false; |
| 9178 | w.mReadyToShow = false; |
| 9179 | if (w.mAppToken != null) { |
| 9180 | w.mAppToken.allDrawn = false; |
| 9181 | } |
| 9182 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9183 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9184 | "Resizing window " + w + " to " + w.mFrame); |
| 9185 | mResizingWindows.add(w); |
| 9186 | } else if (w.mOrientationChanging) { |
| 9187 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9188 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9189 | "Orientation not waiting for draw in " |
| 9190 | + w + ", surface " + w.mSurface); |
| 9191 | w.mOrientationChanging = false; |
| 9192 | } |
| 9193 | } |
| 9194 | } |
| 9195 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9196 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9197 | if (!w.mLastHidden) { |
| 9198 | //dump(); |
| 9199 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9200 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9201 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9202 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9203 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9204 | try { |
| 9205 | w.mSurface.hide(); |
| 9206 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9207 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9208 | } |
| 9209 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9210 | } |
| 9211 | // If we are waiting for this window to handle an |
| 9212 | // orientation change, well, it is hidden, so |
| 9213 | // doesn't really matter. Note that this does |
| 9214 | // introduce a potential glitch if the window |
| 9215 | // becomes unhidden before it has drawn for the |
| 9216 | // new orientation. |
| 9217 | if (w.mOrientationChanging) { |
| 9218 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9219 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9220 | "Orientation change skips hidden " + w); |
| 9221 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | } else if (w.mLastLayer != w.mAnimLayer |
| 9223 | || w.mLastAlpha != w.mShownAlpha |
| 9224 | || w.mLastDsDx != w.mDsDx |
| 9225 | || w.mLastDtDx != w.mDtDx |
| 9226 | || w.mLastDsDy != w.mDsDy |
| 9227 | || w.mLastDtDy != w.mDtDy |
| 9228 | || w.mLastHScale != w.mHScale |
| 9229 | || w.mLastVScale != w.mVScale |
| 9230 | || w.mLastHidden) { |
| 9231 | displayed = true; |
| 9232 | w.mLastAlpha = w.mShownAlpha; |
| 9233 | w.mLastLayer = w.mAnimLayer; |
| 9234 | w.mLastDsDx = w.mDsDx; |
| 9235 | w.mLastDtDx = w.mDtDx; |
| 9236 | w.mLastDsDy = w.mDsDy; |
| 9237 | w.mLastDtDy = w.mDtDy; |
| 9238 | w.mLastHScale = w.mHScale; |
| 9239 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9240 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9241 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9242 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9243 | + "," + (w.mDtDx*w.mVScale) |
| 9244 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9245 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9246 | if (w.mSurface != null) { |
| 9247 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9248 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9249 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9250 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9251 | w.mSurface.setLayer(w.mAnimLayer); |
| 9252 | w.mSurface.setMatrix( |
| 9253 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9254 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9255 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9256 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9257 | if (!recoveringMemory) { |
| 9258 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9259 | } |
| 9260 | } |
| 9261 | } |
| 9262 | |
| 9263 | if (w.mLastHidden && !w.mDrawPending |
| 9264 | && !w.mCommitDrawPending |
| 9265 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9266 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9267 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9268 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9269 | + " during relayout"); |
| 9270 | if (showSurfaceRobustlyLocked(w)) { |
| 9271 | w.mHasDrawn = true; |
| 9272 | w.mLastHidden = false; |
| 9273 | } else { |
| 9274 | w.mOrientationChanging = false; |
| 9275 | } |
| 9276 | } |
| 9277 | if (w.mSurface != null) { |
| 9278 | w.mToken.hasVisible = true; |
| 9279 | } |
| 9280 | } else { |
| 9281 | displayed = true; |
| 9282 | } |
| 9283 | |
| 9284 | if (displayed) { |
| 9285 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9286 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9287 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9288 | covered = true; |
| 9289 | } |
| 9290 | } |
| 9291 | if (w.mOrientationChanging) { |
| 9292 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9293 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9294 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9295 | "Orientation continue waiting for draw in " + w); |
| 9296 | } else { |
| 9297 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9298 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9299 | "Orientation change complete in " + w); |
| 9300 | } |
| 9301 | } |
| 9302 | w.mToken.hasVisible = true; |
| 9303 | } |
| 9304 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9305 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9306 | "Orientation change skips hidden " + w); |
| 9307 | w.mOrientationChanging = false; |
| 9308 | } |
| 9309 | |
| 9310 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9311 | |
| 9312 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9313 | focusDisplayed = true; |
| 9314 | } |
| 9315 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9316 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9318 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9319 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | if (w.mSurface != null) { |
| 9321 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9322 | holdScreen = w.mSession; |
| 9323 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9324 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9325 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9326 | screenBrightness = w.mAttrs.screenBrightness; |
| 9327 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9328 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 9329 | && buttonBrightness < 0) { |
| 9330 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 9331 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 9332 | if (canBeSeen |
| 9333 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9334 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9335 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9336 | syswin = true; |
| 9337 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9338 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9339 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9340 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9341 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9342 | // This window completely covers everything behind it, |
| 9343 | // so we want to leave all of them as unblurred (for |
| 9344 | // performance reasons). |
| 9345 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9346 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9347 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9348 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9349 | obscured = true; |
| 9350 | if (mBackgroundFillerSurface == null) { |
| 9351 | try { |
| 9352 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9353 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9354 | 0, dw, dh, |
| 9355 | PixelFormat.OPAQUE, |
| 9356 | Surface.FX_SURFACE_NORMAL); |
| 9357 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9358 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9359 | } |
| 9360 | } |
| 9361 | try { |
| 9362 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9363 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9364 | // Using the same layer as Dim because they will never be shown at the |
| 9365 | // same time. |
| 9366 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9367 | mBackgroundFillerSurface.show(); |
| 9368 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9369 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9370 | } |
| 9371 | backgroundFillerShown = true; |
| 9372 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9373 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9374 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9375 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9376 | + ": blurring=" + blurring |
| 9377 | + " obscured=" + obscured |
| 9378 | + " displayed=" + displayed); |
| 9379 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9380 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9381 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9382 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9383 | if (mDimAnimator == null) { |
| 9384 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9385 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9386 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9387 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9388 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9389 | } |
| 9390 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9391 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9392 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9393 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9395 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9396 | + mBlurSurface + ": CREATE"); |
| 9397 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9398 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9399 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9400 | -1, 16, 16, |
| 9401 | PixelFormat.OPAQUE, |
| 9402 | Surface.FX_SURFACE_BLUR); |
| 9403 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9404 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9405 | } |
| 9406 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9407 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9408 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9409 | + mBlurSurface + ": pos=(0,0) (" + |
| 9410 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9411 | mBlurSurface.setPosition(0, 0); |
| 9412 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9413 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9414 | if (!mBlurShown) { |
| 9415 | try { |
| 9416 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9417 | + mBlurSurface + ": SHOW"); |
| 9418 | mBlurSurface.show(); |
| 9419 | } catch (RuntimeException e) { |
| 9420 | Slog.w(TAG, "Failure showing blur surface", e); |
| 9421 | } |
| 9422 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9423 | } |
| 9424 | } |
| 9425 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9426 | } |
| 9427 | } |
| 9428 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9429 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9430 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9431 | // This is the wallpaper target and its obscured state |
| 9432 | // changed... make sure the current wallaper's visibility |
| 9433 | // has been updated accordingly. |
| 9434 | updateWallpaperVisibilityLocked(); |
| 9435 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9436 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9437 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9438 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9439 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9440 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9441 | try { |
| 9442 | mBackgroundFillerSurface.hide(); |
| 9443 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9444 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9445 | } |
| 9446 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9447 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9448 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9449 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 9450 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9451 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9453 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9454 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9455 | + ": HIDE"); |
| 9456 | try { |
| 9457 | mBlurSurface.hide(); |
| 9458 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9459 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9460 | } |
| 9461 | mBlurShown = false; |
| 9462 | } |
| 9463 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9464 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9465 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9466 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9467 | } |
| 9468 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9469 | mInputMonitor.updateInputWindowsLw(); |
| 9470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9471 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9472 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9473 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9474 | "With display frozen, orientationChangeComplete=" |
| 9475 | + orientationChangeComplete); |
| 9476 | if (orientationChangeComplete) { |
| 9477 | if (mWindowsFreezingScreen) { |
| 9478 | mWindowsFreezingScreen = false; |
| 9479 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9480 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9481 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9482 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | i = mResizingWindows.size(); |
| 9485 | if (i > 0) { |
| 9486 | do { |
| 9487 | i--; |
| 9488 | WindowState win = mResizingWindows.get(i); |
| 9489 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9490 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 9491 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9492 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9493 | boolean configChanged = |
| 9494 | win.mConfiguration != mCurConfiguration |
| 9495 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9496 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 9497 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 9498 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9499 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9500 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9501 | + " / " + mCurConfiguration + " / 0x" |
| 9502 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9503 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9504 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | win.mClient.resized(win.mFrame.width(), |
| 9506 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9507 | win.mLastVisibleInsets, win.mDrawPending, |
| 9508 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9509 | win.mContentInsetsChanged = false; |
| 9510 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9511 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9512 | } catch (RemoteException e) { |
| 9513 | win.mOrientationChanging = false; |
| 9514 | } |
| 9515 | } while (i > 0); |
| 9516 | mResizingWindows.clear(); |
| 9517 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9519 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9520 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9521 | i = mDestroySurface.size(); |
| 9522 | if (i > 0) { |
| 9523 | do { |
| 9524 | i--; |
| 9525 | WindowState win = mDestroySurface.get(i); |
| 9526 | win.mDestroying = false; |
| 9527 | if (mInputMethodWindow == win) { |
| 9528 | mInputMethodWindow = null; |
| 9529 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9530 | if (win == mWallpaperTarget) { |
| 9531 | wallpaperDestroyed = true; |
| 9532 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9533 | win.destroySurfaceLocked(); |
| 9534 | } while (i > 0); |
| 9535 | mDestroySurface.clear(); |
| 9536 | } |
| 9537 | |
| 9538 | // Time to remove any exiting tokens? |
| 9539 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9540 | WindowToken token = mExitingTokens.get(i); |
| 9541 | if (!token.hasVisible) { |
| 9542 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9543 | if (token.windowType == TYPE_WALLPAPER) { |
| 9544 | mWallpaperTokens.remove(token); |
| 9545 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9546 | } |
| 9547 | } |
| 9548 | |
| 9549 | // Time to remove any exiting applications? |
| 9550 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9551 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9552 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9553 | // Make sure there is no animation running on this token, |
| 9554 | // so any windows associated with it will be removed as |
| 9555 | // soon as their animations are complete |
| 9556 | token.animation = null; |
| 9557 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9558 | mAppTokens.remove(token); |
| 9559 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9560 | if (mLastEnterAnimToken == token) { |
| 9561 | mLastEnterAnimToken = null; |
| 9562 | mLastEnterAnimParams = null; |
| 9563 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9564 | } |
| 9565 | } |
| 9566 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9567 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9568 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9569 | if (!animating && mAppTransitionRunning) { |
| 9570 | // We have finished the animation of an app transition. To do |
| 9571 | // this, we have delayed a lot of operations like showing and |
| 9572 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9573 | // reflects the correct Z-order, but the window list may now |
| 9574 | // be out of sync with it. So here we will just rebuild the |
| 9575 | // entire app window list. Fun! |
| 9576 | mAppTransitionRunning = false; |
| 9577 | needRelayout = true; |
| 9578 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9579 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9580 | // Clear information about apps that were moving. |
| 9581 | mToBottomApps.clear(); |
| 9582 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9583 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9584 | if (focusDisplayed) { |
| 9585 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9586 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9587 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9588 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9589 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9590 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9591 | requestAnimationLocked(0); |
| 9592 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9593 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 9594 | } |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9595 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9596 | mInputMonitor.updateInputWindowsLw(); |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9597 | |
| Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 9598 | setHoldScreenLocked(holdScreen != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 9600 | mPowerManager.setScreenBrightnessOverride(-1); |
| 9601 | } else { |
| 9602 | mPowerManager.setScreenBrightnessOverride((int) |
| 9603 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 9604 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9605 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 9606 | mPowerManager.setButtonBrightnessOverride(-1); |
| 9607 | } else { |
| 9608 | mPowerManager.setButtonBrightnessOverride((int) |
| 9609 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 9610 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9611 | if (holdScreen != mHoldingScreenOn) { |
| 9612 | mHoldingScreenOn = holdScreen; |
| 9613 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 9614 | mH.sendMessage(m); |
| 9615 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9616 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9617 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9618 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9619 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 9620 | LocalPowerManager.BUTTON_EVENT, true); |
| 9621 | mTurnOnScreen = false; |
| 9622 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 9623 | |
| 9624 | // Check to see if we are now in a state where the screen should |
| 9625 | // be enabled, because the window obscured flags have changed. |
| 9626 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9627 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9628 | |
| 9629 | /** |
| 9630 | * Must be called with the main window manager lock held. |
| 9631 | */ |
| 9632 | void setHoldScreenLocked(boolean holding) { |
| 9633 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 9634 | if (holding != state) { |
| 9635 | if (holding) { |
| 9636 | mHoldingScreenWakeLock.acquire(); |
| 9637 | } else { |
| 9638 | mPolicy.screenOnStoppedLw(); |
| 9639 | mHoldingScreenWakeLock.release(); |
| 9640 | } |
| 9641 | } |
| 9642 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9643 | |
| 9644 | void requestAnimationLocked(long delay) { |
| 9645 | if (!mAnimationPending) { |
| 9646 | mAnimationPending = true; |
| 9647 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 9648 | } |
| 9649 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9650 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9651 | /** |
| 9652 | * Have the surface flinger show a surface, robustly dealing with |
| 9653 | * error conditions. In particular, if there is not enough memory |
| 9654 | * to show the surface, then we will try to get rid of other surfaces |
| 9655 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9656 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9657 | * @return Returns true if the surface was successfully shown. |
| 9658 | */ |
| 9659 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 9660 | try { |
| 9661 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9662 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9663 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9664 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9665 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9666 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9667 | win.mTurnOnScreen = false; |
| 9668 | mTurnOnScreen = true; |
| 9669 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9670 | } |
| 9671 | return true; |
| 9672 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9673 | 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] | 9674 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9675 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9676 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9677 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9678 | return false; |
| 9679 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9681 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 9682 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9683 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9684 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9685 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9686 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9687 | if (mForceRemoves == null) { |
| 9688 | mForceRemoves = new ArrayList<WindowState>(); |
| 9689 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9690 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9691 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9692 | try { |
| 9693 | // There was some problem... first, do a sanity check of the |
| 9694 | // window list to make sure we haven't left any dangling surfaces |
| 9695 | // around. |
| 9696 | int N = mWindows.size(); |
| 9697 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9698 | 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] | 9699 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9700 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9701 | if (ws.mSurface != null) { |
| 9702 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9703 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9704 | + ws + " surface=" + ws.mSurface |
| 9705 | + " token=" + win.mToken |
| 9706 | + " pid=" + ws.mSession.mPid |
| 9707 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9708 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9709 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9710 | ws.mSurface = null; |
| 9711 | mForceRemoves.add(ws); |
| 9712 | i--; |
| 9713 | N--; |
| 9714 | leakedSurface = true; |
| 9715 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9716 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9717 | + ws + " surface=" + ws.mSurface |
| 9718 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9719 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9720 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9721 | ws.mSurface = null; |
| 9722 | leakedSurface = true; |
| 9723 | } |
| 9724 | } |
| 9725 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9726 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9727 | boolean killedApps = false; |
| 9728 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9729 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9730 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 9731 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9732 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9733 | if (ws.mSurface != null) { |
| 9734 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 9735 | } |
| 9736 | } |
| 9737 | if (pidCandidates.size() > 0) { |
| 9738 | int[] pids = new int[pidCandidates.size()]; |
| 9739 | for (int i=0; i<pids.length; i++) { |
| 9740 | pids[i] = pidCandidates.keyAt(i); |
| 9741 | } |
| 9742 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9743 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9744 | killedApps = true; |
| 9745 | } |
| 9746 | } catch (RemoteException e) { |
| 9747 | } |
| 9748 | } |
| 9749 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9750 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9751 | if (leakedSurface || killedApps) { |
| 9752 | // We managed to reclaim some memory, so get rid of the trouble |
| 9753 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9754 | 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] | 9755 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9756 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9757 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9758 | win.mSurface = null; |
| 9759 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9760 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9761 | try { |
| 9762 | win.mClient.dispatchGetNewSurface(); |
| 9763 | } catch (RemoteException e) { |
| 9764 | } |
| 9765 | } |
| 9766 | } finally { |
| 9767 | Binder.restoreCallingIdentity(callingIdentity); |
| 9768 | } |
| 9769 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9770 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9771 | private boolean updateFocusedWindowLocked(int mode) { |
| 9772 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9773 | if (mCurrentFocus != newFocus) { |
| 9774 | // This check makes sure that we don't already have the focus |
| 9775 | // change message pending. |
| 9776 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9777 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9778 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9779 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9780 | final WindowState oldFocus = mCurrentFocus; |
| 9781 | mCurrentFocus = newFocus; |
| 9782 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9784 | final WindowState imWindow = mInputMethodWindow; |
| 9785 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9786 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9787 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9788 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 9789 | mLayoutNeeded = true; |
| 9790 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9791 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 9792 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9793 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9794 | // Client will do the layout, but we need to assign layers |
| 9795 | // for handleNewWindowLocked() below. |
| 9796 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9797 | } |
| 9798 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9799 | |
| 9800 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9801 | // If we defer assigning layers, then the caller is responsible for |
| 9802 | // doing this part. |
| 9803 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9804 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9805 | return true; |
| 9806 | } |
| 9807 | return false; |
| 9808 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9809 | |
| 9810 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9811 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9812 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9813 | |
| 9814 | private WindowState computeFocusedWindowLocked() { |
| 9815 | WindowState result = null; |
| 9816 | WindowState win; |
| 9817 | |
| 9818 | int i = mWindows.size() - 1; |
| 9819 | int nextAppIndex = mAppTokens.size()-1; |
| 9820 | WindowToken nextApp = nextAppIndex >= 0 |
| 9821 | ? mAppTokens.get(nextAppIndex) : null; |
| 9822 | |
| 9823 | while (i >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9824 | win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9825 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9826 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9827 | TAG, "Looking for focus: " + i |
| 9828 | + " = " + win |
| 9829 | + ", flags=" + win.mAttrs.flags |
| 9830 | + ", canReceive=" + win.canReceiveKeys()); |
| 9831 | |
| 9832 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9834 | // If this window's application has been removed, just skip it. |
| 9835 | if (thisApp != null && thisApp.removed) { |
| 9836 | i--; |
| 9837 | continue; |
| 9838 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9840 | // If there is a focused app, don't allow focus to go to any |
| 9841 | // windows below it. If this is an application window, step |
| 9842 | // through the app tokens until we find its app. |
| 9843 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9844 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9845 | int origAppIndex = nextAppIndex; |
| 9846 | while (nextAppIndex > 0) { |
| 9847 | if (nextApp == mFocusedApp) { |
| 9848 | // Whoops, we are below the focused app... no focus |
| 9849 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9850 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9851 | TAG, "Reached focused app: " + mFocusedApp); |
| 9852 | return null; |
| 9853 | } |
| 9854 | nextAppIndex--; |
| 9855 | nextApp = mAppTokens.get(nextAppIndex); |
| 9856 | if (nextApp == thisApp) { |
| 9857 | break; |
| 9858 | } |
| 9859 | } |
| 9860 | if (thisApp != nextApp) { |
| 9861 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9862 | // happen, but if it does we can get totally hosed... |
| 9863 | // so restart at the original app. |
| 9864 | nextAppIndex = origAppIndex; |
| 9865 | nextApp = mAppTokens.get(nextAppIndex); |
| 9866 | } |
| 9867 | } |
| 9868 | |
| 9869 | // Dispatch to this window if it is wants key events. |
| 9870 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9871 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9872 | TAG, "Found focus @ " + i + " = " + win); |
| 9873 | result = win; |
| 9874 | break; |
| 9875 | } |
| 9876 | |
| 9877 | i--; |
| 9878 | } |
| 9879 | |
| 9880 | return result; |
| 9881 | } |
| 9882 | |
| 9883 | private void startFreezingDisplayLocked() { |
| 9884 | if (mDisplayFrozen) { |
| 9885 | return; |
| 9886 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9887 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9888 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9889 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9890 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9891 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9892 | if (mFreezeGcPending != 0) { |
| 9893 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9894 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9895 | mH.removeMessages(H.FORCE_GC); |
| 9896 | Runtime.getRuntime().gc(); |
| 9897 | mFreezeGcPending = now; |
| 9898 | } |
| 9899 | } else { |
| 9900 | mFreezeGcPending = now; |
| 9901 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9902 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9903 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9904 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9905 | mInputMonitor.freezeInputDispatchingLw(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9906 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9907 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 9908 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9909 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9910 | mAppTransitionReady = true; |
| 9911 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9913 | if (PROFILE_ORIENTATION) { |
| 9914 | File file = new File("/data/system/frozen"); |
| 9915 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9916 | } |
| 9917 | Surface.freezeDisplay(0); |
| 9918 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9920 | private void stopFreezingDisplayLocked() { |
| 9921 | if (!mDisplayFrozen) { |
| 9922 | return; |
| 9923 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9924 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9925 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 9926 | return; |
| 9927 | } |
| 9928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9929 | mDisplayFrozen = false; |
| 9930 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 9931 | if (PROFILE_ORIENTATION) { |
| 9932 | Debug.stopMethodTracing(); |
| 9933 | } |
| 9934 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9935 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9936 | mInputMonitor.thawInputDispatchingLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9937 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 9938 | // While the display is frozen we don't re-compute the orientation |
| 9939 | // to avoid inconsistent states. However, something interesting |
| 9940 | // could have actually changed during that time so re-evaluate it |
| 9941 | // now to catch that. |
| 9942 | if (updateOrientationFromAppTokensLocked()) { |
| 9943 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9944 | } |
| 9945 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9946 | // A little kludge: a lot could have happened while the |
| 9947 | // display was frozen, so now that we are coming back we |
| 9948 | // do a gc so that any remote references the system |
| 9949 | // processes holds on others can be released if they are |
| 9950 | // no longer needed. |
| 9951 | mH.removeMessages(H.FORCE_GC); |
| 9952 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9953 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9955 | mScreenFrozenLock.release(); |
| 9956 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9957 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9958 | @Override |
| 9959 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 9960 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 9961 | != PackageManager.PERMISSION_GRANTED) { |
| 9962 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 9963 | + Binder.getCallingPid() |
| 9964 | + ", uid=" + Binder.getCallingUid()); |
| 9965 | return; |
| 9966 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9967 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9968 | mInputManager.dump(pw); |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 9969 | pw.println(" "); |
| 9970 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9971 | synchronized(mWindowMap) { |
| 9972 | pw.println("Current Window Manager state:"); |
| 9973 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9974 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9975 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 9976 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9977 | w.dump(pw, " "); |
| 9978 | } |
| 9979 | if (mInputMethodDialogs.size() > 0) { |
| 9980 | pw.println(" "); |
| 9981 | pw.println(" Input method dialogs:"); |
| 9982 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 9983 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9984 | 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] | 9985 | } |
| 9986 | } |
| 9987 | if (mPendingRemove.size() > 0) { |
| 9988 | pw.println(" "); |
| 9989 | pw.println(" Remove pending for:"); |
| 9990 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 9991 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9992 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 9993 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9994 | w.dump(pw, " "); |
| 9995 | } |
| 9996 | } |
| 9997 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 9998 | pw.println(" "); |
| 9999 | pw.println(" Windows force removing:"); |
| 10000 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10001 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10002 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10003 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10004 | w.dump(pw, " "); |
| 10005 | } |
| 10006 | } |
| 10007 | if (mDestroySurface.size() > 0) { |
| 10008 | pw.println(" "); |
| 10009 | pw.println(" Windows waiting to destroy their surface:"); |
| 10010 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10011 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10012 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10013 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10014 | w.dump(pw, " "); |
| 10015 | } |
| 10016 | } |
| 10017 | if (mLosingFocus.size() > 0) { |
| 10018 | pw.println(" "); |
| 10019 | pw.println(" Windows losing focus:"); |
| 10020 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10021 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10022 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10023 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10024 | w.dump(pw, " "); |
| 10025 | } |
| 10026 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10027 | if (mResizingWindows.size() > 0) { |
| 10028 | pw.println(" "); |
| 10029 | pw.println(" Windows waiting to resize:"); |
| 10030 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10031 | WindowState w = mResizingWindows.get(i); |
| 10032 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10033 | pw.print(w); pw.println(":"); |
| 10034 | w.dump(pw, " "); |
| 10035 | } |
| 10036 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10037 | if (mSessions.size() > 0) { |
| 10038 | pw.println(" "); |
| 10039 | pw.println(" All active sessions:"); |
| 10040 | Iterator<Session> it = mSessions.iterator(); |
| 10041 | while (it.hasNext()) { |
| 10042 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10043 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10044 | s.dump(pw, " "); |
| 10045 | } |
| 10046 | } |
| 10047 | if (mTokenMap.size() > 0) { |
| 10048 | pw.println(" "); |
| 10049 | pw.println(" All tokens:"); |
| 10050 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10051 | while (it.hasNext()) { |
| 10052 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10053 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10054 | token.dump(pw, " "); |
| 10055 | } |
| 10056 | } |
| 10057 | if (mTokenList.size() > 0) { |
| 10058 | pw.println(" "); |
| 10059 | pw.println(" Window token list:"); |
| 10060 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10061 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10062 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10063 | } |
| 10064 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10065 | if (mWallpaperTokens.size() > 0) { |
| 10066 | pw.println(" "); |
| 10067 | pw.println(" Wallpaper tokens:"); |
| 10068 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10069 | WindowToken token = mWallpaperTokens.get(i); |
| 10070 | pw.print(" Wallpaper #"); pw.print(i); |
| 10071 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10072 | token.dump(pw, " "); |
| 10073 | } |
| 10074 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10075 | if (mAppTokens.size() > 0) { |
| 10076 | pw.println(" "); |
| 10077 | pw.println(" Application tokens in Z order:"); |
| 10078 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10079 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10080 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10081 | } |
| 10082 | } |
| 10083 | if (mFinishedStarting.size() > 0) { |
| 10084 | pw.println(" "); |
| 10085 | pw.println(" Finishing start of application tokens:"); |
| 10086 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10087 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10088 | pw.print(" Finished Starting #"); pw.print(i); |
| 10089 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10090 | token.dump(pw, " "); |
| 10091 | } |
| 10092 | } |
| 10093 | if (mExitingTokens.size() > 0) { |
| 10094 | pw.println(" "); |
| 10095 | pw.println(" Exiting tokens:"); |
| 10096 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10097 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10098 | pw.print(" Exiting #"); pw.print(i); |
| 10099 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10100 | token.dump(pw, " "); |
| 10101 | } |
| 10102 | } |
| 10103 | if (mExitingAppTokens.size() > 0) { |
| 10104 | pw.println(" "); |
| 10105 | pw.println(" Exiting application tokens:"); |
| 10106 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10107 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10108 | pw.print(" Exiting App #"); pw.print(i); |
| 10109 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10110 | token.dump(pw, " "); |
| 10111 | } |
| 10112 | } |
| 10113 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10114 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10115 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10116 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10117 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10118 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10119 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10120 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10121 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10122 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10123 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10124 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10125 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10126 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10127 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10128 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10129 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10130 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10131 | if (mDimAnimator != null) { |
| 10132 | mDimAnimator.printTo(pw); |
| 10133 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10134 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10135 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10136 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10137 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10138 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10139 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10140 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10141 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10142 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10143 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10144 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10145 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10146 | pw.print(" mRotation="); pw.print(mRotation); |
| 10147 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10148 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10149 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10150 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10151 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10152 | pw.print(" mNextAppTransition=0x"); |
| 10153 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10154 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10155 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10156 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10157 | if (mNextAppTransitionPackage != null) { |
| 10158 | pw.print(" mNextAppTransitionPackage="); |
| 10159 | pw.print(mNextAppTransitionPackage); |
| 10160 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10161 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10162 | pw.print(", mNextAppTransitionExit=0x"); |
| 10163 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10164 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10165 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10166 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10167 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10168 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10169 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10170 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10171 | if (mOpeningApps.size() > 0) { |
| 10172 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10173 | } |
| 10174 | if (mClosingApps.size() > 0) { |
| 10175 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10176 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10177 | if (mToTopApps.size() > 0) { |
| 10178 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10179 | } |
| 10180 | if (mToBottomApps.size() > 0) { |
| 10181 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10182 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10183 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10184 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10185 | } |
| 10186 | } |
| 10187 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10188 | // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection). |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10189 | public void monitor() { |
| 10190 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10191 | synchronized (mKeyguardTokenWatcher) { } |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10192 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10193 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10194 | /** |
| 10195 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10196 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10197 | */ |
| 10198 | private static class DimAnimator { |
| 10199 | Surface mDimSurface; |
| 10200 | boolean mDimShown = false; |
| 10201 | float mDimCurrentAlpha; |
| 10202 | float mDimTargetAlpha; |
| 10203 | float mDimDeltaPerMs; |
| 10204 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10205 | |
| 10206 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10207 | |
| 10208 | DimAnimator (SurfaceSession session) { |
| 10209 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10210 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10211 | + mDimSurface + ": CREATE"); |
| 10212 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10213 | mDimSurface = new Surface(session, 0, |
| 10214 | "DimSurface", |
| 10215 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10216 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 10217 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10218 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10219 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10220 | } |
| 10221 | } |
| 10222 | } |
| 10223 | |
| 10224 | /** |
| 10225 | * Show the dim surface. |
| 10226 | */ |
| 10227 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10228 | if (!mDimShown) { |
| 10229 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 10230 | dw + "x" + dh + ")"); |
| 10231 | mDimShown = true; |
| 10232 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10233 | mLastDimWidth = dw; |
| 10234 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10235 | mDimSurface.setPosition(0, 0); |
| 10236 | mDimSurface.setSize(dw, dh); |
| 10237 | mDimSurface.show(); |
| 10238 | } catch (RuntimeException e) { |
| 10239 | Slog.w(TAG, "Failure showing dim surface", e); |
| 10240 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10241 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 10242 | mLastDimWidth = dw; |
| 10243 | mLastDimHeight = dh; |
| 10244 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10245 | } |
| 10246 | } |
| 10247 | |
| 10248 | /** |
| 10249 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 10250 | * {@link updateSurface} after all windows are examined. |
| 10251 | */ |
| 10252 | void updateParameters(WindowState w, long currentTime) { |
| 10253 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 10254 | |
| 10255 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10256 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10257 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10258 | if (mDimTargetAlpha != target) { |
| 10259 | // If the desired dim level has changed, then |
| 10260 | // start an animation to it. |
| 10261 | mLastDimAnimTime = currentTime; |
| 10262 | long duration = (w.mAnimating && w.mAnimation != null) |
| 10263 | ? w.mAnimation.computeDurationHint() |
| 10264 | : DEFAULT_DIM_DURATION; |
| 10265 | if (target > mDimTargetAlpha) { |
| 10266 | // This is happening behind the activity UI, |
| 10267 | // so we can make it run a little longer to |
| 10268 | // give a stronger impression without disrupting |
| 10269 | // the user. |
| 10270 | duration *= DIM_DURATION_MULTIPLIER; |
| 10271 | } |
| 10272 | if (duration < 1) { |
| 10273 | // Don't divide by zero |
| 10274 | duration = 1; |
| 10275 | } |
| 10276 | mDimTargetAlpha = target; |
| 10277 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10278 | } |
| 10279 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10280 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10281 | /** |
| 10282 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10283 | * false when the animation is finished and the dim surface is hidden. |
| 10284 | */ |
| 10285 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10286 | if (!dimming) { |
| 10287 | if (mDimTargetAlpha != 0) { |
| 10288 | mLastDimAnimTime = currentTime; |
| 10289 | mDimTargetAlpha = 0; |
| 10290 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10291 | } |
| 10292 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10293 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10294 | boolean animating = false; |
| 10295 | if (mLastDimAnimTime != 0) { |
| 10296 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10297 | * (currentTime-mLastDimAnimTime); |
| 10298 | boolean more = true; |
| 10299 | if (displayFrozen) { |
| 10300 | // If the display is frozen, there is no reason to animate. |
| 10301 | more = false; |
| 10302 | } else if (mDimDeltaPerMs > 0) { |
| 10303 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10304 | more = false; |
| 10305 | } |
| 10306 | } else if (mDimDeltaPerMs < 0) { |
| 10307 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10308 | more = false; |
| 10309 | } |
| 10310 | } else { |
| 10311 | more = false; |
| 10312 | } |
| 10313 | |
| 10314 | // Do we need to continue animating? |
| 10315 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10316 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10317 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10318 | mLastDimAnimTime = currentTime; |
| 10319 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10320 | animating = true; |
| 10321 | } else { |
| 10322 | mDimCurrentAlpha = mDimTargetAlpha; |
| 10323 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10324 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10325 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 10326 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10327 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10328 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10329 | + ": HIDE"); |
| 10330 | try { |
| 10331 | mDimSurface.hide(); |
| 10332 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10333 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10334 | } |
| 10335 | mDimShown = false; |
| 10336 | } |
| 10337 | } |
| 10338 | } |
| 10339 | return animating; |
| 10340 | } |
| 10341 | |
| 10342 | public void printTo(PrintWriter pw) { |
| 10343 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 10344 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 10345 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 10346 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 10347 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 10348 | } |
| 10349 | } |
| 10350 | |
| 10351 | /** |
| 10352 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 10353 | * This is used for opening/closing transition for apps in compatible mode. |
| 10354 | */ |
| 10355 | private static class FadeInOutAnimation extends Animation { |
| 10356 | int mWidth; |
| 10357 | boolean mFadeIn; |
| 10358 | |
| 10359 | public FadeInOutAnimation(boolean fadeIn) { |
| 10360 | setInterpolator(new AccelerateInterpolator()); |
| 10361 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 10362 | mFadeIn = fadeIn; |
| 10363 | } |
| 10364 | |
| 10365 | @Override |
| 10366 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 10367 | float x = interpolatedTime; |
| 10368 | if (!mFadeIn) { |
| 10369 | x = 1.0f - x; // reverse the interpolation for fade out |
| 10370 | } |
| 10371 | if (x < 0.5) { |
| 10372 | // move the window out of the screen. |
| 10373 | t.getMatrix().setTranslate(mWidth, 0); |
| 10374 | } else { |
| 10375 | t.getMatrix().setTranslate(0, 0);// show |
| 10376 | t.setAlpha((x - 0.5f) * 2); |
| 10377 | } |
| 10378 | } |
| 10379 | |
| 10380 | @Override |
| 10381 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 10382 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 10383 | mWidth = width; |
| 10384 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10385 | |
| 10386 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 10387 | public int getZAdjustment() { |
| 10388 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10389 | } |
| 10390 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10391 | } |