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 | 46b9ac0 | 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 | 46b9ac0 | 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; |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 158 | static final boolean DEBUG_FREEZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 160 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 161 | static final boolean MEASURE_LATENCY = false; |
| 162 | static private LatencyTimer lt; |
| 163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | static final boolean PROFILE_ORIENTATION = false; |
| 165 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 166 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | /** How much to multiply the policy's type layer, to reserve room |
| 169 | * for multiple windows of the same type and Z-ordering adjustment |
| 170 | * with TYPE_LAYER_OFFSET. */ |
| 171 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 174 | * or below others in the same layer. */ |
| 175 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** How much to increment the layer for each window, to reserve room |
| 178 | * for effect surfaces between them. |
| 179 | */ |
| 180 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** The maximum length we will accept for a loaded animation duration: |
| 183 | * this is 10 seconds. |
| 184 | */ |
| 185 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 186 | |
| 187 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 188 | * value to another, when no window animation is driving it. |
| 189 | */ |
| 190 | static final int DEFAULT_DIM_DURATION = 200; |
| 191 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 192 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 193 | * compatible windows. |
| 194 | */ |
| 195 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 198 | */ |
| 199 | static final int DIM_DURATION_MULTIPLIER = 6; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 200 | |
| 201 | // Maximum number of milliseconds to wait for input event injection. |
| 202 | // FIXME is this value reasonable? |
| 203 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 204 | |
| 205 | // Default input dispatching timeout in nanoseconds. |
| 206 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 209 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 210 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 211 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 214 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 218 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 219 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 220 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 222 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 224 | private static final int ALLOW_DISABLE_YES = 1; |
| 225 | private static final int ALLOW_DISABLE_NO = 0; |
| 226 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 227 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 228 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 229 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 230 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 232 | if (shouldAllowDisableKeyguard()) { |
| 233 | mPolicy.enableKeyguard(false); |
| 234 | mKeyguardDisabled = true; |
| 235 | } else { |
| 236 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 237 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | } |
| 239 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 240 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 241 | synchronized (mKeyguardTokenWatcher) { |
| 242 | mKeyguardDisabled = false; |
| 243 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | }; |
| 247 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 248 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 249 | @Override |
| 250 | public void onReceive(Context context, Intent intent) { |
| 251 | mPolicy.enableKeyguard(true); |
| 252 | synchronized(mKeyguardTokenWatcher) { |
| 253 | // lazily evaluate this next time we're asked to disable keyguard |
| 254 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 255 | mKeyguardDisabled = false; |
| 256 | } |
| 257 | } |
| 258 | }; |
| 259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | final Context mContext; |
| 261 | |
| 262 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 267 | |
| 268 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | /** |
| 273 | * All currently active sessions with clients. |
| 274 | */ |
| 275 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | /** |
| 278 | * Mapping from an IWindow IBinder to the server's Window object. |
| 279 | * This is also used as the lock for all of our state. |
| 280 | */ |
| 281 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 282 | |
| 283 | /** |
| 284 | * Mapping from a token IBinder to a WindowToken object. |
| 285 | */ |
| 286 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 287 | new HashMap<IBinder, WindowToken>(); |
| 288 | |
| 289 | /** |
| 290 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 291 | * over them. |
| 292 | */ |
| 293 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | /** |
| 296 | * Window tokens that are in the process of exiting, but still |
| 297 | * on screen for animations. |
| 298 | */ |
| 299 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 300 | |
| 301 | /** |
| 302 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 303 | * controlling the ordering of windows in different applications. This |
| 304 | * contains WindowToken objects. |
| 305 | */ |
| 306 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 307 | |
| 308 | /** |
| 309 | * Application tokens that are in the process of exiting, but still |
| 310 | * on screen for animations. |
| 311 | */ |
| 312 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 313 | |
| 314 | /** |
| 315 | * List of window tokens that have finished starting their application, |
| 316 | * and now need to have the policy remove their windows. |
| 317 | */ |
| 318 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 319 | |
| 320 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 321 | * This was the app token that was used to retrieve the last enter |
| 322 | * animation. It will be used for the next exit animation. |
| 323 | */ |
| 324 | AppWindowToken mLastEnterAnimToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 325 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 326 | /** |
| 327 | * These were the layout params used to retrieve the last enter animation. |
| 328 | * They will be used for the next exit animation. |
| 329 | */ |
| 330 | LayoutParams mLastEnterAnimParams; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 331 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 332 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | * Z-ordered (bottom-most first) list of all Window objects. |
| 334 | */ |
| 335 | final ArrayList mWindows = new ArrayList(); |
| 336 | |
| 337 | /** |
| 338 | * Windows that are being resized. Used so we can tell the client about |
| 339 | * the resize after closing the transaction in which we resized the |
| 340 | * underlying surface. |
| 341 | */ |
| 342 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 343 | |
| 344 | /** |
| 345 | * Windows whose animations have ended and now must be removed. |
| 346 | */ |
| 347 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 348 | |
| 349 | /** |
| 350 | * Windows whose surface should be destroyed. |
| 351 | */ |
| 352 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 353 | |
| 354 | /** |
| 355 | * Windows that have lost input focus and are waiting for the new |
| 356 | * focus window to be displayed before they are told about this. |
| 357 | */ |
| 358 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 359 | |
| 360 | /** |
| 361 | * This is set when we have run out of memory, and will either be an empty |
| 362 | * list or contain windows that need to be force removed. |
| 363 | */ |
| 364 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 369 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | Surface mBlurSurface; |
| 371 | boolean mBlurShown; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | final float[] mTmpFloats = new float[9]; |
| 376 | |
| 377 | boolean mSafeMode; |
| 378 | boolean mDisplayEnabled = false; |
| 379 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 380 | int mInitialDisplayWidth = 0; |
| 381 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | int mRotation = 0; |
| 383 | int mRequestedRotation = 0; |
| 384 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 385 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | ArrayList<IRotationWatcher> mRotationWatchers |
| 387 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | boolean mLayoutNeeded = true; |
| 390 | boolean mAnimationPending = false; |
| 391 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 392 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | boolean mWindowsFreezingScreen = false; |
| 394 | long mFreezeGcPending = 0; |
| 395 | int mAppsFreezingScreen = 0; |
| 396 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 397 | int mLayoutSeq = 0; |
| 398 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 399 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 400 | boolean mFocusMayChange; |
| 401 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 402 | Configuration mCurConfiguration = new Configuration(); |
| 403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | // This is held as long as we have the screen frozen, to give us time to |
| 405 | // perform a rotation animation when turning off shows the lock screen which |
| 406 | // changes the orientation. |
| 407 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | // State management of app transitions. When we are preparing for a |
| 410 | // transition, mNextAppTransition will be the kind of transition to |
| 411 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 412 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 413 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 414 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 415 | String mNextAppTransitionPackage; |
| 416 | int mNextAppTransitionEnter; |
| 417 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 419 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | boolean mAppTransitionTimeout = false; |
| 421 | boolean mStartingIconInTransition = false; |
| 422 | boolean mSkipAppTransitionAnimation = false; |
| 423 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 424 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 425 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 426 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | H mH = new H(); |
| 431 | |
| 432 | WindowState mCurrentFocus = null; |
| 433 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | // This just indicates the window the input method is on top of, not |
| 436 | // necessarily the window its input is going to. |
| 437 | WindowState mInputMethodTarget = null; |
| 438 | WindowState mUpcomingInputMethodTarget = null; |
| 439 | boolean mInputMethodTargetWaitingAnim; |
| 440 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | WindowState mInputMethodWindow = null; |
| 443 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 444 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 445 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 446 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 447 | // If non-null, this is the currently visible window that is associated |
| 448 | // with the wallpaper. |
| 449 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 450 | // If non-null, we are in the middle of animating from one wallpaper target |
| 451 | // to another, and this is the lower one in Z-order. |
| 452 | WindowState mLowerWallpaperTarget = null; |
| 453 | // If non-null, we are in the middle of animating from one wallpaper target |
| 454 | // to another, and this is the higher one in Z-order. |
| 455 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 456 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 457 | float mLastWallpaperX = -1; |
| 458 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 459 | float mLastWallpaperXStep = -1; |
| 460 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 461 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 462 | // changing its scroll position. |
| 463 | WindowState mWaitingOnWallpaper; |
| 464 | // The last time we had a timeout when waiting for a wallpaper. |
| 465 | long mLastWallpaperTimeoutTime; |
| 466 | // We give a wallpaper up to 150ms to finish scrolling. |
| 467 | static final long WALLPAPER_TIMEOUT = 150; |
| 468 | // Time we wait after a timeout before trying to wait again. |
| 469 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | AppWindowToken mFocusedApp = null; |
| 472 | |
| 473 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | float mWindowAnimationScale = 1.0f; |
| 476 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 477 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 478 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | |
| 480 | // Who is holding the screen on. |
| 481 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 482 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 483 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 484 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | /** |
| 487 | * Whether the UI is currently running in touch mode (not showing |
| 488 | * navigational focus because the user is directly pressing the screen). |
| 489 | */ |
| 490 | boolean mInTouchMode = false; |
| 491 | |
| 492 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 493 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 494 | new ArrayList<WindowChangeListener>(); |
| 495 | private boolean mWindowsChanged = false; |
| 496 | |
| 497 | public interface WindowChangeListener { |
| 498 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 499 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 500 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 502 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 503 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 504 | |
| 505 | // The frame use to limit the size of the app running in compatibility mode. |
| 506 | Rect mCompatibleScreenFrame = new Rect(); |
| 507 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 508 | Surface mBackgroundFillerSurface = null; |
| 509 | boolean mBackgroundFillerShown = false; |
| 510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | public static WindowManagerService main(Context context, |
| 512 | PowerManagerService pm, boolean haveInputMethods) { |
| 513 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 514 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | synchronized (thr) { |
| 517 | while (thr.mService == null) { |
| 518 | try { |
| 519 | thr.wait(); |
| 520 | } catch (InterruptedException e) { |
| 521 | } |
| 522 | } |
| 523 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | return thr.mService; |
| 526 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | static class WMThread extends Thread { |
| 529 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | private final Context mContext; |
| 532 | private final PowerManagerService mPM; |
| 533 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | public WMThread(Context context, PowerManagerService pm, |
| 536 | boolean haveInputMethods) { |
| 537 | super("WindowManager"); |
| 538 | mContext = context; |
| 539 | mPM = pm; |
| 540 | mHaveInputMethods = haveInputMethods; |
| 541 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | public void run() { |
| 544 | Looper.prepare(); |
| 545 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 546 | mHaveInputMethods); |
| 547 | android.os.Process.setThreadPriority( |
| 548 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 549 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | synchronized (this) { |
| 552 | mService = s; |
| 553 | notifyAll(); |
| 554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | Looper.loop(); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | static class PolicyThread extends Thread { |
| 561 | private final WindowManagerPolicy mPolicy; |
| 562 | private final WindowManagerService mService; |
| 563 | private final Context mContext; |
| 564 | private final PowerManagerService mPM; |
| 565 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | public PolicyThread(WindowManagerPolicy policy, |
| 568 | WindowManagerService service, Context context, |
| 569 | PowerManagerService pm) { |
| 570 | super("WindowManagerPolicy"); |
| 571 | mPolicy = policy; |
| 572 | mService = service; |
| 573 | mContext = context; |
| 574 | mPM = pm; |
| 575 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | public void run() { |
| 578 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 579 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 582 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | android.os.Process.setThreadPriority( |
| 584 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 585 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | synchronized (this) { |
| 589 | mRunning = true; |
| 590 | notifyAll(); |
| 591 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | Looper.loop(); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | private WindowManagerService(Context context, PowerManagerService pm, |
| 598 | boolean haveInputMethods) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 599 | if (MEASURE_LATENCY) { |
| 600 | lt = new LatencyTimer(100, 1000); |
| 601 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | mContext = context; |
| 604 | mHaveInputMethods = haveInputMethods; |
| 605 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 606 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | mPowerManager = pm; |
| 609 | mPowerManager.setPolicy(mPolicy); |
| 610 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 611 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 612 | "SCREEN_FROZEN"); |
| 613 | mScreenFrozenLock.setReferenceCounted(false); |
| 614 | |
| 615 | mActivityManager = ActivityManagerNative.getDefault(); |
| 616 | mBatteryStats = BatteryStatsService.getService(); |
| 617 | |
| 618 | // Get persisted window scale setting |
| 619 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 620 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 621 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 622 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 623 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 624 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 625 | IntentFilter filter = new IntentFilter(); |
| 626 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 627 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 628 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 629 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 630 | "KEEP_SCREEN_ON_FLAG"); |
| 631 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 633 | mInputManager = new InputManager(context, this, pmc, mPowerManager); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 636 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | synchronized (thr) { |
| 639 | while (!thr.mRunning) { |
| 640 | try { |
| 641 | thr.wait(); |
| 642 | } catch (InterruptedException e) { |
| 643 | } |
| 644 | } |
| 645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 646 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 647 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | // Add ourself to the Watchdog monitors. |
| 650 | Watchdog.getInstance().addMonitor(this); |
| 651 | } |
| 652 | |
| 653 | @Override |
| 654 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 655 | throws RemoteException { |
| 656 | try { |
| 657 | return super.onTransact(code, data, reply, flags); |
| 658 | } catch (RuntimeException e) { |
| 659 | // The window manager only throws security exceptions, so let's |
| 660 | // log all others. |
| 661 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 662 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } |
| 664 | throw e; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | private void placeWindowAfter(Object pos, WindowState window) { |
| 669 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 670 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | TAG, "Adding window " + window + " at " |
| 672 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 673 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 674 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | private void placeWindowBefore(Object pos, WindowState window) { |
| 678 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 679 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 680 | TAG, "Adding window " + window + " at " |
| 681 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 682 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 683 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | //This method finds out the index of a window that has the same app token as |
| 687 | //win. used for z ordering the windows in mWindows |
| 688 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 689 | //use a local variable to cache mWindows |
| 690 | ArrayList localmWindows = mWindows; |
| 691 | int jmax = localmWindows.size(); |
| 692 | if(jmax == 0) { |
| 693 | return -1; |
| 694 | } |
| 695 | for(int j = (jmax-1); j >= 0; j--) { |
| 696 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 697 | if(wentry.mAppToken == win.mAppToken) { |
| 698 | return j; |
| 699 | } |
| 700 | } |
| 701 | return -1; |
| 702 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 705 | final IWindow client = win.mClient; |
| 706 | final WindowToken token = win.mToken; |
| 707 | final ArrayList localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | final int N = localmWindows.size(); |
| 710 | final WindowState attached = win.mAttachedWindow; |
| 711 | int i; |
| 712 | if (attached == null) { |
| 713 | int tokenWindowsPos = token.windows.size(); |
| 714 | if (token.appWindowToken != null) { |
| 715 | int index = tokenWindowsPos-1; |
| 716 | if (index >= 0) { |
| 717 | // If this application has existing windows, we |
| 718 | // simply place the new window on top of them... but |
| 719 | // keep the starting window on top. |
| 720 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 721 | // Base windows go behind everything else. |
| 722 | placeWindowBefore(token.windows.get(0), win); |
| 723 | tokenWindowsPos = 0; |
| 724 | } else { |
| 725 | AppWindowToken atoken = win.mAppToken; |
| 726 | if (atoken != null && |
| 727 | token.windows.get(index) == atoken.startingWindow) { |
| 728 | placeWindowBefore(token.windows.get(index), win); |
| 729 | tokenWindowsPos--; |
| 730 | } else { |
| 731 | int newIdx = findIdxBasedOnAppTokens(win); |
| 732 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 733 | //there is a window above this one associated with the same |
| 734 | //apptoken note that the window could be a floating window |
| 735 | //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] | 736 | //windows associated with this token. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 737 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 738 | TAG, "Adding window " + win + " at " |
| 739 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 741 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 742 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 746 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | TAG, "Figuring out where to add app window " |
| 748 | + client.asBinder() + " (token=" + token + ")"); |
| 749 | // Figure out where the window should go, based on the |
| 750 | // order of applications. |
| 751 | final int NA = mAppTokens.size(); |
| 752 | Object pos = null; |
| 753 | for (i=NA-1; i>=0; i--) { |
| 754 | AppWindowToken t = mAppTokens.get(i); |
| 755 | if (t == token) { |
| 756 | i--; |
| 757 | break; |
| 758 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 759 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 760 | // We haven't reached the token yet; if this token |
| 761 | // is not going to the bottom and has windows, we can |
| 762 | // use it as an anchor for when we do reach the token. |
| 763 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | pos = t.windows.get(0); |
| 765 | } |
| 766 | } |
| 767 | // We now know the index into the apps. If we found |
| 768 | // an app window above, that gives us the position; else |
| 769 | // we need to look some more. |
| 770 | if (pos != null) { |
| 771 | // Move behind any windows attached to this one. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 772 | WindowToken atoken = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 774 | if (atoken != null) { |
| 775 | final int NC = atoken.windows.size(); |
| 776 | if (NC > 0) { |
| 777 | WindowState bottom = atoken.windows.get(0); |
| 778 | if (bottom.mSubLayer < 0) { |
| 779 | pos = bottom; |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | placeWindowBefore(pos, win); |
| 784 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 785 | // Continue looking down until we find the first |
| 786 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | while (i >= 0) { |
| 788 | AppWindowToken t = mAppTokens.get(i); |
| 789 | final int NW = t.windows.size(); |
| 790 | if (NW > 0) { |
| 791 | pos = t.windows.get(NW-1); |
| 792 | break; |
| 793 | } |
| 794 | i--; |
| 795 | } |
| 796 | if (pos != null) { |
| 797 | // Move in front of any windows attached to this |
| 798 | // one. |
| 799 | WindowToken atoken = |
| 800 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 801 | if (atoken != null) { |
| 802 | final int NC = atoken.windows.size(); |
| 803 | if (NC > 0) { |
| 804 | WindowState top = atoken.windows.get(NC-1); |
| 805 | if (top.mSubLayer >= 0) { |
| 806 | pos = top; |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | placeWindowAfter(pos, win); |
| 811 | } else { |
| 812 | // Just search for the start of this layer. |
| 813 | final int myLayer = win.mBaseLayer; |
| 814 | for (i=0; i<N; i++) { |
| 815 | WindowState w = (WindowState)localmWindows.get(i); |
| 816 | if (w.mBaseLayer > myLayer) { |
| 817 | break; |
| 818 | } |
| 819 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 820 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 821 | TAG, "Adding window " + win + " at " |
| 822 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 824 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | } |
| 828 | } else { |
| 829 | // Figure out where window should go, based on layer. |
| 830 | final int myLayer = win.mBaseLayer; |
| 831 | for (i=N-1; i>=0; i--) { |
| 832 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 833 | i++; |
| 834 | break; |
| 835 | } |
| 836 | } |
| 837 | if (i < 0) i = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 838 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 839 | TAG, "Adding window " + win + " at " |
| 840 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 842 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | } |
| 844 | if (addToToken) { |
| 845 | token.windows.add(tokenWindowsPos, win); |
| 846 | } |
| 847 | |
| 848 | } else { |
| 849 | // Figure out this window's ordering relative to the window |
| 850 | // it is attached to. |
| 851 | final int NA = token.windows.size(); |
| 852 | final int sublayer = win.mSubLayer; |
| 853 | int largestSublayer = Integer.MIN_VALUE; |
| 854 | WindowState windowWithLargestSublayer = null; |
| 855 | for (i=0; i<NA; i++) { |
| 856 | WindowState w = token.windows.get(i); |
| 857 | final int wSublayer = w.mSubLayer; |
| 858 | if (wSublayer >= largestSublayer) { |
| 859 | largestSublayer = wSublayer; |
| 860 | windowWithLargestSublayer = w; |
| 861 | } |
| 862 | if (sublayer < 0) { |
| 863 | // For negative sublayers, we go below all windows |
| 864 | // in the same sublayer. |
| 865 | if (wSublayer >= sublayer) { |
| 866 | if (addToToken) { |
| 867 | token.windows.add(i, win); |
| 868 | } |
| 869 | placeWindowBefore( |
| 870 | wSublayer >= 0 ? attached : w, win); |
| 871 | break; |
| 872 | } |
| 873 | } else { |
| 874 | // For positive sublayers, we go above all windows |
| 875 | // in the same sublayer. |
| 876 | if (wSublayer > sublayer) { |
| 877 | if (addToToken) { |
| 878 | token.windows.add(i, win); |
| 879 | } |
| 880 | placeWindowBefore(w, win); |
| 881 | break; |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | if (i >= NA) { |
| 886 | if (addToToken) { |
| 887 | token.windows.add(win); |
| 888 | } |
| 889 | if (sublayer < 0) { |
| 890 | placeWindowBefore(attached, win); |
| 891 | } else { |
| 892 | placeWindowAfter(largestSublayer >= 0 |
| 893 | ? windowWithLargestSublayer |
| 894 | : attached, |
| 895 | win); |
| 896 | } |
| 897 | } |
| 898 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | if (win.mAppToken != null && addToToken) { |
| 901 | win.mAppToken.allAppWindows.add(win); |
| 902 | } |
| 903 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | static boolean canBeImeTarget(WindowState w) { |
| 906 | final int fl = w.mAttrs.flags |
| 907 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 908 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 909 | return w.isVisibleOrAdding(); |
| 910 | } |
| 911 | return false; |
| 912 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 915 | final ArrayList localmWindows = mWindows; |
| 916 | final int N = localmWindows.size(); |
| 917 | WindowState w = null; |
| 918 | int i = N; |
| 919 | while (i > 0) { |
| 920 | i--; |
| 921 | w = (WindowState)localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 922 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 923 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | // + Integer.toHexString(w.mAttrs.flags)); |
| 925 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 926 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | // Yet more tricksyness! If this window is a "starting" |
| 929 | // window, we do actually want to be on top of it, but |
| 930 | // it is not -really- where input will go. So if the caller |
| 931 | // is not actually looking to move the IME, look down below |
| 932 | // for a real window to target... |
| 933 | if (!willMove |
| 934 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 935 | && i > 0) { |
| 936 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 937 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 938 | i--; |
| 939 | w = wb; |
| 940 | } |
| 941 | } |
| 942 | break; |
| 943 | } |
| 944 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 947 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 948 | 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] | 949 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | if (willMove && w != null) { |
| 952 | final WindowState curTarget = mInputMethodTarget; |
| 953 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 954 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | // Now some fun for dealing with window animations that |
| 956 | // modify the Z order. We need to look at all windows below |
| 957 | // the current target that are in this app, finding the highest |
| 958 | // visible one in layering. |
| 959 | AppWindowToken token = curTarget.mAppToken; |
| 960 | WindowState highestTarget = null; |
| 961 | int highestPos = 0; |
| 962 | if (token.animating || token.animation != null) { |
| 963 | int pos = 0; |
| 964 | pos = localmWindows.indexOf(curTarget); |
| 965 | while (pos >= 0) { |
| 966 | WindowState win = (WindowState)localmWindows.get(pos); |
| 967 | if (win.mAppToken != token) { |
| 968 | break; |
| 969 | } |
| 970 | if (!win.mRemoved) { |
| 971 | if (highestTarget == null || win.mAnimLayer > |
| 972 | highestTarget.mAnimLayer) { |
| 973 | highestTarget = win; |
| 974 | highestPos = pos; |
| 975 | } |
| 976 | } |
| 977 | pos--; |
| 978 | } |
| 979 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 982 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | + mNextAppTransition + " " + highestTarget |
| 984 | + " animating=" + highestTarget.isAnimating() |
| 985 | + " layer=" + highestTarget.mAnimLayer |
| 986 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 987 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 988 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | // If we are currently setting up for an animation, |
| 990 | // hold everything until we can find out what will happen. |
| 991 | mInputMethodTargetWaitingAnim = true; |
| 992 | mInputMethodTarget = highestTarget; |
| 993 | return highestPos + 1; |
| 994 | } else if (highestTarget.isAnimating() && |
| 995 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 996 | // If the window we are currently targeting is involved |
| 997 | // with an animation, and it is on top of the next target |
| 998 | // we will be over, then hold off on moving until |
| 999 | // that is done. |
| 1000 | mInputMethodTarget = highestTarget; |
| 1001 | return highestPos + 1; |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1006 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1007 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | if (w != null) { |
| 1009 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1010 | if (DEBUG_INPUT_METHOD) { |
| 1011 | RuntimeException e = null; |
| 1012 | if (!HIDE_STACK_CRAWLS) { |
| 1013 | e = new RuntimeException(); |
| 1014 | e.fillInStackTrace(); |
| 1015 | } |
| 1016 | Slog.w(TAG, "Moving IM target from " |
| 1017 | + mInputMethodTarget + " to " + w, e); |
| 1018 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | mInputMethodTarget = w; |
| 1020 | if (w.mAppToken != null) { |
| 1021 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1022 | } else { |
| 1023 | setInputMethodAnimLayerAdjustment(0); |
| 1024 | } |
| 1025 | } |
| 1026 | return i+1; |
| 1027 | } |
| 1028 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1029 | if (DEBUG_INPUT_METHOD) { |
| 1030 | RuntimeException e = null; |
| 1031 | if (!HIDE_STACK_CRAWLS) { |
| 1032 | e = new RuntimeException(); |
| 1033 | e.fillInStackTrace(); |
| 1034 | } |
| 1035 | Slog.w(TAG, "Moving IM target from " |
| 1036 | + mInputMethodTarget + " to null", e); |
| 1037 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | mInputMethodTarget = null; |
| 1039 | setInputMethodAnimLayerAdjustment(0); |
| 1040 | } |
| 1041 | return -1; |
| 1042 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1045 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1046 | if (pos >= 0) { |
| 1047 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1048 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1049 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1051 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | moveInputMethodDialogsLocked(pos+1); |
| 1053 | return; |
| 1054 | } |
| 1055 | win.mTargetAppToken = null; |
| 1056 | addWindowToListInOrderLocked(win, true); |
| 1057 | moveInputMethodDialogsLocked(pos); |
| 1058 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1061 | 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] | 1062 | mInputMethodAnimLayerAdjustment = adj; |
| 1063 | WindowState imw = mInputMethodWindow; |
| 1064 | if (imw != null) { |
| 1065 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1066 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | + " anim layer: " + imw.mAnimLayer); |
| 1068 | int wi = imw.mChildWindows.size(); |
| 1069 | while (wi > 0) { |
| 1070 | wi--; |
| 1071 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1072 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1073 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | + " anim layer: " + cw.mAnimLayer); |
| 1075 | } |
| 1076 | } |
| 1077 | int di = mInputMethodDialogs.size(); |
| 1078 | while (di > 0) { |
| 1079 | di --; |
| 1080 | imw = mInputMethodDialogs.get(di); |
| 1081 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1082 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | + " anim layer: " + imw.mAnimLayer); |
| 1084 | } |
| 1085 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1088 | int wpos = mWindows.indexOf(win); |
| 1089 | if (wpos >= 0) { |
| 1090 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1091 | 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] | 1092 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1093 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | int NC = win.mChildWindows.size(); |
| 1095 | while (NC > 0) { |
| 1096 | NC--; |
| 1097 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1098 | int cpos = mWindows.indexOf(cw); |
| 1099 | if (cpos >= 0) { |
| 1100 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1101 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1102 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | mWindows.remove(cpos); |
| 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | return interestingPos; |
| 1108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1111 | addWindowToListInOrderLocked(win, false); |
| 1112 | // This is a hack to get all of the child windows added as well |
| 1113 | // at the right position. Child windows should be rare and |
| 1114 | // this case should be rare, so it shouldn't be that big a deal. |
| 1115 | int wpos = mWindows.indexOf(win); |
| 1116 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1117 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1118 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1120 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | reAddWindowLocked(wpos, win); |
| 1122 | } |
| 1123 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | void logWindowList(String prefix) { |
| 1126 | int N = mWindows.size(); |
| 1127 | while (N > 0) { |
| 1128 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1129 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | } |
| 1131 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | void moveInputMethodDialogsLocked(int pos) { |
| 1134 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1137 | 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] | 1138 | for (int i=0; i<N; i++) { |
| 1139 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1140 | } |
| 1141 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1142 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | logWindowList(" "); |
| 1144 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | if (pos >= 0) { |
| 1147 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1148 | if (pos < mWindows.size()) { |
| 1149 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1150 | if (wp == mInputMethodWindow) { |
| 1151 | pos++; |
| 1152 | } |
| 1153 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1154 | 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] | 1155 | for (int i=0; i<N; i++) { |
| 1156 | WindowState win = dialogs.get(i); |
| 1157 | win.mTargetAppToken = targetAppToken; |
| 1158 | pos = reAddWindowLocked(pos, win); |
| 1159 | } |
| 1160 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1161 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1162 | logWindowList(" "); |
| 1163 | } |
| 1164 | return; |
| 1165 | } |
| 1166 | for (int i=0; i<N; i++) { |
| 1167 | WindowState win = dialogs.get(i); |
| 1168 | win.mTargetAppToken = null; |
| 1169 | reAddWindowToListInOrderLocked(win); |
| 1170 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1171 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | logWindowList(" "); |
| 1173 | } |
| 1174 | } |
| 1175 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1178 | final WindowState imWin = mInputMethodWindow; |
| 1179 | final int DN = mInputMethodDialogs.size(); |
| 1180 | if (imWin == null && DN == 0) { |
| 1181 | return false; |
| 1182 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1185 | if (imPos >= 0) { |
| 1186 | // In this case, the input method windows are to be placed |
| 1187 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | // First check to see if the input method windows are already |
| 1190 | // located here, and contiguous. |
| 1191 | final int N = mWindows.size(); |
| 1192 | WindowState firstImWin = imPos < N |
| 1193 | ? (WindowState)mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | // Figure out the actual input method window that should be |
| 1196 | // at the bottom of their stack. |
| 1197 | WindowState baseImWin = imWin != null |
| 1198 | ? imWin : mInputMethodDialogs.get(0); |
| 1199 | if (baseImWin.mChildWindows.size() > 0) { |
| 1200 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1201 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1202 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1204 | if (firstImWin == baseImWin) { |
| 1205 | // The windows haven't moved... but are they still contiguous? |
| 1206 | // First find the top IM window. |
| 1207 | int pos = imPos+1; |
| 1208 | while (pos < N) { |
| 1209 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1210 | break; |
| 1211 | } |
| 1212 | pos++; |
| 1213 | } |
| 1214 | pos++; |
| 1215 | // Now there should be no more input method windows above. |
| 1216 | while (pos < N) { |
| 1217 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1218 | break; |
| 1219 | } |
| 1220 | pos++; |
| 1221 | } |
| 1222 | if (pos >= N) { |
| 1223 | // All is good! |
| 1224 | return false; |
| 1225 | } |
| 1226 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | if (imWin != null) { |
| 1229 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1230 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | logWindowList(" "); |
| 1232 | } |
| 1233 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1234 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1235 | 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] | 1236 | logWindowList(" "); |
| 1237 | } |
| 1238 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1239 | reAddWindowLocked(imPos, imWin); |
| 1240 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1241 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | logWindowList(" "); |
| 1243 | } |
| 1244 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1245 | } else { |
| 1246 | moveInputMethodDialogsLocked(imPos); |
| 1247 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | } else { |
| 1250 | // In this case, the input method windows go in a fixed layer, |
| 1251 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1254 | 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] | 1255 | tmpRemoveWindowLocked(0, imWin); |
| 1256 | imWin.mTargetAppToken = null; |
| 1257 | reAddWindowToListInOrderLocked(imWin); |
| 1258 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1259 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1260 | logWindowList(" "); |
| 1261 | } |
| 1262 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1263 | } else { |
| 1264 | moveInputMethodDialogsLocked(-1);; |
| 1265 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | if (needAssignLayers) { |
| 1270 | assignLayersLocked(); |
| 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 | return true; |
| 1274 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | void adjustInputMethodDialogsLocked() { |
| 1277 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1278 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1279 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1280 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1281 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1282 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1283 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1284 | ? wallpaperTarget.mAppToken.animation : null) |
| 1285 | + " upper=" + mUpperWallpaperTarget |
| 1286 | + " lower=" + mLowerWallpaperTarget); |
| 1287 | return (wallpaperTarget != null |
| 1288 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1289 | && wallpaperTarget.mAppToken.animation != null))) |
| 1290 | || mUpperWallpaperTarget != null |
| 1291 | || mLowerWallpaperTarget != null; |
| 1292 | } |
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 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1295 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1296 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1297 | int adjustWallpaperWindowsLocked() { |
| 1298 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1299 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1300 | final int dw = mDisplay.getWidth(); |
| 1301 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1302 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1303 | // First find top-most window that has asked to be on top of the |
| 1304 | // wallpaper; all wallpapers go behind it. |
| 1305 | final ArrayList localmWindows = mWindows; |
| 1306 | int N = localmWindows.size(); |
| 1307 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1308 | WindowState foundW = null; |
| 1309 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1310 | WindowState topCurW = null; |
| 1311 | int topCurI = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1312 | int i = N; |
| 1313 | while (i > 0) { |
| 1314 | i--; |
| 1315 | w = (WindowState)localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1316 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1317 | if (topCurW == null) { |
| 1318 | topCurW = w; |
| 1319 | topCurI = i; |
| 1320 | } |
| 1321 | continue; |
| 1322 | } |
| 1323 | topCurW = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1324 | if (w.mAppToken != null) { |
| 1325 | // If this window's app token is hidden and not animating, |
| 1326 | // it is of no interest to us. |
| 1327 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1328 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1329 | "Skipping hidden or animating token: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1330 | topCurW = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1331 | continue; |
| 1332 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1333 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1334 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1335 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1336 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1337 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1338 | && (mWallpaperTarget == w |
| 1339 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1340 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1341 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1342 | foundW = w; |
| 1343 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1344 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1345 | && w.mAppToken.animation != null) |
| 1346 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1347 | // The current wallpaper target is animating, so we'll |
| 1348 | // look behind it for another possible target and figure |
| 1349 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1350 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1351 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1352 | continue; |
| 1353 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1354 | break; |
| 1355 | } |
| 1356 | } |
| 1357 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1358 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1359 | // If we are currently waiting for an app transition, and either |
| 1360 | // the current target or the next target are involved with it, |
| 1361 | // then hold off on doing anything with the wallpaper. |
| 1362 | // Note that we are checking here for just whether the target |
| 1363 | // is part of an app token... which is potentially overly aggressive |
| 1364 | // (the app token may not be involved in the transition), but good |
| 1365 | // enough (we'll just wait until whatever transition is pending |
| 1366 | // executes). |
| 1367 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1368 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1369 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1370 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1371 | } |
| 1372 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1373 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1374 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1375 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1376 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1377 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1378 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1379 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1380 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1381 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1382 | + " oldTarget: " + mWallpaperTarget); |
| 1383 | } |
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 | mLowerWallpaperTarget = null; |
| 1386 | mUpperWallpaperTarget = null; |
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 | WindowState oldW = mWallpaperTarget; |
| 1389 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1390 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1391 | // Now what is happening... if the current and new targets are |
| 1392 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1393 | if (foundW != null && oldW != null) { |
| 1394 | boolean oldAnim = oldW.mAnimation != null |
| 1395 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1396 | boolean foundAnim = foundW.mAnimation != null |
| 1397 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1398 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1399 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1400 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1401 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1402 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1403 | int oldI = localmWindows.indexOf(oldW); |
| 1404 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1405 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1406 | } |
| 1407 | if (oldI >= 0) { |
| 1408 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1409 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1410 | + "=" + oldW + "; new#" + foundI |
| 1411 | + "=" + foundW); |
| 1412 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1413 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1414 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1415 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1416 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1417 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1418 | } |
| 1419 | mWallpaperTarget = oldW; |
| 1420 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1421 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1422 | // Now set the upper and lower wallpaper targets |
| 1423 | // correctly, and make sure that we are positioning |
| 1424 | // the wallpaper below the lower. |
| 1425 | if (foundI > oldI) { |
| 1426 | // The new target is on top of the old one. |
| 1427 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1428 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1429 | } |
| 1430 | mUpperWallpaperTarget = foundW; |
| 1431 | mLowerWallpaperTarget = oldW; |
| 1432 | foundW = oldW; |
| 1433 | foundI = oldI; |
| 1434 | } else { |
| 1435 | // The new target is below the old one. |
| 1436 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1437 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1438 | } |
| 1439 | mUpperWallpaperTarget = oldW; |
| 1440 | mLowerWallpaperTarget = foundW; |
| 1441 | } |
| 1442 | } |
| 1443 | } |
| 1444 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1445 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1446 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1447 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1448 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1449 | || (mLowerWallpaperTarget.mAppToken != null |
| 1450 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1451 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1452 | || (mUpperWallpaperTarget.mAppToken != null |
| 1453 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1454 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1455 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1456 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1457 | } |
| 1458 | mLowerWallpaperTarget = null; |
| 1459 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1460 | } |
| 1461 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1462 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1463 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1464 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1465 | // The window is visible to the compositor... but is it visible |
| 1466 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1467 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1468 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1469 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1470 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1471 | // its layer adjustment. Only do this if we are not transfering |
| 1472 | // between two wallpaper targets. |
| 1473 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1474 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1475 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1476 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1477 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1478 | * TYPE_LAYER_MULTIPLIER |
| 1479 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1480 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1481 | // Now w is the window we are supposed to be behind... but we |
| 1482 | // 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] | 1483 | // AND any starting window associated with it, AND below the |
| 1484 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1485 | while (foundI > 0) { |
| 1486 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1487 | if (wb.mBaseLayer < maxLayer && |
| 1488 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1489 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1490 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1491 | // This window is not related to the previous one in any |
| 1492 | // interesting way, so stop here. |
| 1493 | break; |
| 1494 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1495 | foundW = wb; |
| 1496 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1497 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1498 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1499 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1500 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1501 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1502 | if (foundW == null && topCurW != null) { |
| 1503 | // There is no wallpaper target, so it goes at the bottom. |
| 1504 | // We will assume it is the same place as last time, if known. |
| 1505 | foundW = topCurW; |
| 1506 | foundI = topCurI+1; |
| 1507 | } else { |
| 1508 | // Okay i is the position immediately above the wallpaper. Look at |
| 1509 | // what is below it for later. |
| 1510 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1511 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1512 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1513 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1514 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1515 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1516 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1517 | } |
| 1518 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1519 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1520 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1521 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1522 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1523 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1524 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1525 | // are correctly placed. |
| 1526 | int curTokenIndex = mWallpaperTokens.size(); |
| 1527 | while (curTokenIndex > 0) { |
| 1528 | curTokenIndex--; |
| 1529 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1530 | if (token.hidden == visible) { |
| 1531 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1532 | token.hidden = !visible; |
| 1533 | // Need to do a layout to ensure the wallpaper now has the |
| 1534 | // correct size. |
| 1535 | mLayoutNeeded = true; |
| 1536 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1537 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1538 | int curWallpaperIndex = token.windows.size(); |
| 1539 | while (curWallpaperIndex > 0) { |
| 1540 | curWallpaperIndex--; |
| 1541 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1542 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1543 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1544 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1545 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1546 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1547 | // First, make sure the client has the current visibility |
| 1548 | // state. |
| 1549 | if (wallpaper.mWallpaperVisible != visible) { |
| 1550 | wallpaper.mWallpaperVisible = visible; |
| 1551 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1552 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1553 | "Setting visibility of wallpaper " + wallpaper |
| 1554 | + ": " + visible); |
| 1555 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1556 | } catch (RemoteException e) { |
| 1557 | } |
| 1558 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1559 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1560 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1561 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1562 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1563 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1564 | // First, if this window is at the current index, then all |
| 1565 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1566 | if (wallpaper == foundW) { |
| 1567 | foundI--; |
| 1568 | foundW = foundI > 0 |
| 1569 | ? (WindowState)localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1570 | continue; |
| 1571 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1572 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1573 | // The window didn't match... the current wallpaper window, |
| 1574 | // wherever it is, is in the wrong place, so make sure it is |
| 1575 | // not in the list. |
| 1576 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1577 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1578 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1579 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1580 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1581 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1582 | if (oldIndex < foundI) { |
| 1583 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1584 | } |
| 1585 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1586 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1587 | // Now stick it in. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1588 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1589 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1590 | + " from " + oldIndex + " to " + foundI); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1591 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1592 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1593 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1594 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1595 | } |
| 1596 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1597 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1598 | return changed; |
| 1599 | } |
| 1600 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1601 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1602 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1603 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1604 | mWallpaperAnimLayerAdjustment = adj; |
| 1605 | int curTokenIndex = mWallpaperTokens.size(); |
| 1606 | while (curTokenIndex > 0) { |
| 1607 | curTokenIndex--; |
| 1608 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1609 | int curWallpaperIndex = token.windows.size(); |
| 1610 | while (curWallpaperIndex > 0) { |
| 1611 | curWallpaperIndex--; |
| 1612 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1613 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1614 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1615 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1620 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1621 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1622 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1623 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1624 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1625 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1626 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1627 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1628 | changed = wallpaperWin.mXOffset != offset; |
| 1629 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1630 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1631 | + wallpaperWin + " x: " + offset); |
| 1632 | wallpaperWin.mXOffset = offset; |
| 1633 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1634 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1635 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1636 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1637 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1638 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1639 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1640 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1641 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1642 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1643 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1644 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1645 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1646 | + wallpaperWin + " y: " + offset); |
| 1647 | changed = true; |
| 1648 | wallpaperWin.mYOffset = offset; |
| 1649 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1650 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1651 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1652 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1653 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1654 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1655 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1656 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1657 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1658 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1659 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1660 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1661 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1662 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1663 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1664 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1665 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1666 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1667 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1668 | if (mWaitingOnWallpaper != null) { |
| 1669 | long start = SystemClock.uptimeMillis(); |
| 1670 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1671 | < start) { |
| 1672 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1673 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1674 | "Waiting for offset complete..."); |
| 1675 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1676 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1677 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1678 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1679 | if ((start+WALLPAPER_TIMEOUT) |
| 1680 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1681 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1682 | + wallpaperWin); |
| 1683 | mLastWallpaperTimeoutTime = start; |
| 1684 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1685 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1686 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1687 | } |
| 1688 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1689 | } catch (RemoteException e) { |
| 1690 | } |
| 1691 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1692 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1693 | return changed; |
| 1694 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1695 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1696 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1697 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1698 | if (mWaitingOnWallpaper != null && |
| 1699 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1700 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1701 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1705 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1706 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1707 | final int dw = mDisplay.getWidth(); |
| 1708 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1709 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1710 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1711 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1712 | WindowState target = mWallpaperTarget; |
| 1713 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1714 | if (target.mWallpaperX >= 0) { |
| 1715 | mLastWallpaperX = target.mWallpaperX; |
| 1716 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1717 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1718 | } |
| 1719 | if (target.mWallpaperY >= 0) { |
| 1720 | mLastWallpaperY = target.mWallpaperY; |
| 1721 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1722 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1723 | } |
| 1724 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1725 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1726 | int curTokenIndex = mWallpaperTokens.size(); |
| 1727 | while (curTokenIndex > 0) { |
| 1728 | curTokenIndex--; |
| 1729 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1730 | int curWallpaperIndex = token.windows.size(); |
| 1731 | while (curWallpaperIndex > 0) { |
| 1732 | curWallpaperIndex--; |
| 1733 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1734 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1735 | wallpaper.computeShownFrameLocked(); |
| 1736 | changed = true; |
| 1737 | // We only want to be synchronous with one wallpaper. |
| 1738 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1742 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1743 | return changed; |
| 1744 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1745 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1746 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1747 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1748 | final int dw = mDisplay.getWidth(); |
| 1749 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1750 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1751 | int curTokenIndex = mWallpaperTokens.size(); |
| 1752 | while (curTokenIndex > 0) { |
| 1753 | curTokenIndex--; |
| 1754 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1755 | if (token.hidden == visible) { |
| 1756 | token.hidden = !visible; |
| 1757 | // Need to do a layout to ensure the wallpaper now has the |
| 1758 | // correct size. |
| 1759 | mLayoutNeeded = true; |
| 1760 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1761 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1762 | int curWallpaperIndex = token.windows.size(); |
| 1763 | while (curWallpaperIndex > 0) { |
| 1764 | curWallpaperIndex--; |
| 1765 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1766 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1767 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1768 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1769 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1770 | if (wallpaper.mWallpaperVisible != visible) { |
| 1771 | wallpaper.mWallpaperVisible = visible; |
| 1772 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1773 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1774 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1775 | + ": " + visible); |
| 1776 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1777 | } catch (RemoteException e) { |
| 1778 | } |
| 1779 | } |
| 1780 | } |
| 1781 | } |
| 1782 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | public int addWindow(Session session, IWindow client, |
| 1785 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1786 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | int res = mPolicy.checkAddPermission(attrs); |
| 1788 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1789 | return res; |
| 1790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | boolean reportNewConfig = false; |
| 1793 | WindowState attachedWindow = null; |
| 1794 | WindowState win = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | synchronized(mWindowMap) { |
| 1797 | // Instantiating a Display requires talking with the simulator, |
| 1798 | // so don't do it until we know the system is mostly up and |
| 1799 | // running. |
| 1800 | if (mDisplay == null) { |
| 1801 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1802 | mDisplay = wm.getDefaultDisplay(); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 1803 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 1804 | mInitialDisplayHeight = mDisplay.getHeight(); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1805 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1806 | reportNewConfig = true; |
| 1807 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1809 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1810 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1811 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1812 | } |
| 1813 | |
| 1814 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1815 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1817 | 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] | 1818 | + attrs.token + ". Aborting."); |
| 1819 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1820 | } |
| 1821 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1822 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1823 | 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] | 1824 | + attrs.token + ". Aborting."); |
| 1825 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | boolean addToken = false; |
| 1830 | WindowToken token = mTokenMap.get(attrs.token); |
| 1831 | if (token == null) { |
| 1832 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1833 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1834 | 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] | 1835 | + attrs.token + ". Aborting."); |
| 1836 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1837 | } |
| 1838 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1839 | 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] | 1840 | + attrs.token + ". Aborting."); |
| 1841 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1842 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1843 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1844 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1845 | + attrs.token + ". Aborting."); |
| 1846 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1847 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1848 | token = new WindowToken(attrs.token, -1, false); |
| 1849 | addToken = true; |
| 1850 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1851 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1852 | AppWindowToken atoken = token.appWindowToken; |
| 1853 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1854 | 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] | 1855 | + token + ". Aborting."); |
| 1856 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1857 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1858 | 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] | 1859 | + token + ". Aborting."); |
| 1860 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1861 | } |
| 1862 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1863 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1864 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1865 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1866 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1867 | } |
| 1868 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1869 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1870 | 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] | 1871 | + attrs.token + ". Aborting."); |
| 1872 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1873 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1874 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1875 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1876 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1877 | + attrs.token + ". Aborting."); |
| 1878 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1879 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | win = new WindowState(session, client, token, |
| 1883 | attachedWindow, attrs, viewVisibility); |
| 1884 | if (win.mDeathRecipient == null) { |
| 1885 | // Client has apparently died, so there is no reason to |
| 1886 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1887 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | + " that is dead, aborting."); |
| 1889 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1890 | } |
| 1891 | |
| 1892 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1895 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1896 | return res; |
| 1897 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1898 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1899 | if (outInputChannel != null) { |
| 1900 | String name = win.makeInputChannelName(); |
| 1901 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 1902 | win.mInputChannel = inputChannels[0]; |
| 1903 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 1904 | |
| 1905 | mInputManager.registerInputChannel(win.mInputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1906 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | |
| 1908 | // From now on, no exceptions or errors allowed! |
| 1909 | |
| 1910 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1914 | if (addToken) { |
| 1915 | mTokenMap.put(attrs.token, token); |
| 1916 | mTokenList.add(token); |
| 1917 | } |
| 1918 | win.attach(); |
| 1919 | mWindowMap.put(client.asBinder(), win); |
| 1920 | |
| 1921 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1922 | token.appWindowToken != null) { |
| 1923 | token.appWindowToken.startingWindow = win; |
| 1924 | } |
| 1925 | |
| 1926 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1928 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1929 | mInputMethodWindow = win; |
| 1930 | addInputMethodWindowToListLocked(win); |
| 1931 | imMayMove = false; |
| 1932 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1933 | mInputMethodDialogs.add(win); |
| 1934 | addWindowToListInOrderLocked(win, true); |
| 1935 | adjustInputMethodDialogsLocked(); |
| 1936 | imMayMove = false; |
| 1937 | } else { |
| 1938 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1939 | if (attrs.type == TYPE_WALLPAPER) { |
| 1940 | mLastWallpaperTimeoutTime = 0; |
| 1941 | adjustWallpaperWindowsLocked(); |
| 1942 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1943 | adjustWallpaperWindowsLocked(); |
| 1944 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1947 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | if (mInTouchMode) { |
| 1952 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1953 | } |
| 1954 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1955 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1956 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1957 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1958 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | if (win.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1960 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 1961 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | imMayMove = false; |
| 1963 | } |
| 1964 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1966 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1967 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1968 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | assignLayersLocked(); |
| 1971 | // Don't do layout here, the window must call |
| 1972 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1973 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | //dump(); |
| 1975 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1976 | if (focusChanged) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1977 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1978 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1979 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1980 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | TAG, "New client " + client.asBinder() |
| 1982 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1983 | |
| 1984 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 1985 | reportNewConfig = true; |
| 1986 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1990 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1991 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1992 | // block. |
| 1993 | final long origId = Binder.clearCallingIdentity(); |
| 1994 | if (reportNewConfig) { |
| 1995 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | } |
| 1997 | Binder.restoreCallingIdentity(origId); |
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 | return res; |
| 2000 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2002 | public void removeWindow(Session session, IWindow client) { |
| 2003 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2004 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | if (win == null) { |
| 2006 | return; |
| 2007 | } |
| 2008 | removeWindowLocked(session, win); |
| 2009 | } |
| 2010 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | public void removeWindowLocked(Session session, WindowState win) { |
| 2013 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2014 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | TAG, "Remove " + win + " client=" |
| 2016 | + Integer.toHexString(System.identityHashCode( |
| 2017 | win.mClient.asBinder())) |
| 2018 | + ", surface=" + win.mSurface); |
| 2019 | |
| 2020 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 2021 | |
| 2022 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2023 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2024 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2025 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2026 | + " mExiting=" + win.mExiting |
| 2027 | + " isAnimating=" + win.isAnimating() |
| 2028 | + " app-animation=" |
| 2029 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2030 | + " inPendingTransaction=" |
| 2031 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2032 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2033 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2034 | boolean wasVisible = false; |
| 2035 | // First, see if we need to run an animation. If we do, we have |
| 2036 | // to hold off on removing the window until the animation is done. |
| 2037 | // If the display is frozen, just remove immediately, since the |
| 2038 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2039 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | // If we are not currently running the exit animation, we |
| 2041 | // need to see about starting one. |
| 2042 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2045 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2046 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2047 | } |
| 2048 | // Try starting an animation. |
| 2049 | if (applyAnimationLocked(win, transit, false)) { |
| 2050 | win.mExiting = true; |
| 2051 | } |
| 2052 | } |
| 2053 | if (win.mExiting || win.isAnimating()) { |
| 2054 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2055 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2056 | win.mExiting = true; |
| 2057 | win.mRemoveOnExit = true; |
| 2058 | mLayoutNeeded = true; |
| 2059 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2060 | performLayoutAndPlaceSurfacesLocked(); |
| 2061 | if (win.mAppToken != null) { |
| 2062 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2063 | } |
| 2064 | //dump(); |
| 2065 | Binder.restoreCallingIdentity(origId); |
| 2066 | return; |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | removeWindowInnerLocked(session, win); |
| 2071 | // Removing a visible window will effect the computed orientation |
| 2072 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2073 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2074 | != mForcedAppOrientation |
| 2075 | && updateOrientationFromAppTokensLocked()) { |
| 2076 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | } |
| 2078 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2079 | Binder.restoreCallingIdentity(origId); |
| 2080 | } |
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 | private void removeWindowInnerLocked(Session session, WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2085 | if (mInputMethodTarget == win) { |
| 2086 | moveInputMethodWindowsIfNeededLocked(false); |
| 2087 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2088 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2089 | if (false) { |
| 2090 | RuntimeException e = new RuntimeException("here"); |
| 2091 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2092 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2093 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | mPolicy.removeWindowLw(win); |
| 2096 | win.removeLocked(); |
| 2097 | |
| 2098 | mWindowMap.remove(win.mClient.asBinder()); |
| 2099 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2100 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2101 | 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] | 2102 | |
| 2103 | if (mInputMethodWindow == win) { |
| 2104 | mInputMethodWindow = null; |
| 2105 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2106 | mInputMethodDialogs.remove(win); |
| 2107 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | final WindowToken token = win.mToken; |
| 2110 | final AppWindowToken atoken = win.mAppToken; |
| 2111 | token.windows.remove(win); |
| 2112 | if (atoken != null) { |
| 2113 | atoken.allAppWindows.remove(win); |
| 2114 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2115 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2116 | TAG, "**** Removing window " + win + ": count=" |
| 2117 | + token.windows.size()); |
| 2118 | if (token.windows.size() == 0) { |
| 2119 | if (!token.explicit) { |
| 2120 | mTokenMap.remove(token.token); |
| 2121 | mTokenList.remove(token); |
| 2122 | } else if (atoken != null) { |
| 2123 | atoken.firstWindowDrawn = false; |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | if (atoken != null) { |
| 2128 | if (atoken.startingWindow == win) { |
| 2129 | atoken.startingWindow = null; |
| 2130 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2131 | // If this is the last window and we had requested a starting |
| 2132 | // transition window, well there is no point now. |
| 2133 | atoken.startingData = null; |
| 2134 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2135 | // If this is the last window except for a starting transition |
| 2136 | // window, we need to get rid of the starting transition. |
| 2137 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2138 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | + ": no more real windows"); |
| 2140 | } |
| 2141 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2142 | mH.sendMessage(m); |
| 2143 | } |
| 2144 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2145 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2146 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2147 | mLastWallpaperTimeoutTime = 0; |
| 2148 | adjustWallpaperWindowsLocked(); |
| 2149 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2150 | adjustWallpaperWindowsLocked(); |
| 2151 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | if (!mInLayout) { |
| 2154 | assignLayersLocked(); |
| 2155 | mLayoutNeeded = true; |
| 2156 | performLayoutAndPlaceSurfacesLocked(); |
| 2157 | if (win.mAppToken != null) { |
| 2158 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2159 | } |
| 2160 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 2161 | |
| 2162 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | } |
| 2164 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2165 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2166 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2167 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2168 | if (where != null) { |
| 2169 | Slog.i(TAG, str, where); |
| 2170 | } else { |
| 2171 | Slog.i(TAG, str); |
| 2172 | } |
| 2173 | } |
| 2174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2175 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2176 | long origId = Binder.clearCallingIdentity(); |
| 2177 | try { |
| 2178 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2179 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2180 | if ((w != null) && (w.mSurface != null)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2181 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2182 | Surface.openTransaction(); |
| 2183 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2184 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2185 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2186 | w.mSurface.setTransparentRegionHint(region); |
| 2187 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2188 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2189 | Surface.closeTransaction(); |
| 2190 | } |
| 2191 | } |
| 2192 | } |
| 2193 | } finally { |
| 2194 | Binder.restoreCallingIdentity(origId); |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2199 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2200 | Rect visibleInsets) { |
| 2201 | long origId = Binder.clearCallingIdentity(); |
| 2202 | try { |
| 2203 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2204 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2205 | if (w != null) { |
| 2206 | w.mGivenInsetsPending = false; |
| 2207 | w.mGivenContentInsets.set(contentInsets); |
| 2208 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2209 | w.mTouchableInsets = touchableInsets; |
| 2210 | mLayoutNeeded = true; |
| 2211 | performLayoutAndPlaceSurfacesLocked(); |
| 2212 | } |
| 2213 | } |
| 2214 | } finally { |
| 2215 | Binder.restoreCallingIdentity(origId); |
| 2216 | } |
| 2217 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2219 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2220 | Rect outDisplayFrame) { |
| 2221 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2222 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2223 | if (win == null) { |
| 2224 | outDisplayFrame.setEmpty(); |
| 2225 | return; |
| 2226 | } |
| 2227 | outDisplayFrame.set(win.mDisplayFrame); |
| 2228 | } |
| 2229 | } |
| 2230 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2231 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2232 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2233 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2234 | window.mWallpaperX = x; |
| 2235 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2236 | window.mWallpaperXStep = xStep; |
| 2237 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2238 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2239 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2243 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2244 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2245 | synchronized (mWindowMap) { |
| 2246 | if (mWaitingOnWallpaper != null && |
| 2247 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2248 | mWaitingOnWallpaper = null; |
| 2249 | mWindowMap.notifyAll(); |
| 2250 | } |
| 2251 | } |
| 2252 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2253 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2254 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2255 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2256 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2257 | || window == mUpperWallpaperTarget) { |
| 2258 | boolean doWait = sync; |
| 2259 | int curTokenIndex = mWallpaperTokens.size(); |
| 2260 | while (curTokenIndex > 0) { |
| 2261 | curTokenIndex--; |
| 2262 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2263 | int curWallpaperIndex = token.windows.size(); |
| 2264 | while (curWallpaperIndex > 0) { |
| 2265 | curWallpaperIndex--; |
| 2266 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2267 | try { |
| 2268 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2269 | x, y, z, extras, sync); |
| 2270 | // We only want to be synchronous with one wallpaper. |
| 2271 | sync = false; |
| 2272 | } catch (RemoteException e) { |
| 2273 | } |
| 2274 | } |
| 2275 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2276 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2277 | if (doWait) { |
| 2278 | // XXX Need to wait for result. |
| 2279 | } |
| 2280 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2281 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2282 | return null; |
| 2283 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | public int relayoutWindow(Session session, IWindow client, |
| 2286 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2287 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2288 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2289 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | boolean displayed = false; |
| 2291 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2292 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2295 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2296 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2297 | if (win == null) { |
| 2298 | return 0; |
| 2299 | } |
| 2300 | win.mRequestedWidth = requestedWidth; |
| 2301 | win.mRequestedHeight = requestedHeight; |
| 2302 | |
| 2303 | if (attrs != null) { |
| 2304 | mPolicy.adjustWindowParamsLw(attrs); |
| 2305 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | int attrChanges = 0; |
| 2308 | int flagChanges = 0; |
| 2309 | if (attrs != null) { |
| 2310 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2311 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2312 | } |
| 2313 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2314 | 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] | 2315 | |
| 2316 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2317 | win.mAlpha = attrs.alpha; |
| 2318 | } |
| 2319 | |
| 2320 | final boolean scaledWindow = |
| 2321 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2322 | |
| 2323 | if (scaledWindow) { |
| 2324 | // requested{Width|Height} Surface's physical size |
| 2325 | // attrs.{width|height} Size on screen |
| 2326 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2327 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2328 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2329 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2330 | } else { |
| 2331 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | boolean imMayMove = (flagChanges&( |
| 2335 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2336 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2339 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2340 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2341 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2342 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2343 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2345 | win.mRelayoutCalled = true; |
| 2346 | final int oldVisibility = win.mViewVisibility; |
| 2347 | win.mViewVisibility = viewVisibility; |
| 2348 | if (viewVisibility == View.VISIBLE && |
| 2349 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2350 | displayed = !win.isVisibleLw(); |
| 2351 | if (win.mExiting) { |
| 2352 | win.mExiting = false; |
| 2353 | win.mAnimation = null; |
| 2354 | } |
| 2355 | if (win.mDestroying) { |
| 2356 | win.mDestroying = false; |
| 2357 | mDestroySurface.remove(win); |
| 2358 | } |
| 2359 | if (oldVisibility == View.GONE) { |
| 2360 | win.mEnterAnimationPending = true; |
| 2361 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2362 | if (displayed) { |
| 2363 | if (win.mSurface != null && !win.mDrawPending |
| 2364 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2365 | && mPolicy.isScreenOn()) { |
| 2366 | applyEnterAnimationLocked(win); |
| 2367 | } |
| 2368 | if ((win.mAttrs.flags |
| 2369 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2370 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2371 | "Relayout window turning screen on: " + win); |
| 2372 | win.mTurnOnScreen = true; |
| 2373 | } |
| 2374 | int diff = 0; |
| 2375 | if (win.mConfiguration != mCurConfiguration |
| 2376 | && (win.mConfiguration == null |
| 2377 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2378 | win.mConfiguration = mCurConfiguration; |
| 2379 | if (DEBUG_CONFIGURATION) { |
| 2380 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2381 | + win.mConfiguration + " / 0x" |
| 2382 | + Integer.toHexString(diff)); |
| 2383 | } |
| 2384 | outConfig.setTo(mCurConfiguration); |
| 2385 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2386 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2388 | // To change the format, we need to re-build the surface. |
| 2389 | win.destroySurfaceLocked(); |
| 2390 | displayed = true; |
| 2391 | } |
| 2392 | try { |
| 2393 | Surface surface = win.createSurfaceLocked(); |
| 2394 | if (surface != null) { |
| 2395 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2396 | win.mReportDestroySurface = false; |
| 2397 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2398 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2399 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2401 | // For some reason there isn't a surface. Clear the |
| 2402 | // caller's object so they see the same state. |
| 2403 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2404 | } |
| 2405 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2406 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2407 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2408 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2409 | Binder.restoreCallingIdentity(origId); |
| 2410 | return 0; |
| 2411 | } |
| 2412 | if (displayed) { |
| 2413 | focusMayChange = true; |
| 2414 | } |
| 2415 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2416 | && mInputMethodWindow == null) { |
| 2417 | mInputMethodWindow = win; |
| 2418 | imMayMove = true; |
| 2419 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2420 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2421 | && win.mAppToken != null |
| 2422 | && win.mAppToken.startingWindow != null) { |
| 2423 | // Special handling of starting window over the base |
| 2424 | // window of the app: propagate lock screen flags to it, |
| 2425 | // to provide the correct semantics while starting. |
| 2426 | final int mask = |
| 2427 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2428 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2429 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2430 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2431 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2432 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | } else { |
| 2434 | win.mEnterAnimationPending = false; |
| 2435 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2436 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2437 | + ": mExiting=" + win.mExiting |
| 2438 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2439 | // If we are not currently running the exit animation, we |
| 2440 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2441 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | // Try starting an animation; if there isn't one, we |
| 2443 | // can destroy the surface right away. |
| 2444 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2445 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2446 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2447 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2448 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2450 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | win.mExiting = true; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2452 | mInputMonitor.windowIsBecomingInvisibleLw(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2453 | } else if (win.isAnimating()) { |
| 2454 | // Currently in a hide animation... turn this into |
| 2455 | // an exit. |
| 2456 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2457 | } else if (win == mWallpaperTarget) { |
| 2458 | // If the wallpaper is currently behind this |
| 2459 | // window, we need to change both of them inside |
| 2460 | // of a transaction to avoid artifacts. |
| 2461 | win.mExiting = true; |
| 2462 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | } else { |
| 2464 | if (mInputMethodWindow == win) { |
| 2465 | mInputMethodWindow = null; |
| 2466 | } |
| 2467 | win.destroySurfaceLocked(); |
| 2468 | } |
| 2469 | } |
| 2470 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2471 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2472 | if (win.mSurface == null || (win.getAttrs().flags |
| 2473 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2474 | || win.mSurfacePendingDestroy) { |
| 2475 | // We are being called from a local process, which |
| 2476 | // means outSurface holds its current surface. Ensure the |
| 2477 | // surface object is cleared, but we don't want it actually |
| 2478 | // destroyed at this point. |
| 2479 | win.mSurfacePendingDestroy = false; |
| 2480 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2481 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2482 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2483 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2484 | "Keeping surface, will report destroy: " + win); |
| 2485 | win.mReportDestroySurface = true; |
| 2486 | outSurface.copyFrom(win.mSurface); |
| 2487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2488 | } |
| 2489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | if (focusMayChange) { |
| 2491 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2492 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2493 | imMayMove = false; |
| 2494 | } |
| 2495 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2496 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2497 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2498 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2499 | // reassign them at this point if the IM window state gets shuffled |
| 2500 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2503 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2504 | // Little hack here -- we -should- be able to rely on the |
| 2505 | // function to return true if the IME has moved and needs |
| 2506 | // its layer recomputed. However, if the IME was hidden |
| 2507 | // and isn't actually moved in the list, its layer may be |
| 2508 | // 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] | 2509 | assignLayers = true; |
| 2510 | } |
| 2511 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2512 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2513 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2514 | assignLayers = true; |
| 2515 | } |
| 2516 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | mLayoutNeeded = true; |
| 2519 | win.mGivenInsetsPending = insetsPending; |
| 2520 | if (assignLayers) { |
| 2521 | assignLayersLocked(); |
| 2522 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2523 | configChanged = updateOrientationFromAppTokensLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2525 | if (displayed && win.mIsWallpaper) { |
| 2526 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2527 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2528 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2529 | if (win.mAppToken != null) { |
| 2530 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2531 | } |
| 2532 | outFrame.set(win.mFrame); |
| 2533 | outContentInsets.set(win.mContentInsets); |
| 2534 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2535 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2537 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | + ", requestedHeight=" + requestedHeight |
| 2539 | + ", viewVisibility=" + viewVisibility |
| 2540 | + "\nRelayout returning frame=" + outFrame |
| 2541 | + ", surface=" + outSurface); |
| 2542 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2543 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2545 | |
| 2546 | inTouchMode = mInTouchMode; |
| 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) { |
| 3002 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 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 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3556 | mInputMonitor.windowIsBecomingInvisibleLw(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | changed = true; |
| 3558 | } |
| 3559 | } |
| 3560 | |
| 3561 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3562 | if (!visible) { |
| 3563 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3564 | } else { |
| 3565 | // If we are being set visible, and the starting window is |
| 3566 | // not yet displayed, then make sure it doesn't get displayed. |
| 3567 | WindowState swin = wtoken.startingWindow; |
| 3568 | if (swin != null && (swin.mDrawPending |
| 3569 | || swin.mCommitDrawPending)) { |
| 3570 | swin.mPolicyVisibility = false; |
| 3571 | swin.mPolicyVisibilityAfterAnim = false; |
| 3572 | } |
| 3573 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3574 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3575 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3576 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3577 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3578 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3579 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3580 | mLayoutNeeded = true; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3581 | if (performLayout) { |
| 3582 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3583 | performLayoutAndPlaceSurfacesLocked(); |
| 3584 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3585 | } |
| 3586 | } |
| 3587 | |
| 3588 | if (wtoken.animation != null) { |
| 3589 | delayed = true; |
| 3590 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | return delayed; |
| 3593 | } |
| 3594 | |
| 3595 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3596 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3597 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3598 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | AppWindowToken wtoken; |
| 3602 | |
| 3603 | synchronized(mWindowMap) { |
| 3604 | wtoken = findAppWindowToken(token); |
| 3605 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3606 | 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] | 3607 | return; |
| 3608 | } |
| 3609 | |
| 3610 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3611 | RuntimeException e = null; |
| 3612 | if (!HIDE_STACK_CRAWLS) { |
| 3613 | e = new RuntimeException(); |
| 3614 | e.fillInStackTrace(); |
| 3615 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3616 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | + "): mNextAppTransition=" + mNextAppTransition |
| 3618 | + " hidden=" + wtoken.hidden |
| 3619 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | // If we are preparing an app transition, then delay changing |
| 3623 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3624 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3625 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | // Already in requested state, don't do anything more. |
| 3627 | if (wtoken.hiddenRequested != visible) { |
| 3628 | return; |
| 3629 | } |
| 3630 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3631 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3632 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | TAG, "Setting dummy animation on: " + wtoken); |
| 3634 | wtoken.setDummyAnimation(); |
| 3635 | mOpeningApps.remove(wtoken); |
| 3636 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3637 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | wtoken.inPendingTransaction = true; |
| 3639 | if (visible) { |
| 3640 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | wtoken.startingDisplayed = false; |
| 3642 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3643 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3644 | // If the token is currently hidden (should be the |
| 3645 | // common case), then we need to set up to wait for |
| 3646 | // its windows to be ready. |
| 3647 | if (wtoken.hidden) { |
| 3648 | wtoken.allDrawn = false; |
| 3649 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3650 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3651 | if (wtoken.clientHidden) { |
| 3652 | // In the case where we are making an app visible |
| 3653 | // but holding off for a transition, we still need |
| 3654 | // to tell the client to make its windows visible so |
| 3655 | // they get drawn. Otherwise, we will wait on |
| 3656 | // performing the transition until all windows have |
| 3657 | // been drawn, they never will be, and we are sad. |
| 3658 | wtoken.clientHidden = false; |
| 3659 | wtoken.sendAppVisibilityToClients(); |
| 3660 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | } |
| 3662 | } else { |
| 3663 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3664 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3665 | // If the token is currently visible (should be the |
| 3666 | // common case), then set up to wait for it to be hidden. |
| 3667 | if (!wtoken.hidden) { |
| 3668 | wtoken.waitingToHide = true; |
| 3669 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | } |
| 3671 | return; |
| 3672 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3675 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | wtoken.updateReportedVisibilityLocked(); |
| 3677 | Binder.restoreCallingIdentity(origId); |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3682 | boolean unfreezeSurfaceNow, boolean force) { |
| 3683 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3684 | 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] | 3685 | + " force=" + force); |
| 3686 | final int N = wtoken.allAppWindows.size(); |
| 3687 | boolean unfrozeWindows = false; |
| 3688 | for (int i=0; i<N; i++) { |
| 3689 | WindowState w = wtoken.allAppWindows.get(i); |
| 3690 | if (w.mAppFreezing) { |
| 3691 | w.mAppFreezing = false; |
| 3692 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3693 | w.mOrientationChanging = true; |
| 3694 | } |
| 3695 | unfrozeWindows = true; |
| 3696 | } |
| 3697 | } |
| 3698 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3699 | 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] | 3700 | wtoken.freezingScreen = false; |
| 3701 | mAppsFreezingScreen--; |
| 3702 | } |
| 3703 | if (unfreezeSurfaceNow) { |
| 3704 | if (unfrozeWindows) { |
| 3705 | mLayoutNeeded = true; |
| 3706 | performLayoutAndPlaceSurfacesLocked(); |
| 3707 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3708 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3714 | int configChanges) { |
| 3715 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3716 | RuntimeException e = null; |
| 3717 | if (!HIDE_STACK_CRAWLS) { |
| 3718 | e = new RuntimeException(); |
| 3719 | e.fillInStackTrace(); |
| 3720 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3721 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3723 | + wtoken.freezingScreen, e); |
| 3724 | } |
| 3725 | if (!wtoken.hiddenRequested) { |
| 3726 | if (!wtoken.freezingScreen) { |
| 3727 | wtoken.freezingScreen = true; |
| 3728 | mAppsFreezingScreen++; |
| 3729 | if (mAppsFreezingScreen == 1) { |
| 3730 | startFreezingDisplayLocked(); |
| 3731 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3732 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3733 | 5000); |
| 3734 | } |
| 3735 | } |
| 3736 | final int N = wtoken.allAppWindows.size(); |
| 3737 | for (int i=0; i<N; i++) { |
| 3738 | WindowState w = wtoken.allAppWindows.get(i); |
| 3739 | w.mAppFreezing = true; |
| 3740 | } |
| 3741 | } |
| 3742 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3745 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3746 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3747 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3751 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3752 | 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] | 3753 | return; |
| 3754 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3756 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3757 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3758 | 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] | 3759 | return; |
| 3760 | } |
| 3761 | final long origId = Binder.clearCallingIdentity(); |
| 3762 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3763 | Binder.restoreCallingIdentity(origId); |
| 3764 | } |
| 3765 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3768 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3769 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3770 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | synchronized(mWindowMap) { |
| 3774 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3775 | if (wtoken == null || wtoken.appToken == null) { |
| 3776 | return; |
| 3777 | } |
| 3778 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3779 | 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] | 3780 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3781 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3782 | Binder.restoreCallingIdentity(origId); |
| 3783 | } |
| 3784 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | public void removeAppToken(IBinder token) { |
| 3787 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3788 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3789 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | AppWindowToken wtoken = null; |
| 3793 | AppWindowToken startingToken = null; |
| 3794 | boolean delayed = false; |
| 3795 | |
| 3796 | final long origId = Binder.clearCallingIdentity(); |
| 3797 | synchronized(mWindowMap) { |
| 3798 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3799 | mTokenList.remove(basewtoken); |
| 3800 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3801 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3802 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | wtoken.inPendingTransaction = false; |
| 3804 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3805 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3806 | if (mClosingApps.contains(wtoken)) { |
| 3807 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3808 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3810 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3811 | delayed = true; |
| 3812 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3813 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3814 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3815 | + " animation=" + wtoken.animation |
| 3816 | + " animating=" + wtoken.animating); |
| 3817 | if (delayed) { |
| 3818 | // set the token aside because it has an active animation to be finished |
| 3819 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3820 | } else { |
| 3821 | // Make sure there is no animation running on this token, |
| 3822 | // so any windows associated with it will be removed as |
| 3823 | // soon as their animations are complete |
| 3824 | wtoken.animation = null; |
| 3825 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | } |
| 3827 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3828 | if (mLastEnterAnimToken == wtoken) { |
| 3829 | mLastEnterAnimToken = null; |
| 3830 | mLastEnterAnimParams = null; |
| 3831 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | wtoken.removed = true; |
| 3833 | if (wtoken.startingData != null) { |
| 3834 | startingToken = wtoken; |
| 3835 | } |
| 3836 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3837 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3838 | 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] | 3839 | mFocusedApp = null; |
| 3840 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3841 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | } |
| 3843 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3844 | 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] | 3845 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3847 | if (!delayed && wtoken != null) { |
| 3848 | wtoken.updateReportedVisibilityLocked(); |
| 3849 | } |
| 3850 | } |
| 3851 | Binder.restoreCallingIdentity(origId); |
| 3852 | |
| 3853 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3854 | 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] | 3855 | + startingToken + ": app token removed"); |
| 3856 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3857 | mH.sendMessage(m); |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3862 | final int NW = token.windows.size(); |
| 3863 | for (int i=0; i<NW; i++) { |
| 3864 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3865 | 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] | 3866 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3867 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3868 | int j = win.mChildWindows.size(); |
| 3869 | while (j > 0) { |
| 3870 | j--; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3871 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3872 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3873 | "Tmp removing child window " + cwin); |
| 3874 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | return NW > 0; |
| 3878 | } |
| 3879 | |
| 3880 | void dumpAppTokensLocked() { |
| 3881 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3882 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | } |
| 3884 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | void dumpWindowsLocked() { |
| 3887 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3888 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | } |
| 3890 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3891 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3892 | private int findWindowOffsetLocked(int tokenPos) { |
| 3893 | final int NW = mWindows.size(); |
| 3894 | |
| 3895 | if (tokenPos >= mAppTokens.size()) { |
| 3896 | int i = NW; |
| 3897 | while (i > 0) { |
| 3898 | i--; |
| 3899 | WindowState win = (WindowState)mWindows.get(i); |
| 3900 | if (win.getAppToken() != null) { |
| 3901 | return i+1; |
| 3902 | } |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | while (tokenPos > 0) { |
| 3907 | // Find the first app token below the new position that has |
| 3908 | // a window displayed. |
| 3909 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3910 | 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] | 3911 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3912 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3913 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3914 | "Skipping token -- currently sending to bottom"); |
| 3915 | tokenPos--; |
| 3916 | continue; |
| 3917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | int i = wtoken.windows.size(); |
| 3919 | while (i > 0) { |
| 3920 | i--; |
| 3921 | WindowState win = wtoken.windows.get(i); |
| 3922 | int j = win.mChildWindows.size(); |
| 3923 | while (j > 0) { |
| 3924 | j--; |
| 3925 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3926 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | for (int pos=NW-1; pos>=0; pos--) { |
| 3928 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3929 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3930 | "Found child win @" + (pos+1)); |
| 3931 | return pos+1; |
| 3932 | } |
| 3933 | } |
| 3934 | } |
| 3935 | } |
| 3936 | for (int pos=NW-1; pos>=0; pos--) { |
| 3937 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3938 | 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] | 3939 | return pos+1; |
| 3940 | } |
| 3941 | } |
| 3942 | } |
| 3943 | tokenPos--; |
| 3944 | } |
| 3945 | |
| 3946 | return 0; |
| 3947 | } |
| 3948 | |
| 3949 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3950 | final int NCW = win.mChildWindows.size(); |
| 3951 | boolean added = false; |
| 3952 | for (int j=0; j<NCW; j++) { |
| 3953 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3954 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3955 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3956 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | mWindows.add(index, win); |
| 3958 | index++; |
| 3959 | added = true; |
| 3960 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3961 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3962 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | mWindows.add(index, cwin); |
| 3964 | index++; |
| 3965 | } |
| 3966 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3967 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3968 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3969 | mWindows.add(index, win); |
| 3970 | index++; |
| 3971 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3972 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3973 | return index; |
| 3974 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3977 | final int NW = token.windows.size(); |
| 3978 | for (int i=0; i<NW; i++) { |
| 3979 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3980 | } |
| 3981 | return index; |
| 3982 | } |
| 3983 | |
| 3984 | public void moveAppToken(int index, IBinder token) { |
| 3985 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3986 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3987 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3991 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3993 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3994 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3995 | 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] | 3996 | + token + " (" + wtoken + ")"); |
| 3997 | return; |
| 3998 | } |
| 3999 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4000 | 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] | 4001 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4004 | 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] | 4005 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4006 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4007 | 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] | 4008 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4009 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4010 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4011 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4012 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4013 | mLayoutNeeded = true; |
| 4014 | performLayoutAndPlaceSurfacesLocked(); |
| 4015 | } |
| 4016 | Binder.restoreCallingIdentity(origId); |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4021 | // XXX This should be done more efficiently! |
| 4022 | // (take advantage of the fact that both lists should be |
| 4023 | // ordered in the same way.) |
| 4024 | int N = tokens.size(); |
| 4025 | for (int i=0; i<N; i++) { |
| 4026 | IBinder token = tokens.get(i); |
| 4027 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4028 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4029 | 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] | 4030 | + token + " (" + wtoken + ")"); |
| 4031 | i--; |
| 4032 | N--; |
| 4033 | } |
| 4034 | } |
| 4035 | } |
| 4036 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4037 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4038 | boolean updateFocusAndLayout) { |
| 4039 | // First remove all of the windows from the list. |
| 4040 | tmpRemoveAppWindowsLocked(wtoken); |
| 4041 | |
| 4042 | // Where to start adding? |
| 4043 | int pos = findWindowOffsetLocked(tokenPos); |
| 4044 | |
| 4045 | // And now add them back at the correct place. |
| 4046 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4047 | |
| 4048 | if (updateFocusAndLayout) { |
| 4049 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4050 | assignLayersLocked(); |
| 4051 | } |
| 4052 | mLayoutNeeded = true; |
| 4053 | performLayoutAndPlaceSurfacesLocked(); |
| 4054 | } |
| 4055 | } |
| 4056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4058 | // First remove all of the windows from the list. |
| 4059 | final int N = tokens.size(); |
| 4060 | int i; |
| 4061 | for (i=0; i<N; i++) { |
| 4062 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4063 | if (token != null) { |
| 4064 | tmpRemoveAppWindowsLocked(token); |
| 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | // Where to start adding? |
| 4069 | int pos = findWindowOffsetLocked(tokenPos); |
| 4070 | |
| 4071 | // And now add them back at the correct place. |
| 4072 | for (i=0; i<N; i++) { |
| 4073 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4074 | if (token != null) { |
| 4075 | pos = reAddAppWindowsLocked(pos, token); |
| 4076 | } |
| 4077 | } |
| 4078 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4079 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4080 | assignLayersLocked(); |
| 4081 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4082 | mLayoutNeeded = true; |
| 4083 | performLayoutAndPlaceSurfacesLocked(); |
| 4084 | |
| 4085 | //dump(); |
| 4086 | } |
| 4087 | |
| 4088 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4089 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4090 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4091 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | final long origId = Binder.clearCallingIdentity(); |
| 4095 | synchronized(mWindowMap) { |
| 4096 | removeAppTokensLocked(tokens); |
| 4097 | final int N = tokens.size(); |
| 4098 | for (int i=0; i<N; i++) { |
| 4099 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4100 | if (wt != null) { |
| 4101 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4102 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4103 | mToTopApps.remove(wt); |
| 4104 | mToBottomApps.remove(wt); |
| 4105 | mToTopApps.add(wt); |
| 4106 | wt.sendingToBottom = false; |
| 4107 | wt.sendingToTop = true; |
| 4108 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | } |
| 4110 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4111 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4112 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4113 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | } |
| 4116 | Binder.restoreCallingIdentity(origId); |
| 4117 | } |
| 4118 | |
| 4119 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4120 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4121 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4122 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | final long origId = Binder.clearCallingIdentity(); |
| 4126 | synchronized(mWindowMap) { |
| 4127 | removeAppTokensLocked(tokens); |
| 4128 | final int N = tokens.size(); |
| 4129 | int pos = 0; |
| 4130 | for (int i=0; i<N; i++) { |
| 4131 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4132 | if (wt != null) { |
| 4133 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4134 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4135 | mToTopApps.remove(wt); |
| 4136 | mToBottomApps.remove(wt); |
| 4137 | mToBottomApps.add(i, wt); |
| 4138 | wt.sendingToTop = false; |
| 4139 | wt.sendingToBottom = true; |
| 4140 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4141 | pos++; |
| 4142 | } |
| 4143 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4144 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4145 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4146 | moveAppWindowsLocked(tokens, 0); |
| 4147 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4148 | } |
| 4149 | Binder.restoreCallingIdentity(origId); |
| 4150 | } |
| 4151 | |
| 4152 | // ------------------------------------------------------------- |
| 4153 | // Misc IWindowSession methods |
| 4154 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4155 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4156 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4157 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4158 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4159 | // called before DevicePolicyManagerService has started. |
| 4160 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4161 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4162 | Context.DEVICE_POLICY_SERVICE); |
| 4163 | if (dpm != null) { |
| 4164 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4165 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4166 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4167 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4168 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4169 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4173 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | != PackageManager.PERMISSION_GRANTED) { |
| 4175 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4176 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4177 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4178 | synchronized (mKeyguardTokenWatcher) { |
| 4179 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4180 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4184 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | != PackageManager.PERMISSION_GRANTED) { |
| 4186 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4187 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4189 | synchronized (mKeyguardTokenWatcher) { |
| 4190 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4191 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4192 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4193 | // If we are the last one to reenable the keyguard wait until |
| 4194 | // we have actually finished reenabling until returning. |
| 4195 | // It is possible that reenableKeyguard() can be called before |
| 4196 | // the previous disableKeyguard() is handled, in which case |
| 4197 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4198 | // be called. In that case mKeyguardDisabled will be false here |
| 4199 | // and we have nothing to wait for. |
| 4200 | while (mKeyguardDisabled) { |
| 4201 | try { |
| 4202 | mKeyguardTokenWatcher.wait(); |
| 4203 | } catch (InterruptedException e) { |
| 4204 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | } |
| 4206 | } |
| 4207 | } |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | /** |
| 4212 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4213 | */ |
| 4214 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4215 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | != PackageManager.PERMISSION_GRANTED) { |
| 4217 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4218 | } |
| 4219 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4220 | public void onKeyguardExitResult(boolean success) { |
| 4221 | try { |
| 4222 | callback.onKeyguardExitResult(success); |
| 4223 | } catch (RemoteException e) { |
| 4224 | // Client has died, we don't care. |
| 4225 | } |
| 4226 | } |
| 4227 | }); |
| 4228 | } |
| 4229 | |
| 4230 | public boolean inKeyguardRestrictedInputMode() { |
| 4231 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4232 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4233 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4234 | public void closeSystemDialogs(String reason) { |
| 4235 | synchronized(mWindowMap) { |
| 4236 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4237 | WindowState w = (WindowState)mWindows.get(i); |
| 4238 | if (w.mSurface != null) { |
| 4239 | try { |
| 4240 | w.mClient.closeSystemDialogs(reason); |
| 4241 | } catch (RemoteException e) { |
| 4242 | } |
| 4243 | } |
| 4244 | } |
| 4245 | } |
| 4246 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4248 | static float fixScale(float scale) { |
| 4249 | if (scale < 0) scale = 0; |
| 4250 | else if (scale > 20) scale = 20; |
| 4251 | return Math.abs(scale); |
| 4252 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | public void setAnimationScale(int which, float scale) { |
| 4255 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4256 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4257 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | if (scale < 0) scale = 0; |
| 4261 | else if (scale > 20) scale = 20; |
| 4262 | scale = Math.abs(scale); |
| 4263 | switch (which) { |
| 4264 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4265 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4266 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | // Persist setting |
| 4269 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4270 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | public void setAnimationScales(float[] scales) { |
| 4273 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4274 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4275 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | if (scales != null) { |
| 4279 | if (scales.length >= 1) { |
| 4280 | mWindowAnimationScale = fixScale(scales[0]); |
| 4281 | } |
| 4282 | if (scales.length >= 2) { |
| 4283 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4284 | } |
| 4285 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | // Persist setting |
| 4288 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4289 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | public float getAnimationScale(int which) { |
| 4292 | switch (which) { |
| 4293 | case 0: return mWindowAnimationScale; |
| 4294 | case 1: return mTransitionAnimationScale; |
| 4295 | } |
| 4296 | return 0; |
| 4297 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | public float[] getAnimationScales() { |
| 4300 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4301 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4303 | public int getSwitchState(int sw) { |
| 4304 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4305 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4306 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4308 | return mInputManager.getSwitchState(sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4311 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4312 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4313 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4314 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4316 | return mInputManager.getSwitchState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | public int getScancodeState(int sw) { |
| 4320 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4321 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4322 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4324 | return mInputManager.getScancodeState(sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4328 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4329 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4330 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4332 | return mInputManager.getScancodeState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4334 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4335 | public int getTrackballScancodeState(int sw) { |
| 4336 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4337 | "getTrackballScancodeState()")) { |
| 4338 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4339 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4340 | return mInputManager.getTrackballScancodeState(sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | public int getDPadScancodeState(int sw) { |
| 4344 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4345 | "getDPadScancodeState()")) { |
| 4346 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4347 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4348 | return mInputManager.getDPadScancodeState(sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4349 | } |
| 4350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4351 | public int getKeycodeState(int sw) { |
| 4352 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4353 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4354 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4356 | return mInputManager.getKeycodeState(sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4359 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4360 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4361 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4362 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4363 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4364 | return mInputManager.getKeycodeState(devid, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4365 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4366 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4367 | public int getTrackballKeycodeState(int sw) { |
| 4368 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4369 | "getTrackballKeycodeState()")) { |
| 4370 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4371 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4372 | return mInputManager.getTrackballKeycodeState(sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | public int getDPadKeycodeState(int sw) { |
| 4376 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4377 | "getDPadKeycodeState()")) { |
| 4378 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4379 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4380 | return mInputManager.getDPadKeycodeState(sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4381 | } |
| 4382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4384 | return mInputManager.hasKeys(keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4387 | public void enableScreenAfterBoot() { |
| 4388 | synchronized(mWindowMap) { |
| 4389 | if (mSystemBooted) { |
| 4390 | return; |
| 4391 | } |
| 4392 | mSystemBooted = true; |
| 4393 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | performEnableScreen(); |
| 4396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | public void enableScreenIfNeededLocked() { |
| 4399 | if (mDisplayEnabled) { |
| 4400 | return; |
| 4401 | } |
| 4402 | if (!mSystemBooted) { |
| 4403 | return; |
| 4404 | } |
| 4405 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4406 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4408 | public void performEnableScreen() { |
| 4409 | synchronized(mWindowMap) { |
| 4410 | if (mDisplayEnabled) { |
| 4411 | return; |
| 4412 | } |
| 4413 | if (!mSystemBooted) { |
| 4414 | return; |
| 4415 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | // Don't enable the screen until all existing windows |
| 4418 | // have been drawn. |
| 4419 | final int N = mWindows.size(); |
| 4420 | for (int i=0; i<N; i++) { |
| 4421 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 4422 | if (w.isVisibleLw() && !w.mObscured |
| 4423 | && (w.mOrientationChanging || !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--) { |
| 4534 | WindowState w = (WindowState)mWindows.get(i); |
| 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 | |
| 4690 | Object[] windows; |
| 4691 | synchronized (mWindowMap) { |
| 4692 | windows = new Object[mWindows.size()]; |
| 4693 | //noinspection unchecked |
| 4694 | windows = mWindows.toArray(windows); |
| 4695 | } |
| 4696 | |
| 4697 | BufferedWriter out = null; |
| 4698 | |
| 4699 | // Any uncaught exception will crash the system process |
| 4700 | try { |
| 4701 | OutputStream clientStream = client.getOutputStream(); |
| 4702 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4703 | |
| 4704 | final int count = windows.length; |
| 4705 | for (int i = 0; i < count; i++) { |
| 4706 | final WindowState w = (WindowState) windows[i]; |
| 4707 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4708 | out.write(' '); |
| 4709 | out.append(w.mAttrs.getTitle()); |
| 4710 | out.write('\n'); |
| 4711 | } |
| 4712 | |
| 4713 | out.write("DONE.\n"); |
| 4714 | out.flush(); |
| 4715 | } catch (Exception e) { |
| 4716 | result = false; |
| 4717 | } finally { |
| 4718 | if (out != null) { |
| 4719 | try { |
| 4720 | out.close(); |
| 4721 | } catch (IOException e) { |
| 4722 | result = false; |
| 4723 | } |
| 4724 | } |
| 4725 | } |
| 4726 | |
| 4727 | return result; |
| 4728 | } |
| 4729 | |
| 4730 | /** |
| 4731 | * Sends a command to a target window. The result of the command, if any, will be |
| 4732 | * written in the output stream of the specified socket. |
| 4733 | * |
| 4734 | * The parameters must follow this syntax: |
| 4735 | * windowHashcode extra |
| 4736 | * |
| 4737 | * Where XX is the length in characeters of the windowTitle. |
| 4738 | * |
| 4739 | * The first parameter is the target window. The window with the specified hashcode |
| 4740 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4741 | * will be delivered to the target window and as parameters to the command itself. |
| 4742 | * |
| 4743 | * @param client The remote client to sent the result, if any, to. |
| 4744 | * @param command The command to execute. |
| 4745 | * @param parameters The command parameters. |
| 4746 | * |
| 4747 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4748 | * not indicate whether the command itself was successful. |
| 4749 | */ |
| 4750 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4751 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4752 | return false; |
| 4753 | } |
| 4754 | |
| 4755 | boolean success = true; |
| 4756 | Parcel data = null; |
| 4757 | Parcel reply = null; |
| 4758 | |
| 4759 | // Any uncaught exception will crash the system process |
| 4760 | try { |
| 4761 | // Find the hashcode of the window |
| 4762 | int index = parameters.indexOf(' '); |
| 4763 | if (index == -1) { |
| 4764 | index = parameters.length(); |
| 4765 | } |
| 4766 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4767 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4768 | |
| 4769 | // Extract the command's parameter after the window description |
| 4770 | if (index < parameters.length()) { |
| 4771 | parameters = parameters.substring(index + 1); |
| 4772 | } else { |
| 4773 | parameters = ""; |
| 4774 | } |
| 4775 | |
| 4776 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4777 | if (window == null) { |
| 4778 | return false; |
| 4779 | } |
| 4780 | |
| 4781 | data = Parcel.obtain(); |
| 4782 | data.writeInterfaceToken("android.view.IWindow"); |
| 4783 | data.writeString(command); |
| 4784 | data.writeString(parameters); |
| 4785 | data.writeInt(1); |
| 4786 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4787 | |
| 4788 | reply = Parcel.obtain(); |
| 4789 | |
| 4790 | final IBinder binder = window.mClient.asBinder(); |
| 4791 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4792 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4793 | |
| 4794 | reply.readException(); |
| 4795 | |
| 4796 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4797 | 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] | 4798 | success = false; |
| 4799 | } finally { |
| 4800 | if (data != null) { |
| 4801 | data.recycle(); |
| 4802 | } |
| 4803 | if (reply != null) { |
| 4804 | reply.recycle(); |
| 4805 | } |
| 4806 | } |
| 4807 | |
| 4808 | return success; |
| 4809 | } |
| 4810 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4811 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 4812 | synchronized(mWindowMap) { |
| 4813 | mWindowChangeListeners.add(listener); |
| 4814 | } |
| 4815 | } |
| 4816 | |
| 4817 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 4818 | synchronized(mWindowMap) { |
| 4819 | mWindowChangeListeners.remove(listener); |
| 4820 | } |
| 4821 | } |
| 4822 | |
| 4823 | private void notifyWindowsChanged() { |
| 4824 | WindowChangeListener[] windowChangeListeners; |
| 4825 | synchronized(mWindowMap) { |
| 4826 | if(mWindowChangeListeners.isEmpty()) { |
| 4827 | return; |
| 4828 | } |
| 4829 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 4830 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 4831 | } |
| 4832 | int N = windowChangeListeners.length; |
| 4833 | for(int i = 0; i < N; i++) { |
| 4834 | windowChangeListeners[i].windowsChanged(); |
| 4835 | } |
| 4836 | } |
| 4837 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 4838 | private void notifyFocusChanged() { |
| 4839 | WindowChangeListener[] windowChangeListeners; |
| 4840 | synchronized(mWindowMap) { |
| 4841 | if(mWindowChangeListeners.isEmpty()) { |
| 4842 | return; |
| 4843 | } |
| 4844 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 4845 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 4846 | } |
| 4847 | int N = windowChangeListeners.length; |
| 4848 | for(int i = 0; i < N; i++) { |
| 4849 | windowChangeListeners[i].focusChanged(); |
| 4850 | } |
| 4851 | } |
| 4852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4853 | private WindowState findWindow(int hashCode) { |
| 4854 | if (hashCode == -1) { |
| 4855 | return getFocusedWindow(); |
| 4856 | } |
| 4857 | |
| 4858 | synchronized (mWindowMap) { |
| 4859 | final ArrayList windows = mWindows; |
| 4860 | final int count = windows.size(); |
| 4861 | |
| 4862 | for (int i = 0; i < count; i++) { |
| 4863 | WindowState w = (WindowState) windows.get(i); |
| 4864 | if (System.identityHashCode(w) == hashCode) { |
| 4865 | return w; |
| 4866 | } |
| 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | return null; |
| 4871 | } |
| 4872 | |
| 4873 | /* |
| 4874 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4875 | * that to config-changed listeners if appropriate. |
| 4876 | */ |
| 4877 | void sendNewConfiguration() { |
| 4878 | try { |
| 4879 | mActivityManager.updateConfiguration(null); |
| 4880 | } catch (RemoteException e) { |
| 4881 | } |
| 4882 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4884 | public Configuration computeNewConfiguration() { |
| 4885 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4886 | return computeNewConfigurationLocked(); |
| 4887 | } |
| 4888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4889 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4890 | Configuration computeNewConfigurationLocked() { |
| 4891 | Configuration config = new Configuration(); |
| 4892 | if (!computeNewConfigurationLocked(config)) { |
| 4893 | return null; |
| 4894 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4895 | return config; |
| 4896 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4897 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4898 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4899 | if (mDisplay == null) { |
| 4900 | return false; |
| 4901 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4902 | |
| 4903 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 4904 | |
| 4905 | // Use the effective "visual" dimensions based on current rotation |
| 4906 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 4907 | || mRotation == Surface.ROTATION_270); |
| 4908 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 4909 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 4910 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4911 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4912 | if (dw < dh) { |
| 4913 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4914 | } else if (dw > dh) { |
| 4915 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4916 | } |
| 4917 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4918 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4919 | DisplayMetrics dm = new DisplayMetrics(); |
| 4920 | mDisplay.getMetrics(dm); |
| 4921 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4922 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4923 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4924 | // Note we only do this once because at this point we don't |
| 4925 | // expect the screen to change in this way at runtime, and want |
| 4926 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4927 | int longSize = dw; |
| 4928 | int shortSize = dh; |
| 4929 | if (longSize < shortSize) { |
| 4930 | int tmp = longSize; |
| 4931 | longSize = shortSize; |
| 4932 | shortSize = tmp; |
| 4933 | } |
| 4934 | longSize = (int)(longSize/dm.density); |
| 4935 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4936 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4937 | // These semi-magic numbers define our compatibility modes for |
| 4938 | // applications with different screens. Don't change unless you |
| 4939 | // make sure to test lots and lots of apps! |
| 4940 | if (longSize < 470) { |
| 4941 | // This is shorter than an HVGA normal density screen (which |
| 4942 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4943 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4944 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4945 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 4946 | // What size is this screen screen? |
| 4947 | if (longSize >= 800 && shortSize >= 600) { |
| 4948 | // SVGA or larger screens at medium density are the point |
| 4949 | // at which we consider it to be an extra large screen. |
| 4950 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 4951 | } else if (longSize >= 640 && shortSize >= 480) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4952 | // VGA or larger screens at medium density are the point |
| 4953 | // at which we consider it to be a large screen. |
| 4954 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4955 | } else { |
| 4956 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4957 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4958 | // If this screen is wider than normal HVGA, or taller |
| 4959 | // than FWVGA, then for old apps we want to run in size |
| 4960 | // compatibility mode. |
| 4961 | if (shortSize > 321 || longSize > 570) { |
| 4962 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4963 | } |
| 4964 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4965 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4966 | // Is this a long screen? |
| 4967 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4968 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4969 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4970 | } else { |
| 4971 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4972 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4973 | } |
| 4974 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4975 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4976 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4977 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4978 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4979 | mPolicy.adjustConfigurationLw(config); |
| 4980 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4981 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 4982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | // ------------------------------------------------------------- |
| 4984 | // Input Events and Focus Management |
| 4985 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4986 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4987 | InputMonitor mInputMonitor = new InputMonitor(); |
| 4988 | |
| 4989 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 4990 | * is kept in sync with changes in window focus, visibility, registration, and |
| 4991 | * other relevant Window Manager state transitions. */ |
| 4992 | final class InputMonitor { |
| 4993 | // Current window with input focus for keys and other non-touch events. May be null. |
| 4994 | private WindowState mInputFocus; |
| 4995 | |
| 4996 | // When true, prevents input dispatch from proceeding until set to false again. |
| 4997 | private boolean mInputDispatchFrozen; |
| 4998 | |
| 4999 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5000 | private boolean mInputDispatchEnabled = true; |
| 5001 | |
| 5002 | // Temporary list of windows information to provide to the input dispatcher. |
| 5003 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5004 | |
| 5005 | // Temporary input application object to provide to the input dispatcher. |
| 5006 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5007 | |
| 5008 | /* Notifies the window manager about a broken input channel. |
| 5009 | * |
| 5010 | * Called by the InputManager. |
| 5011 | */ |
| 5012 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5013 | synchronized (mWindowMap) { |
| 5014 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5015 | if (windowState == null) { |
| 5016 | return; // irrelevant |
| 5017 | } |
| 5018 | |
| 5019 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5020 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5021 | } |
| 5022 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5023 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5024 | /* Notifies the window manager about an input channel that is not responding. |
| 5025 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5026 | * return a new timeout in nanoseconds. |
| 5027 | * |
| 5028 | * Called by the InputManager. |
| 5029 | */ |
| 5030 | public long notifyInputChannelANR(InputChannel inputChannel) { |
| 5031 | AppWindowToken token; |
| 5032 | synchronized (mWindowMap) { |
| 5033 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5034 | if (windowState == null) { |
| 5035 | return -2; // irrelevant, abort dispatching (-2) |
| 5036 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5037 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5038 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5039 | + windowState.mAttrs.getTitle()); |
| 5040 | token = windowState.mAppToken; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5041 | } |
| 5042 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5043 | return notifyANRInternal(token); |
| 5044 | } |
| 5045 | |
| 5046 | /* Notifies the window manager about an input channel spontaneously recovering from ANR |
| 5047 | * by successfully delivering the event that originally timed out. |
| 5048 | * |
| 5049 | * Called by the InputManager. |
| 5050 | */ |
| 5051 | public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) { |
| 5052 | // Nothing to do just now. |
| 5053 | // Just wait for the user to dismiss the ANR dialog. |
| 5054 | } |
| 5055 | |
| 5056 | /* Notifies the window manager about an application that is not responding |
| 5057 | * in general rather than with respect to a particular input channel. |
| 5058 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5059 | * return a new timeout in nanoseconds. |
| 5060 | * |
| 5061 | * Called by the InputManager. |
| 5062 | */ |
| 5063 | public long notifyANR(Object token) { |
| 5064 | AppWindowToken appWindowToken = (AppWindowToken) token; |
| 5065 | |
| 5066 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5067 | + appWindowToken.stringName); |
| 5068 | return notifyANRInternal(appWindowToken); |
| 5069 | } |
| 5070 | |
| 5071 | private long notifyANRInternal(AppWindowToken token) { |
| 5072 | if (token != null && token.appToken != null) { |
| 5073 | try { |
| 5074 | // Notify the activity manager about the timeout and let it decide whether |
| 5075 | // to abort dispatching or keep waiting. |
| 5076 | boolean abort = token.appToken.keyDispatchingTimedOut(); |
| 5077 | if (! abort) { |
| 5078 | // The activity manager declined to abort dispatching. |
| 5079 | // Wait a bit longer and timeout again later. |
| 5080 | return token.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5081 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5082 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5083 | } |
| 5084 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5085 | return -2; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5086 | } |
| 5087 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5088 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5089 | synchronized (mWindowMap) { |
| 5090 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5095 | int windowCount = mWindows.size(); |
| 5096 | for (int i = 0; i < windowCount; i++) { |
| 5097 | WindowState windowState = (WindowState) mWindows.get(i); |
| 5098 | if (windowState.mInputChannel == inputChannel) { |
| 5099 | return windowState; |
| 5100 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5103 | return null; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5104 | } |
| 5105 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5106 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5107 | public void updateInputWindowsLw() { |
| 5108 | // Populate the input window list with information about all of the windows that |
| 5109 | // could potentially receive input. |
| 5110 | // As an optimization, we could try to prune the list of windows but this turns |
| 5111 | // out to be difficult because only the native code knows for sure which window |
| 5112 | // currently has touch focus. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5113 | final ArrayList windows = mWindows; |
| 5114 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5115 | for (int i = N - 1; i >= 0; i--) { |
| 5116 | final WindowState child = (WindowState) windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 5117 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5118 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5119 | continue; |
| 5120 | } |
| 5121 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5122 | final int flags = child.mAttrs.flags; |
| 5123 | final int type = child.mAttrs.type; |
| 5124 | |
| 5125 | final boolean hasFocus = (child == mInputFocus); |
| 5126 | final boolean isVisible = child.isVisibleLw(); |
| 5127 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5128 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| 5129 | |
| 5130 | // Add a window to our list of input windows. |
| 5131 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5132 | inputWindow.inputChannel = child.mInputChannel; |
| 5133 | inputWindow.layoutParamsFlags = flags; |
| 5134 | inputWindow.layoutParamsType = type; |
| 5135 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5136 | inputWindow.visible = isVisible; |
| 5137 | inputWindow.hasFocus = hasFocus; |
| 5138 | inputWindow.hasWallpaper = hasWallpaper; |
| 5139 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 5140 | inputWindow.ownerPid = child.mSession.mPid; |
| 5141 | inputWindow.ownerUid = child.mSession.mUid; |
| 5142 | |
| 5143 | final Rect frame = child.mFrame; |
| 5144 | inputWindow.frameLeft = frame.left; |
| 5145 | inputWindow.frameTop = frame.top; |
| 5146 | |
| 5147 | switch (child.mTouchableInsets) { |
| 5148 | default: |
| 5149 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5150 | inputWindow.touchableAreaLeft = frame.left; |
| 5151 | inputWindow.touchableAreaTop = frame.top; |
| 5152 | inputWindow.touchableAreaRight = frame.right; |
| 5153 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5154 | break; |
| 5155 | |
| 5156 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5157 | Rect inset = child.mGivenContentInsets; |
| 5158 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5159 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5160 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5161 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5162 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5163 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5164 | |
| 5165 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5166 | Rect inset = child.mGivenVisibleInsets; |
| 5167 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5168 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5169 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5170 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5171 | break; |
| 5172 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5173 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5174 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5175 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5176 | // Send windows to native code. |
| 5177 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5178 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5179 | // Clear the list in preparation for the next round. |
| 5180 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5181 | mTempInputWindows.clear(); |
| 5182 | } |
| 5183 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5184 | /* Provides feedback for a virtual key down. */ |
| 5185 | public void virtualKeyDownFeedback() { |
| 5186 | synchronized (mWindowMap) { |
| 5187 | mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5188 | } |
| 5189 | } |
| 5190 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5191 | /* Notifies that an app switch key (BACK / HOME) has just been pressed. |
| 5192 | * This essentially starts a .5 second timeout for the application to process |
| 5193 | * subsequent input events while waiting for the app switch to occur. If it takes longer |
| 5194 | * than this, the pending events will be dropped. |
| 5195 | */ |
| 5196 | public void notifyAppSwitchComing() { |
| 5197 | // TODO Not implemented yet. Should go in the native side. |
| 5198 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5199 | |
| 5200 | /* Notifies that the lid switch changed state. */ |
| 5201 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5202 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5203 | } |
| 5204 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5205 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5206 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5207 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5208 | int policyFlags, boolean isScreenOn) { |
| 5209 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5210 | keyCode, down, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | /* Provides an opportunity for the window manager policy to process a key before |
| 5214 | * ordinary dispatch. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5215 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5216 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5217 | int policyFlags) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5218 | WindowState windowState = getWindowStateForInputChannel(focus); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5219 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5220 | keyCode, metaState, repeatCount, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5221 | } |
| 5222 | |
| 5223 | /* Called when the current input focus changes. |
| 5224 | * Layer assignment is assumed to be complete by the time this is called. |
| 5225 | */ |
| 5226 | public void setInputFocusLw(WindowState newWindow) { |
| 5227 | if (DEBUG_INPUT) { |
| 5228 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5229 | } |
| 5230 | |
| 5231 | if (newWindow != mInputFocus) { |
| 5232 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 5233 | // If the new input focus is an error window or appears above the current |
| 5234 | // input focus, preempt any pending synchronous dispatch so that we can |
| 5235 | // start delivering events to the new input focus as soon as possible. |
| 5236 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5237 | if (DEBUG_INPUT) { |
| 5238 | Slog.v(TAG, "New SYSTEM_ERROR window; resetting state"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5239 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5240 | preemptInputDispatchLw(); |
| 5241 | } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) { |
| 5242 | if (DEBUG_INPUT) { |
| 5243 | Slog.v(TAG, "Transferring focus to new window at higher layer: " |
| 5244 | + "old win layer=" + mInputFocus.mLayer |
| 5245 | + ", new win layer=" + newWindow.mLayer); |
| 5246 | } |
| 5247 | preemptInputDispatchLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5248 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5249 | |
| 5250 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5251 | // This is to protect against bugs if someone pauses dispatching but |
| 5252 | // forgets to resume. |
| 5253 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5254 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5255 | |
| 5256 | mInputFocus = newWindow; |
| 5257 | updateInputWindowsLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5258 | } |
| 5259 | } |
| 5260 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5261 | public void windowIsBecomingInvisibleLw(WindowState window) { |
| 5262 | // The window is becoming invisible. Preempt input dispatch in progress |
| 5263 | // so that the next window below can receive focus. |
| 5264 | if (window == mInputFocus) { |
| 5265 | mInputFocus = null; |
| 5266 | preemptInputDispatchLw(); |
| 5267 | } |
| 5268 | |
| 5269 | updateInputWindowsLw(); |
| 5270 | } |
| 5271 | |
| 5272 | /* Tells the dispatcher to stop waiting for its current synchronous event targets. |
| 5273 | * Essentially, just makes those dispatches asynchronous so a new dispatch cycle |
| 5274 | * can begin. |
| 5275 | */ |
| 5276 | private void preemptInputDispatchLw() { |
| 5277 | mInputManager.preemptInputDispatch(); |
| 5278 | } |
| 5279 | |
| 5280 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5281 | // Focused app has changed. |
| 5282 | if (newApp == null) { |
| 5283 | mInputManager.setFocusedApplication(null); |
| 5284 | } else { |
| 5285 | mTempInputApplication.name = newApp.toString(); |
| 5286 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5287 | newApp.inputDispatchingTimeoutNanos; |
| 5288 | mTempInputApplication.token = newApp; |
| 5289 | |
| 5290 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5291 | } |
| 5292 | } |
| 5293 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5294 | public void pauseDispatchingLw(WindowToken window) { |
| 5295 | if (! window.paused) { |
| 5296 | if (DEBUG_INPUT) { |
| 5297 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5298 | } |
| 5299 | |
| 5300 | window.paused = true; |
| 5301 | updateInputWindowsLw(); |
| 5302 | } |
| 5303 | } |
| 5304 | |
| 5305 | public void resumeDispatchingLw(WindowToken window) { |
| 5306 | if (window.paused) { |
| 5307 | if (DEBUG_INPUT) { |
| 5308 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5309 | } |
| 5310 | |
| 5311 | window.paused = false; |
| 5312 | updateInputWindowsLw(); |
| 5313 | } |
| 5314 | } |
| 5315 | |
| 5316 | public void freezeInputDispatchingLw() { |
| 5317 | if (! mInputDispatchFrozen) { |
| 5318 | if (DEBUG_INPUT) { |
| 5319 | Slog.v(TAG, "Freezing input dispatching"); |
| 5320 | } |
| 5321 | |
| 5322 | mInputDispatchFrozen = true; |
| 5323 | updateInputDispatchModeLw(); |
| 5324 | } |
| 5325 | } |
| 5326 | |
| 5327 | public void thawInputDispatchingLw() { |
| 5328 | if (mInputDispatchFrozen) { |
| 5329 | if (DEBUG_INPUT) { |
| 5330 | Slog.v(TAG, "Thawing input dispatching"); |
| 5331 | } |
| 5332 | |
| 5333 | mInputDispatchFrozen = false; |
| 5334 | updateInputDispatchModeLw(); |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | public void setEventDispatchingLw(boolean enabled) { |
| 5339 | if (mInputDispatchEnabled != enabled) { |
| 5340 | if (DEBUG_INPUT) { |
| 5341 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5342 | } |
| 5343 | |
| 5344 | mInputDispatchEnabled = enabled; |
| 5345 | updateInputDispatchModeLw(); |
| 5346 | } |
| 5347 | } |
| 5348 | |
| 5349 | private void updateInputDispatchModeLw() { |
| 5350 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5351 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5352 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5354 | public void pauseKeyDispatching(IBinder _token) { |
| 5355 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5356 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5357 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | synchronized (mWindowMap) { |
| 5361 | WindowToken token = mTokenMap.get(_token); |
| 5362 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5363 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | } |
| 5367 | |
| 5368 | public void resumeKeyDispatching(IBinder _token) { |
| 5369 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5370 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5371 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5372 | } |
| 5373 | |
| 5374 | synchronized (mWindowMap) { |
| 5375 | WindowToken token = mTokenMap.get(_token); |
| 5376 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5377 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5378 | } |
| 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | public void setEventDispatching(boolean enabled) { |
| 5383 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5384 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5385 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5389 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5390 | } |
| 5391 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | /** |
| 5394 | * Injects a keystroke event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5395 | * |
| 5396 | * @param ev A motion event describing the keystroke action. (Be sure to use |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5398 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5399 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5400 | */ |
| 5401 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5402 | long downTime = ev.getDownTime(); |
| 5403 | long eventTime = ev.getEventTime(); |
| 5404 | |
| 5405 | int action = ev.getAction(); |
| 5406 | int code = ev.getKeyCode(); |
| 5407 | int repeatCount = ev.getRepeatCount(); |
| 5408 | int metaState = ev.getMetaState(); |
| 5409 | int deviceId = ev.getDeviceId(); |
| 5410 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 5411 | int source = ev.getSource(); |
| 5412 | |
| 5413 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5414 | source = InputDevice.SOURCE_KEYBOARD; |
| 5415 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5416 | |
| 5417 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5418 | if (downTime == 0) downTime = eventTime; |
| 5419 | |
| 5420 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 5421 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5422 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5423 | final int pid = Binder.getCallingPid(); |
| 5424 | final int uid = Binder.getCallingUid(); |
| 5425 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5426 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5427 | final int result = mInputManager.injectKeyEvent(newEvent, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 5428 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5429 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5430 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5431 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | /** |
| 5435 | * Inject a pointer (touch) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5436 | * |
| 5437 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5438 | * {@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] | 5439 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5440 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5441 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5442 | */ |
| 5443 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5444 | final int pid = Binder.getCallingPid(); |
| 5445 | final int uid = Binder.getCallingUid(); |
| 5446 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5447 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 5448 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5449 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5450 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5451 | } |
| 5452 | |
| 5453 | final int result = mInputManager.injectMotionEvent(newEvent, |
| 5454 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5455 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5456 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5457 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5458 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5460 | /** |
| 5461 | * Inject a trackball (navigation device) event into the UI. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5462 | * |
| 5463 | * @param ev A motion event describing the trackball action. (As noted in |
| 5464 | * {@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] | 5465 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5466 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5467 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5468 | */ |
| 5469 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5470 | final int pid = Binder.getCallingPid(); |
| 5471 | final int uid = Binder.getCallingUid(); |
| 5472 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5473 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 5474 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5475 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5476 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5477 | } |
| 5478 | |
| 5479 | final int result = mInputManager.injectMotionEvent(newEvent, |
| 5480 | pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5481 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5482 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5483 | return reportInjectionResult(result); |
| 5484 | } |
| 5485 | |
| 5486 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5487 | switch (result) { |
| 5488 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5489 | Slog.w(TAG, "Input event injection permission denied."); |
| 5490 | throw new SecurityException( |
| 5491 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5492 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| 5493 | Slog.v(TAG, "Input event injection succeeded."); |
| 5494 | return true; |
| 5495 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5496 | Slog.w(TAG, "Input event injection timed out."); |
| 5497 | return false; |
| 5498 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5499 | default: |
| 5500 | Slog.w(TAG, "Input event injection failed."); |
| 5501 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5502 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5503 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | private WindowState getFocusedWindow() { |
| 5506 | synchronized (mWindowMap) { |
| 5507 | return getFocusedWindowLocked(); |
| 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | private WindowState getFocusedWindowLocked() { |
| 5512 | return mCurrentFocus; |
| 5513 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5515 | public boolean detectSafeMode() { |
| 5516 | mSafeMode = mPolicy.detectSafeMode(); |
| 5517 | return mSafeMode; |
| 5518 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5520 | public void systemReady() { |
| 5521 | mPolicy.systemReady(); |
| 5522 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5524 | // ------------------------------------------------------------- |
| 5525 | // Client Session State |
| 5526 | // ------------------------------------------------------------- |
| 5527 | |
| 5528 | private final class Session extends IWindowSession.Stub |
| 5529 | implements IBinder.DeathRecipient { |
| 5530 | final IInputMethodClient mClient; |
| 5531 | final IInputContext mInputContext; |
| 5532 | final int mUid; |
| 5533 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5534 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5535 | SurfaceSession mSurfaceSession; |
| 5536 | int mNumWindow = 0; |
| 5537 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 5540 | mClient = client; |
| 5541 | mInputContext = inputContext; |
| 5542 | mUid = Binder.getCallingUid(); |
| 5543 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5544 | StringBuilder sb = new StringBuilder(); |
| 5545 | sb.append("Session{"); |
| 5546 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5547 | sb.append(" uid "); |
| 5548 | sb.append(mUid); |
| 5549 | sb.append("}"); |
| 5550 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | synchronized (mWindowMap) { |
| 5553 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 5554 | IBinder b = ServiceManager.getService( |
| 5555 | Context.INPUT_METHOD_SERVICE); |
| 5556 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 5557 | } |
| 5558 | } |
| 5559 | long ident = Binder.clearCallingIdentity(); |
| 5560 | try { |
| 5561 | // Note: it is safe to call in to the input method manager |
| 5562 | // here because we are not holding our lock. |
| 5563 | if (mInputMethodManager != null) { |
| 5564 | mInputMethodManager.addClient(client, inputContext, |
| 5565 | mUid, mPid); |
| 5566 | } else { |
| 5567 | client.setUsingInputMethod(false); |
| 5568 | } |
| 5569 | client.asBinder().linkToDeath(this, 0); |
| 5570 | } catch (RemoteException e) { |
| 5571 | // The caller has died, so we can just forget about this. |
| 5572 | try { |
| 5573 | if (mInputMethodManager != null) { |
| 5574 | mInputMethodManager.removeClient(client); |
| 5575 | } |
| 5576 | } catch (RemoteException ee) { |
| 5577 | } |
| 5578 | } finally { |
| 5579 | Binder.restoreCallingIdentity(ident); |
| 5580 | } |
| 5581 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5583 | @Override |
| 5584 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 5585 | throws RemoteException { |
| 5586 | try { |
| 5587 | return super.onTransact(code, data, reply, flags); |
| 5588 | } catch (RuntimeException e) { |
| 5589 | // Log all 'real' exceptions thrown to the caller |
| 5590 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5591 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5592 | } |
| 5593 | throw e; |
| 5594 | } |
| 5595 | } |
| 5596 | |
| 5597 | public void binderDied() { |
| 5598 | // Note: it is safe to call in to the input method manager |
| 5599 | // here because we are not holding our lock. |
| 5600 | try { |
| 5601 | if (mInputMethodManager != null) { |
| 5602 | mInputMethodManager.removeClient(mClient); |
| 5603 | } |
| 5604 | } catch (RemoteException e) { |
| 5605 | } |
| 5606 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5607 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5608 | mClientDead = true; |
| 5609 | killSessionLocked(); |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5614 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 5615 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 5616 | outInputChannel); |
| 5617 | } |
| 5618 | |
| 5619 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5620 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5621 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5622 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5624 | public void remove(IWindow window) { |
| 5625 | removeWindow(this, window); |
| 5626 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5628 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 5629 | int requestedWidth, int requestedHeight, int viewFlags, |
| 5630 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5631 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | return relayoutWindow(this, window, attrs, |
| 5633 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5634 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5635 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5637 | public void setTransparentRegion(IWindow window, Region region) { |
| 5638 | setTransparentRegionWindow(this, window, region); |
| 5639 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | public void setInsets(IWindow window, int touchableInsets, |
| 5642 | Rect contentInsets, Rect visibleInsets) { |
| 5643 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 5644 | visibleInsets); |
| 5645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5647 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 5648 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 5649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5651 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5652 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | TAG, "IWindow finishDrawing called for " + window); |
| 5654 | finishDrawingWindow(this, window); |
| 5655 | } |
| 5656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5657 | public void setInTouchMode(boolean mode) { |
| 5658 | synchronized(mWindowMap) { |
| 5659 | mInTouchMode = mode; |
| 5660 | } |
| 5661 | } |
| 5662 | |
| 5663 | public boolean getInTouchMode() { |
| 5664 | synchronized(mWindowMap) { |
| 5665 | return mInTouchMode; |
| 5666 | } |
| 5667 | } |
| 5668 | |
| 5669 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 5670 | boolean always) { |
| 5671 | synchronized(mWindowMap) { |
| 5672 | long ident = Binder.clearCallingIdentity(); |
| 5673 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5674 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5675 | windowForClientLocked(this, window, true), |
| 5676 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | } finally { |
| 5678 | Binder.restoreCallingIdentity(ident); |
| 5679 | } |
| 5680 | } |
| 5681 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5682 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5683 | 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] | 5684 | synchronized(mWindowMap) { |
| 5685 | long ident = Binder.clearCallingIdentity(); |
| 5686 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5687 | setWindowWallpaperPositionLocked( |
| 5688 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5689 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 5690 | } finally { |
| 5691 | Binder.restoreCallingIdentity(ident); |
| 5692 | } |
| 5693 | } |
| 5694 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5695 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 5696 | public void wallpaperOffsetsComplete(IBinder window) { |
| 5697 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 5698 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5699 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5700 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 5701 | int z, Bundle extras, boolean sync) { |
| 5702 | synchronized(mWindowMap) { |
| 5703 | long ident = Binder.clearCallingIdentity(); |
| 5704 | try { |
| 5705 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5706 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5707 | action, x, y, z, extras, sync); |
| 5708 | } finally { |
| 5709 | Binder.restoreCallingIdentity(ident); |
| 5710 | } |
| 5711 | } |
| 5712 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5713 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5714 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 5715 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 5716 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5718 | void windowAddedLocked() { |
| 5719 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5720 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5721 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 5722 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5723 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5724 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5725 | mSessions.add(this); |
| 5726 | } |
| 5727 | mNumWindow++; |
| 5728 | } |
| 5729 | |
| 5730 | void windowRemovedLocked() { |
| 5731 | mNumWindow--; |
| 5732 | killSessionLocked(); |
| 5733 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | void killSessionLocked() { |
| 5736 | if (mNumWindow <= 0 && mClientDead) { |
| 5737 | mSessions.remove(this); |
| 5738 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5739 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5740 | TAG, "Last window removed from " + this |
| 5741 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5742 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5743 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5744 | try { |
| 5745 | mSurfaceSession.kill(); |
| 5746 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5747 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | + mSurfaceSession + " in session " + this |
| 5749 | + ": " + e.toString()); |
| 5750 | } |
| 5751 | mSurfaceSession = null; |
| 5752 | } |
| 5753 | } |
| 5754 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5756 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5757 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 5758 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 5759 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5760 | } |
| 5761 | |
| 5762 | @Override |
| 5763 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5764 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | // ------------------------------------------------------------- |
| 5769 | // Client Window State |
| 5770 | // ------------------------------------------------------------- |
| 5771 | |
| 5772 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 5773 | final Session mSession; |
| 5774 | final IWindow mClient; |
| 5775 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5776 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | AppWindowToken mAppToken; |
| 5778 | AppWindowToken mTargetAppToken; |
| 5779 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 5780 | final DeathRecipient mDeathRecipient; |
| 5781 | final WindowState mAttachedWindow; |
| 5782 | final ArrayList mChildWindows = new ArrayList(); |
| 5783 | final int mBaseLayer; |
| 5784 | final int mSubLayer; |
| 5785 | final boolean mLayoutAttached; |
| 5786 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5787 | final boolean mIsWallpaper; |
| 5788 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | int mViewVisibility; |
| 5790 | boolean mPolicyVisibility = true; |
| 5791 | boolean mPolicyVisibilityAfterAnim = true; |
| 5792 | boolean mAppFreezing; |
| 5793 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5794 | boolean mReportDestroySurface; |
| 5795 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5796 | boolean mAttachedHidden; // is our parent window hidden? |
| 5797 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 5798 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5799 | int mRequestedWidth; |
| 5800 | int mRequestedHeight; |
| 5801 | int mLastRequestedWidth; |
| 5802 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | int mLayer; |
| 5804 | int mAnimLayer; |
| 5805 | int mLastLayer; |
| 5806 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 5807 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 5808 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5809 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5810 | int mLayoutSeq = -1; |
| 5811 | |
| 5812 | Configuration mConfiguration = null; |
| 5813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5814 | // Actual frame shown on-screen (may be modified by animation) |
| 5815 | final Rect mShownFrame = new Rect(); |
| 5816 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 5819 | * Set when we have changed the size of the surface, to know that |
| 5820 | * we must tell them application to resize (and thus redraw itself). |
| 5821 | */ |
| 5822 | boolean mSurfaceResized; |
| 5823 | |
| 5824 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | * Insets that determine the actually visible area |
| 5826 | */ |
| 5827 | final Rect mVisibleInsets = new Rect(); |
| 5828 | final Rect mLastVisibleInsets = new Rect(); |
| 5829 | boolean mVisibleInsetsChanged; |
| 5830 | |
| 5831 | /** |
| 5832 | * Insets that are covered by system windows |
| 5833 | */ |
| 5834 | final Rect mContentInsets = new Rect(); |
| 5835 | final Rect mLastContentInsets = new Rect(); |
| 5836 | boolean mContentInsetsChanged; |
| 5837 | |
| 5838 | /** |
| 5839 | * Set to true if we are waiting for this window to receive its |
| 5840 | * given internal insets before laying out other windows based on it. |
| 5841 | */ |
| 5842 | boolean mGivenInsetsPending; |
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 | * These are the content insets that were given during layout for |
| 5846 | * this window, to be applied to windows behind it. |
| 5847 | */ |
| 5848 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5850 | /** |
| 5851 | * These are the visible insets that were given during layout for |
| 5852 | * this window, to be applied to windows behind it. |
| 5853 | */ |
| 5854 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5856 | /** |
| 5857 | * Flag indicating whether the touchable region should be adjusted by |
| 5858 | * the visible insets; if false the area outside the visible insets is |
| 5859 | * NOT touchable, so we must use those to adjust the frame during hit |
| 5860 | * tests. |
| 5861 | */ |
| 5862 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5864 | // Current transformation being applied. |
| 5865 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 5866 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 5867 | float mHScale=1, mVScale=1; |
| 5868 | float mLastHScale=1, mLastVScale=1; |
| 5869 | final Matrix mTmpMatrix = new Matrix(); |
| 5870 | |
| 5871 | // "Real" frame that the application sees. |
| 5872 | final Rect mFrame = new Rect(); |
| 5873 | final Rect mLastFrame = new Rect(); |
| 5874 | |
| 5875 | final Rect mContainingFrame = new Rect(); |
| 5876 | final Rect mDisplayFrame = new Rect(); |
| 5877 | final Rect mContentFrame = new Rect(); |
| 5878 | final Rect mVisibleFrame = new Rect(); |
| 5879 | |
| 5880 | float mShownAlpha = 1; |
| 5881 | float mAlpha = 1; |
| 5882 | float mLastAlpha = 1; |
| 5883 | |
| 5884 | // Set to true if, when the window gets displayed, it should perform |
| 5885 | // an enter animation. |
| 5886 | boolean mEnterAnimationPending; |
| 5887 | |
| 5888 | // Currently running animation. |
| 5889 | boolean mAnimating; |
| 5890 | boolean mLocalAnimating; |
| 5891 | Animation mAnimation; |
| 5892 | boolean mAnimationIsEntrance; |
| 5893 | boolean mHasTransformation; |
| 5894 | boolean mHasLocalTransformation; |
| 5895 | final Transformation mTransformation = new Transformation(); |
| 5896 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5897 | // If a window showing a wallpaper: the requested offset for the |
| 5898 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 5899 | float mWallpaperX = -1; |
| 5900 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5901 | |
| 5902 | // If a window showing a wallpaper: what fraction of the offset |
| 5903 | // range corresponds to a full virtual screen. |
| 5904 | float mWallpaperXStep = -1; |
| 5905 | float mWallpaperYStep = -1; |
| 5906 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5907 | // Wallpaper windows: pixels offset based on above variables. |
| 5908 | int mXOffset; |
| 5909 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5911 | // This is set after IWindowSession.relayout() has been called at |
| 5912 | // least once for the window. It allows us to detect the situation |
| 5913 | // where we don't yet have a surface, but should have one soon, so |
| 5914 | // we can give the window focus before waiting for the relayout. |
| 5915 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5917 | // This is set after the Surface has been created but before the |
| 5918 | // window has been drawn. During this time the surface is hidden. |
| 5919 | boolean mDrawPending; |
| 5920 | |
| 5921 | // This is set after the window has finished drawing for the first |
| 5922 | // time but before its surface is shown. The surface will be |
| 5923 | // displayed when the next layout is run. |
| 5924 | boolean mCommitDrawPending; |
| 5925 | |
| 5926 | // This is set during the time after the window's drawing has been |
| 5927 | // committed, and before its surface is actually shown. It is used |
| 5928 | // to delay showing the surface until all windows in a token are ready |
| 5929 | // to be shown. |
| 5930 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | // Set when the window has been shown in the screen the first time. |
| 5933 | boolean mHasDrawn; |
| 5934 | |
| 5935 | // Currently running an exit animation? |
| 5936 | boolean mExiting; |
| 5937 | |
| 5938 | // Currently on the mDestroySurface list? |
| 5939 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5940 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5941 | // Completely remove from window manager after exit animation? |
| 5942 | boolean mRemoveOnExit; |
| 5943 | |
| 5944 | // Set when the orientation is changing and this window has not yet |
| 5945 | // been updated for the new orientation. |
| 5946 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | // Is this window now (or just being) removed? |
| 5949 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5950 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 5951 | // For debugging, this is the last information given to the surface flinger. |
| 5952 | boolean mSurfaceShown; |
| 5953 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 5954 | int mSurfaceLayer; |
| 5955 | float mSurfaceAlpha; |
| 5956 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5957 | // Input channel |
| 5958 | InputChannel mInputChannel; |
| 5959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5960 | WindowState(Session s, IWindow c, WindowToken token, |
| 5961 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 5962 | int viewVisibility) { |
| 5963 | mSession = s; |
| 5964 | mClient = c; |
| 5965 | mToken = token; |
| 5966 | mAttrs.copyFrom(a); |
| 5967 | mViewVisibility = viewVisibility; |
| 5968 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 5969 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5970 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5971 | TAG, "Window " + this + " client=" + c.asBinder() |
| 5972 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 5973 | try { |
| 5974 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 5975 | } catch (RemoteException e) { |
| 5976 | mDeathRecipient = null; |
| 5977 | mAttachedWindow = null; |
| 5978 | mLayoutAttached = false; |
| 5979 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5980 | mIsWallpaper = false; |
| 5981 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5982 | mBaseLayer = 0; |
| 5983 | mSubLayer = 0; |
| 5984 | return; |
| 5985 | } |
| 5986 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5987 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5988 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 5989 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 5990 | // The multiplier here is to reserve space for multiple |
| 5991 | // windows in the same type layer. |
| 5992 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 5993 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 5994 | + TYPE_LAYER_OFFSET; |
| 5995 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 5996 | mAttachedWindow = attachedWindow; |
| 5997 | mAttachedWindow.mChildWindows.add(this); |
| 5998 | mLayoutAttached = mAttrs.type != |
| 5999 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6000 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6001 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6002 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6003 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6004 | } else { |
| 6005 | // The multiplier here is to reserve space for multiple |
| 6006 | // windows in the same type layer. |
| 6007 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6008 | * TYPE_LAYER_MULTIPLIER |
| 6009 | + TYPE_LAYER_OFFSET; |
| 6010 | mSubLayer = 0; |
| 6011 | mAttachedWindow = null; |
| 6012 | mLayoutAttached = false; |
| 6013 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6014 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6015 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6016 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | WindowState appWin = this; |
| 6020 | while (appWin.mAttachedWindow != null) { |
| 6021 | appWin = mAttachedWindow; |
| 6022 | } |
| 6023 | WindowToken appToken = appWin.mToken; |
| 6024 | while (appToken.appWindowToken == null) { |
| 6025 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6026 | if (parent == null || appToken == parent) { |
| 6027 | break; |
| 6028 | } |
| 6029 | appToken = parent; |
| 6030 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6031 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6032 | mAppToken = appToken.appWindowToken; |
| 6033 | |
| 6034 | mSurface = null; |
| 6035 | mRequestedWidth = 0; |
| 6036 | mRequestedHeight = 0; |
| 6037 | mLastRequestedWidth = 0; |
| 6038 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6039 | mXOffset = 0; |
| 6040 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6041 | mLayer = 0; |
| 6042 | mAnimLayer = 0; |
| 6043 | mLastLayer = 0; |
| 6044 | } |
| 6045 | |
| 6046 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6047 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6048 | TAG, "Attaching " + this + " token=" + mToken |
| 6049 | + ", list=" + mToken.windows); |
| 6050 | mSession.windowAddedLocked(); |
| 6051 | } |
| 6052 | |
| 6053 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6054 | mHaveFrame = true; |
| 6055 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6056 | final Rect container = mContainingFrame; |
| 6057 | container.set(pf); |
| 6058 | |
| 6059 | final Rect display = mDisplayFrame; |
| 6060 | display.set(df); |
| 6061 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6062 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6063 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6064 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6065 | display.intersect(mCompatibleScreenFrame); |
| 6066 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6067 | } |
| 6068 | |
| 6069 | final int pw = container.right - container.left; |
| 6070 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6071 | |
| 6072 | int w,h; |
| 6073 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6074 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6075 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6076 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6077 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6078 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6079 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6081 | final Rect content = mContentFrame; |
| 6082 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6084 | final Rect visible = mVisibleFrame; |
| 6085 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6087 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6088 | final int fw = frame.width(); |
| 6089 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6091 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6092 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6093 | |
| 6094 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6095 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6096 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6097 | |
| 6098 | //System.out.println("Out: " + mFrame); |
| 6099 | |
| 6100 | // Now make sure the window fits in the overall display. |
| 6101 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6103 | // Make sure the content and visible frames are inside of the |
| 6104 | // final window frame. |
| 6105 | if (content.left < frame.left) content.left = frame.left; |
| 6106 | if (content.top < frame.top) content.top = frame.top; |
| 6107 | if (content.right > frame.right) content.right = frame.right; |
| 6108 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6109 | if (visible.left < frame.left) visible.left = frame.left; |
| 6110 | if (visible.top < frame.top) visible.top = frame.top; |
| 6111 | if (visible.right > frame.right) visible.right = frame.right; |
| 6112 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6114 | final Rect contentInsets = mContentInsets; |
| 6115 | contentInsets.left = content.left-frame.left; |
| 6116 | contentInsets.top = content.top-frame.top; |
| 6117 | contentInsets.right = frame.right-content.right; |
| 6118 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6120 | final Rect visibleInsets = mVisibleInsets; |
| 6121 | visibleInsets.left = visible.left-frame.left; |
| 6122 | visibleInsets.top = visible.top-frame.top; |
| 6123 | visibleInsets.right = frame.right-visible.right; |
| 6124 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6125 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6126 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6127 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6128 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6129 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6131 | if (localLOGV) { |
| 6132 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6133 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6134 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6135 | + mRequestedWidth + ", mRequestedheight=" |
| 6136 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6137 | + "): frame=" + mFrame.toShortString() |
| 6138 | + " ci=" + contentInsets.toShortString() |
| 6139 | + " vi=" + visibleInsets.toShortString()); |
| 6140 | //} |
| 6141 | } |
| 6142 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | public Rect getFrameLw() { |
| 6145 | return mFrame; |
| 6146 | } |
| 6147 | |
| 6148 | public Rect getShownFrameLw() { |
| 6149 | return mShownFrame; |
| 6150 | } |
| 6151 | |
| 6152 | public Rect getDisplayFrameLw() { |
| 6153 | return mDisplayFrame; |
| 6154 | } |
| 6155 | |
| 6156 | public Rect getContentFrameLw() { |
| 6157 | return mContentFrame; |
| 6158 | } |
| 6159 | |
| 6160 | public Rect getVisibleFrameLw() { |
| 6161 | return mVisibleFrame; |
| 6162 | } |
| 6163 | |
| 6164 | public boolean getGivenInsetsPendingLw() { |
| 6165 | return mGivenInsetsPending; |
| 6166 | } |
| 6167 | |
| 6168 | public Rect getGivenContentInsetsLw() { |
| 6169 | return mGivenContentInsets; |
| 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 Rect getGivenVisibleInsetsLw() { |
| 6173 | return mGivenVisibleInsets; |
| 6174 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6176 | public WindowManager.LayoutParams getAttrs() { |
| 6177 | return mAttrs; |
| 6178 | } |
| 6179 | |
| 6180 | public int getSurfaceLayer() { |
| 6181 | return mLayer; |
| 6182 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6184 | public IApplicationToken getAppToken() { |
| 6185 | return mAppToken != null ? mAppToken.appToken : null; |
| 6186 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6187 | |
| 6188 | public long getInputDispatchingTimeoutNanos() { |
| 6189 | return mAppToken != null |
| 6190 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6191 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6193 | |
| 6194 | public boolean hasAppShownWindows() { |
| 6195 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6196 | } |
| 6197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6198 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6199 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6200 | TAG, "Setting animation in " + this + ": " + anim); |
| 6201 | mAnimating = false; |
| 6202 | mLocalAnimating = false; |
| 6203 | mAnimation = anim; |
| 6204 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6205 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6206 | } |
| 6207 | |
| 6208 | public void clearAnimation() { |
| 6209 | if (mAnimation != null) { |
| 6210 | mAnimating = true; |
| 6211 | mLocalAnimating = false; |
| 6212 | mAnimation = null; |
| 6213 | } |
| 6214 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6216 | Surface createSurfaceLocked() { |
| 6217 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6218 | mReportDestroySurface = false; |
| 6219 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6220 | mDrawPending = true; |
| 6221 | mCommitDrawPending = false; |
| 6222 | mReadyToShow = false; |
| 6223 | if (mAppToken != null) { |
| 6224 | mAppToken.allDrawn = false; |
| 6225 | } |
| 6226 | |
| 6227 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6228 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | flags |= Surface.PUSH_BUFFERS; |
| 6230 | } |
| 6231 | |
| 6232 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6233 | flags |= Surface.SECURE; |
| 6234 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6235 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6236 | TAG, "Creating surface in session " |
| 6237 | + mSession.mSurfaceSession + " window " + this |
| 6238 | + " w=" + mFrame.width() |
| 6239 | + " h=" + mFrame.height() + " format=" |
| 6240 | + mAttrs.format + " flags=" + flags); |
| 6241 | |
| 6242 | int w = mFrame.width(); |
| 6243 | int h = mFrame.height(); |
| 6244 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6245 | // for a scaled surface, we always want the requested |
| 6246 | // size. |
| 6247 | w = mRequestedWidth; |
| 6248 | h = mRequestedHeight; |
| 6249 | } |
| 6250 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6251 | // Something is wrong and SurfaceFlinger will not like this, |
| 6252 | // try to revert to sane values |
| 6253 | if (w <= 0) w = 1; |
| 6254 | if (h <= 0) h = 1; |
| 6255 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6256 | mSurfaceShown = false; |
| 6257 | mSurfaceLayer = 0; |
| 6258 | mSurfaceAlpha = 1; |
| 6259 | mSurfaceX = 0; |
| 6260 | mSurfaceY = 0; |
| 6261 | mSurfaceW = w; |
| 6262 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | try { |
| 6264 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6265 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6266 | mAttrs.getTitle().toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | 0, w, h, mAttrs.format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6268 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6269 | + mSurface + " IN SESSION " |
| 6270 | + mSession.mSurfaceSession |
| 6271 | + ": pid=" + mSession.mPid + " format=" |
| 6272 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6273 | + Integer.toHexString(flags) |
| 6274 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6275 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6276 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6278 | return null; |
| 6279 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6280 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6281 | return null; |
| 6282 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6283 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6284 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | TAG, "Got surface: " + mSurface |
| 6286 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6287 | + ", animLayer=" + mAnimLayer); |
| 6288 | if (SHOW_TRANSACTIONS) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6289 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6290 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6291 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6292 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6293 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6294 | } |
| 6295 | Surface.openTransaction(); |
| 6296 | try { |
| 6297 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6298 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6299 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6300 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6301 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6302 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6303 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | mSurface.hide(); |
| 6305 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6306 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6307 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6308 | Surface.SURFACE_DITHER); |
| 6309 | } |
| 6310 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6311 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6312 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6313 | } |
| 6314 | mLastHidden = true; |
| 6315 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6316 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6317 | Surface.closeTransaction(); |
| 6318 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6319 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6320 | TAG, "Created surface " + this); |
| 6321 | } |
| 6322 | return mSurface; |
| 6323 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6325 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6326 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6327 | mAppToken.startingDisplayed = false; |
| 6328 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6330 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6331 | mDrawPending = false; |
| 6332 | mCommitDrawPending = false; |
| 6333 | mReadyToShow = false; |
| 6334 | |
| 6335 | int i = mChildWindows.size(); |
| 6336 | while (i > 0) { |
| 6337 | i--; |
| 6338 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6339 | c.mAttachedHidden = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6340 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6341 | mInputMonitor.windowIsBecomingInvisibleLw(c); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6342 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6343 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6344 | if (mReportDestroySurface) { |
| 6345 | mReportDestroySurface = false; |
| 6346 | mSurfacePendingDestroy = true; |
| 6347 | try { |
| 6348 | mClient.dispatchGetNewSurface(); |
| 6349 | // We'll really destroy on the next time around. |
| 6350 | return; |
| 6351 | } catch (RemoteException e) { |
| 6352 | } |
| 6353 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6356 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6357 | RuntimeException e = null; |
| 6358 | if (!HIDE_STACK_CRAWLS) { |
| 6359 | e = new RuntimeException(); |
| 6360 | e.fillInStackTrace(); |
| 6361 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6362 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6363 | + mSurface + ", session " + mSession, e); |
| 6364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6365 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6366 | RuntimeException e = null; |
| 6367 | if (!HIDE_STACK_CRAWLS) { |
| 6368 | e = new RuntimeException(); |
| 6369 | e.fillInStackTrace(); |
| 6370 | } |
| 6371 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6372 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6373 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6374 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6375 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | + " surface " + mSurface + " session " + mSession |
| 6377 | + ": " + e.toString()); |
| 6378 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6379 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6380 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6381 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6382 | } |
| 6383 | } |
| 6384 | |
| 6385 | boolean finishDrawingLocked() { |
| 6386 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6387 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6388 | TAG, "finishDrawingLocked: " + mSurface); |
| 6389 | mCommitDrawPending = true; |
| 6390 | mDrawPending = false; |
| 6391 | return true; |
| 6392 | } |
| 6393 | return false; |
| 6394 | } |
| 6395 | |
| 6396 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6397 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6398 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6399 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6400 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | } |
| 6402 | mCommitDrawPending = false; |
| 6403 | mReadyToShow = true; |
| 6404 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6405 | final AppWindowToken atoken = mAppToken; |
| 6406 | if (atoken == null || atoken.allDrawn || starting) { |
| 6407 | performShowLocked(); |
| 6408 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6409 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | // This must be called while inside a transaction. |
| 6413 | boolean performShowLocked() { |
| 6414 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6415 | RuntimeException e = null; |
| 6416 | if (!HIDE_STACK_CRAWLS) { |
| 6417 | e = new RuntimeException(); |
| 6418 | e.fillInStackTrace(); |
| 6419 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6420 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6421 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6422 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6423 | } |
| 6424 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6425 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 6426 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6427 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6428 | + " during animation: policyVis=" + mPolicyVisibility |
| 6429 | + " attHidden=" + mAttachedHidden |
| 6430 | + " tok.hiddenRequested=" |
| 6431 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6432 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6433 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6434 | + " animating=" + mAnimating |
| 6435 | + " tok animating=" |
| 6436 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6437 | if (!showSurfaceRobustlyLocked(this)) { |
| 6438 | return false; |
| 6439 | } |
| 6440 | mLastAlpha = -1; |
| 6441 | mHasDrawn = true; |
| 6442 | mLastHidden = false; |
| 6443 | mReadyToShow = false; |
| 6444 | enableScreenIfNeededLocked(); |
| 6445 | |
| 6446 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | int i = mChildWindows.size(); |
| 6449 | while (i > 0) { |
| 6450 | i--; |
| 6451 | WindowState c = (WindowState)mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6452 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6454 | if (c.mSurface != null) { |
| 6455 | c.performShowLocked(); |
| 6456 | // It hadn't been shown, which means layout not |
| 6457 | // performed on it, so now we want to make sure to |
| 6458 | // do a layout. If called from within the transaction |
| 6459 | // loop, this will cause it to restart with a new |
| 6460 | // layout. |
| 6461 | mLayoutNeeded = true; |
| 6462 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6463 | } |
| 6464 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6467 | && mAppToken != null) { |
| 6468 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6469 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6470 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6471 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6472 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6473 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6474 | // If this initial window is animating, stop it -- we |
| 6475 | // will do an animation to reveal it from behind the |
| 6476 | // starting window, so there is no need for it to also |
| 6477 | // be doing its own stuff. |
| 6478 | if (mAnimation != null) { |
| 6479 | mAnimation = null; |
| 6480 | // Make sure we clean up the animation. |
| 6481 | mAnimating = true; |
| 6482 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | mFinishedStarting.add(mAppToken); |
| 6484 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6485 | } |
| 6486 | mAppToken.updateReportedVisibilityLocked(); |
| 6487 | } |
| 6488 | } |
| 6489 | return true; |
| 6490 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6492 | // This must be called while inside a transaction. Returns true if |
| 6493 | // there is more animation to run. |
| 6494 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6495 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6496 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6498 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6499 | mHasTransformation = true; |
| 6500 | mHasLocalTransformation = true; |
| 6501 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6502 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6503 | TAG, "Starting animation in " + this + |
| 6504 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6505 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6506 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6507 | mAnimation.setStartTime(currentTime); |
| 6508 | mLocalAnimating = true; |
| 6509 | mAnimating = true; |
| 6510 | } |
| 6511 | mTransformation.clear(); |
| 6512 | final boolean more = mAnimation.getTransformation( |
| 6513 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6514 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6515 | TAG, "Stepped animation in " + this + |
| 6516 | ": more=" + more + ", xform=" + mTransformation); |
| 6517 | if (more) { |
| 6518 | // we're not done! |
| 6519 | return true; |
| 6520 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6521 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6522 | TAG, "Finished animation in " + this + |
| 6523 | " @ " + currentTime); |
| 6524 | mAnimation = null; |
| 6525 | //WindowManagerService.this.dump(); |
| 6526 | } |
| 6527 | mHasLocalTransformation = false; |
| 6528 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6529 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6530 | // When our app token is animating, we kind-of pretend like |
| 6531 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6532 | // part of this check means that we will only do this if |
| 6533 | // our window is not currently exiting, or it is not |
| 6534 | // locally animating itself. The idea being that one that |
| 6535 | // is exiting and doing a local animation should be removed |
| 6536 | // once that animation is done. |
| 6537 | mAnimating = true; |
| 6538 | mHasTransformation = true; |
| 6539 | mTransformation.clear(); |
| 6540 | return false; |
| 6541 | } else if (mHasTransformation) { |
| 6542 | // Little trick to get through the path below to act like |
| 6543 | // we have finished an animation. |
| 6544 | mAnimating = true; |
| 6545 | } else if (isAnimating()) { |
| 6546 | mAnimating = true; |
| 6547 | } |
| 6548 | } else if (mAnimation != null) { |
| 6549 | // If the display is frozen, and there is a pending animation, |
| 6550 | // clear it and make sure we run the cleanup code. |
| 6551 | mAnimating = true; |
| 6552 | mLocalAnimating = true; |
| 6553 | mAnimation = null; |
| 6554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6556 | if (!mAnimating && !mLocalAnimating) { |
| 6557 | return false; |
| 6558 | } |
| 6559 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6560 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6561 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6562 | + ", reportedVisible=" |
| 6563 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6564 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6565 | mAnimating = false; |
| 6566 | mLocalAnimating = false; |
| 6567 | mAnimation = null; |
| 6568 | mAnimLayer = mLayer; |
| 6569 | if (mIsImWindow) { |
| 6570 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6571 | } else if (mIsWallpaper) { |
| 6572 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6573 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6574 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6575 | + " anim layer: " + mAnimLayer); |
| 6576 | mHasTransformation = false; |
| 6577 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6578 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 6579 | if (DEBUG_VISIBILITY) { |
| 6580 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 6581 | + mPolicyVisibilityAfterAnim); |
| 6582 | } |
| 6583 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6584 | if (!mPolicyVisibility) { |
| 6585 | if (mCurrentFocus == this) { |
| 6586 | mFocusMayChange = true; |
| 6587 | } |
| 6588 | // Window is no longer visible -- make sure if we were waiting |
| 6589 | // for it to be displayed before enabling the display, that |
| 6590 | // we allow the display to be enabled now. |
| 6591 | enableScreenIfNeededLocked(); |
| 6592 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 6593 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6594 | mTransformation.clear(); |
| 6595 | if (mHasDrawn |
| 6596 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6597 | && mAppToken != null |
| 6598 | && mAppToken.firstWindowDrawn |
| 6599 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6600 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | + mToken + ": first real window done animating"); |
| 6602 | mFinishedStarting.add(mAppToken); |
| 6603 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6604 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6606 | finishExit(); |
| 6607 | |
| 6608 | if (mAppToken != null) { |
| 6609 | mAppToken.updateReportedVisibilityLocked(); |
| 6610 | } |
| 6611 | |
| 6612 | return false; |
| 6613 | } |
| 6614 | |
| 6615 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6616 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6617 | TAG, "finishExit in " + this |
| 6618 | + ": exiting=" + mExiting |
| 6619 | + " remove=" + mRemoveOnExit |
| 6620 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6622 | final int N = mChildWindows.size(); |
| 6623 | for (int i=0; i<N; i++) { |
| 6624 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 6625 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6627 | if (!mExiting) { |
| 6628 | return; |
| 6629 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6631 | if (isWindowAnimating()) { |
| 6632 | return; |
| 6633 | } |
| 6634 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6635 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6636 | TAG, "Exit animation finished in " + this |
| 6637 | + ": remove=" + mRemoveOnExit); |
| 6638 | if (mSurface != null) { |
| 6639 | mDestroySurface.add(this); |
| 6640 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6641 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6642 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6643 | try { |
| 6644 | mSurface.hide(); |
| 6645 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6646 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | } |
| 6648 | mLastHidden = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6649 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6650 | for (int i=0; i<N; i++) { |
| 6651 | mInputMonitor.windowIsBecomingInvisibleLw((WindowState)mChildWindows.get(i)); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6652 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6653 | } |
| 6654 | mExiting = false; |
| 6655 | if (mRemoveOnExit) { |
| 6656 | mPendingRemove.add(this); |
| 6657 | mRemoveOnExit = false; |
| 6658 | } |
| 6659 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6661 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 6662 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 6663 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 6664 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 6665 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 6666 | return true; |
| 6667 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6669 | void computeShownFrameLocked() { |
| 6670 | final boolean selfTransformation = mHasLocalTransformation; |
| 6671 | Transformation attachedTransformation = |
| 6672 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 6673 | ? mAttachedWindow.mTransformation : null; |
| 6674 | Transformation appTransformation = |
| 6675 | (mAppToken != null && mAppToken.hasTransformation) |
| 6676 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6677 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6678 | // Wallpapers are animated based on the "real" window they |
| 6679 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6680 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 6681 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6682 | if (mWallpaperTarget.mHasLocalTransformation && |
| 6683 | mWallpaperTarget.mAnimation != null && |
| 6684 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6685 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6686 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6687 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6688 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6689 | } |
| 6690 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6691 | mWallpaperTarget.mAppToken.hasTransformation && |
| 6692 | mWallpaperTarget.mAppToken.animation != null && |
| 6693 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6694 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6695 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6696 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6697 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6698 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6699 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6701 | if (selfTransformation || attachedTransformation != null |
| 6702 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6703 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6704 | final Rect frame = mFrame; |
| 6705 | final float tmpFloats[] = mTmpFloats; |
| 6706 | final Matrix tmpMatrix = mTmpMatrix; |
| 6707 | |
| 6708 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6709 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6710 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6711 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6712 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6713 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6714 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6715 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6716 | } |
| 6717 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6718 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | // "convert" it into SurfaceFlinger's format |
| 6722 | // (a 2x2 matrix + an offset) |
| 6723 | // Here we must not transform the position of the surface |
| 6724 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6725 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6727 | tmpMatrix.getValues(tmpFloats); |
| 6728 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 6729 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 6730 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 6731 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6732 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 6733 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | int w = frame.width(); |
| 6735 | int h = frame.height(); |
| 6736 | mShownFrame.set(x, y, x+w, y+h); |
| 6737 | |
| 6738 | // Now set the alpha... but because our current hardware |
| 6739 | // can't do alpha transformation on a non-opaque surface, |
| 6740 | // turn it off if we are running an animation that is also |
| 6741 | // transforming since it is more important to have that |
| 6742 | // animation be smooth. |
| 6743 | mShownAlpha = mAlpha; |
| 6744 | if (!mLimitedAlphaCompositing |
| 6745 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 6746 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 6747 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6748 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | if (selfTransformation) { |
| 6750 | mShownAlpha *= mTransformation.getAlpha(); |
| 6751 | } |
| 6752 | if (attachedTransformation != null) { |
| 6753 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 6754 | } |
| 6755 | if (appTransformation != null) { |
| 6756 | mShownAlpha *= appTransformation.getAlpha(); |
| 6757 | } |
| 6758 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6759 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6760 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6761 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6762 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6763 | TAG, "Continuing animation in " + this + |
| 6764 | ": " + mShownFrame + |
| 6765 | ", alpha=" + mTransformation.getAlpha()); |
| 6766 | return; |
| 6767 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6770 | if (mXOffset != 0 || mYOffset != 0) { |
| 6771 | mShownFrame.offset(mXOffset, mYOffset); |
| 6772 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | mShownAlpha = mAlpha; |
| 6774 | mDsDx = 1; |
| 6775 | mDtDx = 0; |
| 6776 | mDsDy = 0; |
| 6777 | mDtDy = 1; |
| 6778 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6780 | /** |
| 6781 | * Is this window visible? It is not visible if there is no |
| 6782 | * surface, or we are in the process of running an exit animation |
| 6783 | * that will remove the surface, or its app token has been hidden. |
| 6784 | */ |
| 6785 | public boolean isVisibleLw() { |
| 6786 | final AppWindowToken atoken = mAppToken; |
| 6787 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6788 | && (atoken == null || !atoken.hiddenRequested) |
| 6789 | && !mExiting && !mDestroying; |
| 6790 | } |
| 6791 | |
| 6792 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6793 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 6794 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 6795 | * things like window flags that impact the keyguard. |
| 6796 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 6797 | * for this "hidden behind keyguard" state rather than overloading |
| 6798 | * mPolicyVisibility. Ungh. |
| 6799 | */ |
| 6800 | public boolean isVisibleOrBehindKeyguardLw() { |
| 6801 | final AppWindowToken atoken = mAppToken; |
| 6802 | return mSurface != null && !mAttachedHidden |
| 6803 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6804 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)) |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6805 | && !mExiting && !mDestroying; |
| 6806 | } |
| 6807 | |
| 6808 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6809 | * Is this window visible, ignoring its app token? It is not visible |
| 6810 | * if there is no surface, or we are in the process of running an exit animation |
| 6811 | * that will remove the surface. |
| 6812 | */ |
| 6813 | public boolean isWinVisibleLw() { |
| 6814 | final AppWindowToken atoken = mAppToken; |
| 6815 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6816 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 6817 | && !mExiting && !mDestroying; |
| 6818 | } |
| 6819 | |
| 6820 | /** |
| 6821 | * The same as isVisible(), but follows the current hidden state of |
| 6822 | * the associated app token, not the pending requested hidden state. |
| 6823 | */ |
| 6824 | boolean isVisibleNow() { |
| 6825 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6826 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | } |
| 6828 | |
| 6829 | /** |
| 6830 | * Same as isVisible(), but we also count it as visible between the |
| 6831 | * call to IWindowSession.add() and the first relayout(). |
| 6832 | */ |
| 6833 | boolean isVisibleOrAdding() { |
| 6834 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6835 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 6837 | && mPolicyVisibility && !mAttachedHidden |
| 6838 | && (atoken == null || !atoken.hiddenRequested) |
| 6839 | && !mExiting && !mDestroying; |
| 6840 | } |
| 6841 | |
| 6842 | /** |
| 6843 | * Is this window currently on-screen? It is on-screen either if it |
| 6844 | * is visible or it is currently running an animation before no longer |
| 6845 | * being visible. |
| 6846 | */ |
| 6847 | boolean isOnScreen() { |
| 6848 | final AppWindowToken atoken = mAppToken; |
| 6849 | if (atoken != null) { |
| 6850 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6851 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6852 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6853 | } else { |
| 6854 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6855 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | } |
| 6857 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6859 | /** |
| 6860 | * Like isOnScreen(), but we don't return true if the window is part |
| 6861 | * of a transition that has not yet been started. |
| 6862 | */ |
| 6863 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6864 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 6865 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6866 | return false; |
| 6867 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6868 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6869 | final boolean animating = atoken != null |
| 6870 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6871 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6872 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 6873 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6874 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | } |
| 6876 | |
| 6877 | /** Is the window or its container currently animating? */ |
| 6878 | boolean isAnimating() { |
| 6879 | final WindowState attached = mAttachedWindow; |
| 6880 | final AppWindowToken atoken = mAppToken; |
| 6881 | return mAnimation != null |
| 6882 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6883 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6884 | (atoken.animation != null |
| 6885 | || atoken.inPendingTransaction)); |
| 6886 | } |
| 6887 | |
| 6888 | /** Is this window currently animating? */ |
| 6889 | boolean isWindowAnimating() { |
| 6890 | return mAnimation != null; |
| 6891 | } |
| 6892 | |
| 6893 | /** |
| 6894 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 6895 | * been drawn. |
| 6896 | */ |
| 6897 | public boolean isDisplayedLw() { |
| 6898 | final AppWindowToken atoken = mAppToken; |
| 6899 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6900 | && !mDrawPending && !mCommitDrawPending |
| 6901 | && ((!mAttachedHidden && |
| 6902 | (atoken == null || !atoken.hiddenRequested)) |
| 6903 | || mAnimating); |
| 6904 | } |
| 6905 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6906 | /** |
| 6907 | * Returns true if the window has a surface that it has drawn a |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6908 | * complete UI in to. Note that this returns true if the orientation |
| 6909 | * is changing even if the window hasn't redrawn because we don't want |
| 6910 | * to stop things from executing during that time. |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6911 | */ |
| 6912 | public boolean isDrawnLw() { |
| 6913 | final AppWindowToken atoken = mAppToken; |
| 6914 | return mSurface != null && !mDestroying |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6915 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6916 | } |
| 6917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6918 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 6919 | boolean shownFrame, boolean onlyOpaque) { |
| 6920 | if (mSurface == null) { |
| 6921 | return false; |
| 6922 | } |
| 6923 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 6924 | return false; |
| 6925 | } |
| 6926 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 6927 | return false; |
| 6928 | } |
| 6929 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6930 | |
| 6931 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 6932 | return frame.left <= mCompatibleScreenFrame.left && |
| 6933 | frame.top <= mCompatibleScreenFrame.top && |
| 6934 | frame.right >= mCompatibleScreenFrame.right && |
| 6935 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 6936 | } else { |
| 6937 | return frame.left <= 0 && frame.top <= 0 |
| 6938 | && frame.right >= screenWidth |
| 6939 | && frame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6942 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6943 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 6944 | * Return true if the window is opaque and fully drawn. This indicates |
| 6945 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6946 | */ |
| 6947 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 6948 | return (mAttrs.format == PixelFormat.OPAQUE |
| 6949 | || mAttrs.type == TYPE_WALLPAPER) |
| 6950 | && mSurface != null && mAnimation == null |
| 6951 | && (mAppToken == null || mAppToken.animation == null) |
| 6952 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6953 | } |
| 6954 | |
| 6955 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 6956 | return |
| 6957 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6958 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 6959 | // only if it's visible |
| 6960 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6961 | // and only if the application fills the compatible screen |
| 6962 | mFrame.left <= mCompatibleScreenFrame.left && |
| 6963 | mFrame.top <= mCompatibleScreenFrame.top && |
| 6964 | mFrame.right >= mCompatibleScreenFrame.right && |
| 6965 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6966 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6967 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 6971 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6972 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6973 | } |
| 6974 | |
| 6975 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 6976 | disposeInputChannel(); |
| 6977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | if (mAttachedWindow != null) { |
| 6979 | mAttachedWindow.mChildWindows.remove(this); |
| 6980 | } |
| 6981 | destroySurfaceLocked(); |
| 6982 | mSession.windowRemovedLocked(); |
| 6983 | try { |
| 6984 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 6985 | } catch (RuntimeException e) { |
| 6986 | // Ignore if it has already been removed (usually because |
| 6987 | // we are doing this as part of processing a death note.) |
| 6988 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 6989 | } |
| 6990 | |
| 6991 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6992 | if (mInputChannel != null) { |
| 6993 | mInputManager.unregisterInputChannel(mInputChannel); |
| 6994 | |
| 6995 | mInputChannel.dispose(); |
| 6996 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6998 | } |
| 6999 | |
| 7000 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7001 | public void binderDied() { |
| 7002 | try { |
| 7003 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7004 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7005 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7006 | if (win != null) { |
| 7007 | removeWindowLocked(mSession, win); |
| 7008 | } |
| 7009 | } |
| 7010 | } catch (IllegalArgumentException ex) { |
| 7011 | // This will happen if the window has already been |
| 7012 | // removed. |
| 7013 | } |
| 7014 | } |
| 7015 | } |
| 7016 | |
| 7017 | /** Returns true if this window desires key events. */ |
| 7018 | public final boolean canReceiveKeys() { |
| 7019 | return isVisibleOrAdding() |
| 7020 | && (mViewVisibility == View.VISIBLE) |
| 7021 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7022 | } |
| 7023 | |
| 7024 | public boolean hasDrawnLw() { |
| 7025 | return mHasDrawn; |
| 7026 | } |
| 7027 | |
| 7028 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7029 | return showLw(doAnimation, true); |
| 7030 | } |
| 7031 | |
| 7032 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7033 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7034 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7035 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7036 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7037 | if (doAnimation) { |
| 7038 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7039 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7040 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7041 | doAnimation = false; |
| 7042 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7043 | // Check for the case where we are currently visible and |
| 7044 | // not animating; we do not want to do animation at such a |
| 7045 | // point to become visible when we already are. |
| 7046 | doAnimation = false; |
| 7047 | } |
| 7048 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7049 | mPolicyVisibility = true; |
| 7050 | mPolicyVisibilityAfterAnim = true; |
| 7051 | if (doAnimation) { |
| 7052 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7053 | } |
| 7054 | if (requestAnim) { |
| 7055 | requestAnimationLocked(0); |
| 7056 | } |
| 7057 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7061 | return hideLw(doAnimation, true); |
| 7062 | } |
| 7063 | |
| 7064 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7065 | if (doAnimation) { |
| 7066 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7067 | doAnimation = false; |
| 7068 | } |
| 7069 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7071 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7072 | if (!current) { |
| 7073 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7075 | if (doAnimation) { |
| 7076 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7077 | if (mAnimation == null) { |
| 7078 | doAnimation = false; |
| 7079 | } |
| 7080 | } |
| 7081 | if (doAnimation) { |
| 7082 | mPolicyVisibilityAfterAnim = false; |
| 7083 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7084 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7085 | mPolicyVisibilityAfterAnim = false; |
| 7086 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7087 | // Window is no longer visible -- make sure if we were waiting |
| 7088 | // for it to be displayed before enabling the display, that |
| 7089 | // we allow the display to be enabled now. |
| 7090 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7091 | if (mCurrentFocus == this) { |
| 7092 | mFocusMayChange = true; |
| 7093 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7094 | } |
| 7095 | if (requestAnim) { |
| 7096 | requestAnimationLocked(0); |
| 7097 | } |
| 7098 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7099 | } |
| 7100 | |
| 7101 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7102 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7103 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7104 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7105 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7106 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7107 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7108 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7109 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7110 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7111 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7112 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7113 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7114 | } |
| 7115 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7116 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7117 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7118 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7119 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7120 | pw.print("="); pw.print(mAnimLayer); |
| 7121 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7122 | if (mSurface != null) { |
| 7123 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7124 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7125 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7126 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7127 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7128 | pw.print(","); pw.print(mSurfaceY); |
| 7129 | pw.print(") "); pw.print(mSurfaceW); |
| 7130 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7131 | } |
| 7132 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7133 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7134 | if (mAppToken != null) { |
| 7135 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7136 | } |
| 7137 | if (mTargetAppToken != null) { |
| 7138 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7139 | } |
| 7140 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7141 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7142 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7143 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7144 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7145 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7146 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7147 | pw.print(mPolicyVisibility); |
| 7148 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7149 | pw.print(mPolicyVisibilityAfterAnim); |
| 7150 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7151 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7152 | if (!mRelayoutCalled) { |
| 7153 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7154 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7155 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7156 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7157 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7158 | if (mXOffset != 0 || mYOffset != 0) { |
| 7159 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7160 | pw.print(" y="); pw.println(mYOffset); |
| 7161 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7162 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7163 | mGivenContentInsets.printShortString(pw); |
| 7164 | pw.print(" mGivenVisibleInsets="); |
| 7165 | mGivenVisibleInsets.printShortString(pw); |
| 7166 | pw.println(); |
| 7167 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7168 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7169 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7170 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7171 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7172 | pw.print(prefix); pw.print("mShownFrame="); |
| 7173 | mShownFrame.printShortString(pw); |
| 7174 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7175 | pw.println(); |
| 7176 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7177 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7178 | pw.println(); |
| 7179 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7180 | mContainingFrame.printShortString(pw); |
| 7181 | pw.print(" mDisplayFrame="); |
| 7182 | mDisplayFrame.printShortString(pw); |
| 7183 | pw.println(); |
| 7184 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7185 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7186 | pw.println(); |
| 7187 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7188 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7189 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7190 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7191 | pw.println(); |
| 7192 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7193 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7194 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7195 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7196 | } |
| 7197 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7198 | || mAnimation != null) { |
| 7199 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7200 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7201 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7202 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7203 | } |
| 7204 | if (mHasTransformation || mHasLocalTransformation) { |
| 7205 | pw.print(prefix); pw.print("XForm: has="); |
| 7206 | pw.print(mHasTransformation); |
| 7207 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7208 | pw.print(" "); mTransformation.printShortString(pw); |
| 7209 | pw.println(); |
| 7210 | } |
| 7211 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7212 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7213 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7214 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7215 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7216 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7217 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7218 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7219 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7220 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7221 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7222 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7223 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7224 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7225 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7226 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7227 | if (mHScale != 1 || mVScale != 1) { |
| 7228 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7229 | pw.print(" mVScale="); pw.println(mVScale); |
| 7230 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7231 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7232 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7233 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7234 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7235 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7236 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7237 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7240 | |
| 7241 | String makeInputChannelName() { |
| 7242 | return Integer.toHexString(System.identityHashCode(this)) |
| 7243 | + " " + mAttrs.getTitle(); |
| 7244 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | |
| 7246 | @Override |
| 7247 | public String toString() { |
| 7248 | return "Window{" |
| 7249 | + Integer.toHexString(System.identityHashCode(this)) |
| 7250 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7251 | } |
| 7252 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7254 | // ------------------------------------------------------------- |
| 7255 | // Window Token State |
| 7256 | // ------------------------------------------------------------- |
| 7257 | |
| 7258 | class WindowToken { |
| 7259 | // The actual token. |
| 7260 | final IBinder token; |
| 7261 | |
| 7262 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7263 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7265 | // Set if this token was explicitly added by a client, so should |
| 7266 | // not be removed when all windows are removed. |
| 7267 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7268 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7269 | // For printing. |
| 7270 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7272 | // If this is an AppWindowToken, this is non-null. |
| 7273 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7275 | // All of the windows associated with this token. |
| 7276 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7277 | |
| 7278 | // Is key dispatching paused for this token? |
| 7279 | boolean paused = false; |
| 7280 | |
| 7281 | // Should this token's windows be hidden? |
| 7282 | boolean hidden; |
| 7283 | |
| 7284 | // Temporary for finding which tokens no longer have visible windows. |
| 7285 | boolean hasVisible; |
| 7286 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7287 | // Set to true when this token is in a pending transaction where it |
| 7288 | // will be shown. |
| 7289 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7290 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7291 | // Set to true when this token is in a pending transaction where it |
| 7292 | // will be hidden. |
| 7293 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7294 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7295 | // Set to true when this token is in a pending transaction where its |
| 7296 | // windows will be put to the bottom of the list. |
| 7297 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7298 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7299 | // Set to true when this token is in a pending transaction where its |
| 7300 | // windows will be put to the top of the list. |
| 7301 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7303 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7304 | token = _token; |
| 7305 | windowType = type; |
| 7306 | explicit = _explicit; |
| 7307 | } |
| 7308 | |
| 7309 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7310 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7311 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7312 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7313 | pw.print(" hidden="); pw.print(hidden); |
| 7314 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7315 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7316 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7317 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7318 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7319 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7320 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7321 | } |
| 7322 | |
| 7323 | @Override |
| 7324 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7325 | if (stringName == null) { |
| 7326 | StringBuilder sb = new StringBuilder(); |
| 7327 | sb.append("WindowToken{"); |
| 7328 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7329 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7330 | stringName = sb.toString(); |
| 7331 | } |
| 7332 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7333 | } |
| 7334 | }; |
| 7335 | |
| 7336 | class AppWindowToken extends WindowToken { |
| 7337 | // Non-null only for application tokens. |
| 7338 | final IApplicationToken appToken; |
| 7339 | |
| 7340 | // All of the windows and child windows that are included in this |
| 7341 | // application token. Note this list is NOT sorted! |
| 7342 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7343 | |
| 7344 | int groupId = -1; |
| 7345 | boolean appFullscreen; |
| 7346 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7347 | |
| 7348 | // The input dispatching timeout for this application token in nanoseconds. |
| 7349 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7351 | // These are used for determining when all windows associated with |
| 7352 | // an activity have been drawn, so they can be made visible together |
| 7353 | // at the same time. |
| 7354 | int lastTransactionSequence = mTransactionSequence-1; |
| 7355 | int numInterestingWindows; |
| 7356 | int numDrawnWindows; |
| 7357 | boolean inPendingTransaction; |
| 7358 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7360 | // Is this token going to be hidden in a little while? If so, it |
| 7361 | // won't be taken into account for setting the screen orientation. |
| 7362 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7364 | // Is this window's surface needed? This is almost like hidden, except |
| 7365 | // it will sometimes be true a little earlier: when the token has |
| 7366 | // been shown, but is still waiting for its app transition to execute |
| 7367 | // before making its windows shown. |
| 7368 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7370 | // Have we told the window clients to hide themselves? |
| 7371 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7373 | // Last visibility state we reported to the app token. |
| 7374 | boolean reportedVisible; |
| 7375 | |
| 7376 | // Set to true when the token has been removed from the window mgr. |
| 7377 | boolean removed; |
| 7378 | |
| 7379 | // Have we been asked to have this token keep the screen frozen? |
| 7380 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7382 | boolean animating; |
| 7383 | Animation animation; |
| 7384 | boolean hasTransformation; |
| 7385 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | // Offset to the window of all layers in the token, for use by |
| 7388 | // AppWindowToken animations. |
| 7389 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7391 | // Information about an application starting window if displayed. |
| 7392 | StartingData startingData; |
| 7393 | WindowState startingWindow; |
| 7394 | View startingView; |
| 7395 | boolean startingDisplayed; |
| 7396 | boolean startingMoved; |
| 7397 | boolean firstWindowDrawn; |
| 7398 | |
| 7399 | AppWindowToken(IApplicationToken _token) { |
| 7400 | super(_token.asBinder(), |
| 7401 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7402 | appWindowToken = this; |
| 7403 | appToken = _token; |
| 7404 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7406 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7407 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7408 | TAG, "Setting animation in " + this + ": " + anim); |
| 7409 | animation = anim; |
| 7410 | animating = false; |
| 7411 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7412 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7413 | int zorder = anim.getZAdjustment(); |
| 7414 | int adj = 0; |
| 7415 | if (zorder == Animation.ZORDER_TOP) { |
| 7416 | adj = TYPE_LAYER_OFFSET; |
| 7417 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7418 | adj = -TYPE_LAYER_OFFSET; |
| 7419 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7421 | if (animLayerAdjustment != adj) { |
| 7422 | animLayerAdjustment = adj; |
| 7423 | updateLayers(); |
| 7424 | } |
| 7425 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | public void setDummyAnimation() { |
| 7428 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7429 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7430 | TAG, "Setting dummy animation in " + this); |
| 7431 | animation = sDummyAnimation; |
| 7432 | } |
| 7433 | } |
| 7434 | |
| 7435 | public void clearAnimation() { |
| 7436 | if (animation != null) { |
| 7437 | animation = null; |
| 7438 | animating = true; |
| 7439 | } |
| 7440 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7442 | void updateLayers() { |
| 7443 | final int N = allAppWindows.size(); |
| 7444 | final int adj = animLayerAdjustment; |
| 7445 | for (int i=0; i<N; i++) { |
| 7446 | WindowState w = allAppWindows.get(i); |
| 7447 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7448 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7449 | + w.mAnimLayer); |
| 7450 | if (w == mInputMethodTarget) { |
| 7451 | setInputMethodAnimLayerAdjustment(adj); |
| 7452 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7453 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7454 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7455 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7456 | } |
| 7457 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7459 | void sendAppVisibilityToClients() { |
| 7460 | final int N = allAppWindows.size(); |
| 7461 | for (int i=0; i<N; i++) { |
| 7462 | WindowState win = allAppWindows.get(i); |
| 7463 | if (win == startingWindow && clientHidden) { |
| 7464 | // Don't hide the starting window. |
| 7465 | continue; |
| 7466 | } |
| 7467 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7468 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7469 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 7470 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 7471 | } catch (RemoteException e) { |
| 7472 | } |
| 7473 | } |
| 7474 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7476 | void showAllWindowsLocked() { |
| 7477 | final int NW = allAppWindows.size(); |
| 7478 | for (int i=0; i<NW; i++) { |
| 7479 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7480 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7481 | "performing show on: " + w); |
| 7482 | w.performShowLocked(); |
| 7483 | } |
| 7484 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7486 | // This must be called while inside a transaction. |
| 7487 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7488 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7489 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7491 | if (animation == sDummyAnimation) { |
| 7492 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7493 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7494 | // when it is really time to animate, this will be set to |
| 7495 | // a real animation and the next call will execute normally. |
| 7496 | return false; |
| 7497 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7499 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7500 | if (!animating) { |
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, "Starting animation in " + this + |
| 7503 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7504 | + " scale=" + mTransitionAnimationScale |
| 7505 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7506 | animation.initialize(dw, dh, dw, dh); |
| 7507 | animation.setStartTime(currentTime); |
| 7508 | animating = true; |
| 7509 | } |
| 7510 | transformation.clear(); |
| 7511 | final boolean more = animation.getTransformation( |
| 7512 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7513 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7514 | TAG, "Stepped animation in " + this + |
| 7515 | ": more=" + more + ", xform=" + transformation); |
| 7516 | if (more) { |
| 7517 | // we're done! |
| 7518 | hasTransformation = true; |
| 7519 | return true; |
| 7520 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7521 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7522 | TAG, "Finished animation in " + this + |
| 7523 | " @ " + currentTime); |
| 7524 | animation = null; |
| 7525 | } |
| 7526 | } else if (animation != null) { |
| 7527 | // If the display is frozen, and there is a pending animation, |
| 7528 | // clear it and make sure we run the cleanup code. |
| 7529 | animating = true; |
| 7530 | animation = null; |
| 7531 | } |
| 7532 | |
| 7533 | hasTransformation = false; |
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 | if (!animating) { |
| 7536 | return false; |
| 7537 | } |
| 7538 | |
| 7539 | clearAnimation(); |
| 7540 | animating = false; |
| 7541 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7542 | moveInputMethodWindowsIfNeededLocked(true); |
| 7543 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7544 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7545 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7546 | TAG, "Animation done in " + this |
| 7547 | + ": reportedVisible=" + reportedVisible); |
| 7548 | |
| 7549 | transformation.clear(); |
| 7550 | if (animLayerAdjustment != 0) { |
| 7551 | animLayerAdjustment = 0; |
| 7552 | updateLayers(); |
| 7553 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7555 | final int N = windows.size(); |
| 7556 | for (int i=0; i<N; i++) { |
| 7557 | ((WindowState)windows.get(i)).finishExit(); |
| 7558 | } |
| 7559 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7561 | return false; |
| 7562 | } |
| 7563 | |
| 7564 | void updateReportedVisibilityLocked() { |
| 7565 | if (appToken == null) { |
| 7566 | return; |
| 7567 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | int numInteresting = 0; |
| 7570 | int numVisible = 0; |
| 7571 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7572 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7573 | 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] | 7574 | final int N = allAppWindows.size(); |
| 7575 | for (int i=0; i<N; i++) { |
| 7576 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 7577 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 7578 | || win.mViewVisibility != View.VISIBLE |
| 7579 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7580 | continue; |
| 7581 | } |
| 7582 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7583 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7584 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7585 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7586 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7587 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7588 | + " pv=" + win.mPolicyVisibility |
| 7589 | + " dp=" + win.mDrawPending |
| 7590 | + " cdp=" + win.mCommitDrawPending |
| 7591 | + " ah=" + win.mAttachedHidden |
| 7592 | + " th=" |
| 7593 | + (win.mAppToken != null |
| 7594 | ? win.mAppToken.hiddenRequested : false) |
| 7595 | + " a=" + win.mAnimating); |
| 7596 | } |
| 7597 | } |
| 7598 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7599 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7600 | if (!win.isAnimating()) { |
| 7601 | numVisible++; |
| 7602 | } |
| 7603 | nowGone = false; |
| 7604 | } else if (win.isAnimating()) { |
| 7605 | nowGone = false; |
| 7606 | } |
| 7607 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7610 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7611 | + numInteresting + " visible=" + numVisible); |
| 7612 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7613 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7614 | TAG, "Visibility changed in " + this |
| 7615 | + ": vis=" + nowVisible); |
| 7616 | reportedVisible = nowVisible; |
| 7617 | Message m = mH.obtainMessage( |
| 7618 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7619 | nowVisible ? 1 : 0, |
| 7620 | nowGone ? 1 : 0, |
| 7621 | this); |
| 7622 | mH.sendMessage(m); |
| 7623 | } |
| 7624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7625 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7626 | WindowState findMainWindow() { |
| 7627 | int j = windows.size(); |
| 7628 | while (j > 0) { |
| 7629 | j--; |
| 7630 | WindowState win = windows.get(j); |
| 7631 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7632 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7633 | return win; |
| 7634 | } |
| 7635 | } |
| 7636 | return null; |
| 7637 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7639 | void dump(PrintWriter pw, String prefix) { |
| 7640 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7641 | if (appToken != null) { |
| 7642 | pw.print(prefix); pw.println("app=true"); |
| 7643 | } |
| 7644 | if (allAppWindows.size() > 0) { |
| 7645 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7646 | } |
| 7647 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7648 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7649 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7650 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7651 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7652 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7653 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7654 | if (paused || freezingScreen) { |
| 7655 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7656 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7657 | } |
| 7658 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7659 | || inPendingTransaction || allDrawn) { |
| 7660 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7661 | pw.print(numInterestingWindows); |
| 7662 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7663 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7664 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7665 | } |
| 7666 | if (animating || animation != null) { |
| 7667 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7668 | pw.print(" animation="); pw.println(animation); |
| 7669 | } |
| 7670 | if (animLayerAdjustment != 0) { |
| 7671 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7672 | } |
| 7673 | if (hasTransformation) { |
| 7674 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7675 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7676 | pw.println(); |
| 7677 | } |
| 7678 | if (startingData != null || removed || firstWindowDrawn) { |
| 7679 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7680 | pw.print(" removed="); pw.print(removed); |
| 7681 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7682 | } |
| 7683 | if (startingWindow != null || startingView != null |
| 7684 | || startingDisplayed || startingMoved) { |
| 7685 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7686 | pw.print(" startingView="); pw.print(startingView); |
| 7687 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7688 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7689 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | } |
| 7691 | |
| 7692 | @Override |
| 7693 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7694 | if (stringName == null) { |
| 7695 | StringBuilder sb = new StringBuilder(); |
| 7696 | sb.append("AppWindowToken{"); |
| 7697 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7698 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7699 | stringName = sb.toString(); |
| 7700 | } |
| 7701 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7702 | } |
| 7703 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7705 | // ------------------------------------------------------------- |
| 7706 | // DummyAnimation |
| 7707 | // ------------------------------------------------------------- |
| 7708 | |
| 7709 | // This is an animation that does nothing: it just immediately finishes |
| 7710 | // itself every time it is called. It is used as a stub animation in cases |
| 7711 | // where we want to synchronize multiple things that may be animating. |
| 7712 | static final class DummyAnimation extends Animation { |
| 7713 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 7714 | return false; |
| 7715 | } |
| 7716 | } |
| 7717 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | // ------------------------------------------------------------- |
| 7720 | // Async Handler |
| 7721 | // ------------------------------------------------------------- |
| 7722 | |
| 7723 | static final class StartingData { |
| 7724 | final String pkg; |
| 7725 | final int theme; |
| 7726 | final CharSequence nonLocalizedLabel; |
| 7727 | final int labelRes; |
| 7728 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7730 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 7731 | int _labelRes, int _icon) { |
| 7732 | pkg = _pkg; |
| 7733 | theme = _theme; |
| 7734 | nonLocalizedLabel = _nonLocalizedLabel; |
| 7735 | labelRes = _labelRes; |
| 7736 | icon = _icon; |
| 7737 | } |
| 7738 | } |
| 7739 | |
| 7740 | private final class H extends Handler { |
| 7741 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7742 | public static final int REPORT_LOSING_FOCUS = 3; |
| 7743 | public static final int ANIMATE = 4; |
| 7744 | public static final int ADD_STARTING = 5; |
| 7745 | public static final int REMOVE_STARTING = 6; |
| 7746 | public static final int FINISHED_STARTING = 7; |
| 7747 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7748 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 7749 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 7750 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7751 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7752 | public static final int FORCE_GC = 15; |
| 7753 | public static final int ENABLE_SCREEN = 16; |
| 7754 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7755 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7756 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7758 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7759 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7760 | public H() { |
| 7761 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7763 | @Override |
| 7764 | public void handleMessage(Message msg) { |
| 7765 | switch (msg.what) { |
| 7766 | case REPORT_FOCUS_CHANGE: { |
| 7767 | WindowState lastFocus; |
| 7768 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7770 | synchronized(mWindowMap) { |
| 7771 | lastFocus = mLastFocus; |
| 7772 | newFocus = mCurrentFocus; |
| 7773 | if (lastFocus == newFocus) { |
| 7774 | // Focus is not changing, so nothing to do. |
| 7775 | return; |
| 7776 | } |
| 7777 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7778 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7779 | // + " to " + newFocus); |
| 7780 | if (newFocus != null && lastFocus != null |
| 7781 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7782 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | mLosingFocus.add(lastFocus); |
| 7784 | lastFocus = null; |
| 7785 | } |
| 7786 | } |
| 7787 | |
| 7788 | if (lastFocus != newFocus) { |
| 7789 | //System.out.println("Changing focus from " + lastFocus |
| 7790 | // + " to " + newFocus); |
| 7791 | if (newFocus != null) { |
| 7792 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7793 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7794 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7795 | } catch (RemoteException e) { |
| 7796 | // Ignore if process has died. |
| 7797 | } |
| 7798 | } |
| 7799 | |
| 7800 | if (lastFocus != null) { |
| 7801 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7802 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7803 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7804 | } catch (RemoteException e) { |
| 7805 | // Ignore if process has died. |
| 7806 | } |
| 7807 | } |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7808 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7809 | } |
| 7810 | } break; |
| 7811 | |
| 7812 | case REPORT_LOSING_FOCUS: { |
| 7813 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7815 | synchronized(mWindowMap) { |
| 7816 | losers = mLosingFocus; |
| 7817 | mLosingFocus = new ArrayList<WindowState>(); |
| 7818 | } |
| 7819 | |
| 7820 | final int N = losers.size(); |
| 7821 | for (int i=0; i<N; i++) { |
| 7822 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7823 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7825 | } catch (RemoteException e) { |
| 7826 | // Ignore if process has died. |
| 7827 | } |
| 7828 | } |
| 7829 | } break; |
| 7830 | |
| 7831 | case ANIMATE: { |
| 7832 | synchronized(mWindowMap) { |
| 7833 | mAnimationPending = false; |
| 7834 | performLayoutAndPlaceSurfacesLocked(); |
| 7835 | } |
| 7836 | } break; |
| 7837 | |
| 7838 | case ADD_STARTING: { |
| 7839 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7840 | final StartingData sd = wtoken.startingData; |
| 7841 | |
| 7842 | if (sd == null) { |
| 7843 | // Animation has been canceled... do nothing. |
| 7844 | return; |
| 7845 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7846 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7847 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7848 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7850 | View view = null; |
| 7851 | try { |
| 7852 | view = mPolicy.addStartingWindow( |
| 7853 | wtoken.token, sd.pkg, |
| 7854 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 7855 | sd.icon); |
| 7856 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7857 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7858 | } |
| 7859 | |
| 7860 | if (view != null) { |
| 7861 | boolean abort = false; |
| 7862 | |
| 7863 | synchronized(mWindowMap) { |
| 7864 | if (wtoken.removed || wtoken.startingData == null) { |
| 7865 | // If the window was successfully added, then |
| 7866 | // we need to remove it. |
| 7867 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7868 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | "Aborted starting " + wtoken |
| 7870 | + ": removed=" + wtoken.removed |
| 7871 | + " startingData=" + wtoken.startingData); |
| 7872 | wtoken.startingWindow = null; |
| 7873 | wtoken.startingData = null; |
| 7874 | abort = true; |
| 7875 | } |
| 7876 | } else { |
| 7877 | wtoken.startingView = view; |
| 7878 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7879 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7880 | "Added starting " + wtoken |
| 7881 | + ": startingWindow=" |
| 7882 | + wtoken.startingWindow + " startingView=" |
| 7883 | + wtoken.startingView); |
| 7884 | } |
| 7885 | |
| 7886 | if (abort) { |
| 7887 | try { |
| 7888 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7889 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7890 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7891 | } |
| 7892 | } |
| 7893 | } |
| 7894 | } break; |
| 7895 | |
| 7896 | case REMOVE_STARTING: { |
| 7897 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7898 | IBinder token = null; |
| 7899 | View view = null; |
| 7900 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7901 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7902 | + wtoken + ": startingWindow=" |
| 7903 | + wtoken.startingWindow + " startingView=" |
| 7904 | + wtoken.startingView); |
| 7905 | if (wtoken.startingWindow != null) { |
| 7906 | view = wtoken.startingView; |
| 7907 | token = wtoken.token; |
| 7908 | wtoken.startingData = null; |
| 7909 | wtoken.startingView = null; |
| 7910 | wtoken.startingWindow = null; |
| 7911 | } |
| 7912 | } |
| 7913 | if (view != null) { |
| 7914 | try { |
| 7915 | mPolicy.removeStartingWindow(token, view); |
| 7916 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7917 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7918 | } |
| 7919 | } |
| 7920 | } break; |
| 7921 | |
| 7922 | case FINISHED_STARTING: { |
| 7923 | IBinder token = null; |
| 7924 | View view = null; |
| 7925 | while (true) { |
| 7926 | synchronized (mWindowMap) { |
| 7927 | final int N = mFinishedStarting.size(); |
| 7928 | if (N <= 0) { |
| 7929 | break; |
| 7930 | } |
| 7931 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7932 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7933 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7934 | "Finished starting " + wtoken |
| 7935 | + ": startingWindow=" + wtoken.startingWindow |
| 7936 | + " startingView=" + wtoken.startingView); |
| 7937 | |
| 7938 | if (wtoken.startingWindow == null) { |
| 7939 | continue; |
| 7940 | } |
| 7941 | |
| 7942 | view = wtoken.startingView; |
| 7943 | token = wtoken.token; |
| 7944 | wtoken.startingData = null; |
| 7945 | wtoken.startingView = null; |
| 7946 | wtoken.startingWindow = null; |
| 7947 | } |
| 7948 | |
| 7949 | try { |
| 7950 | mPolicy.removeStartingWindow(token, view); |
| 7951 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7952 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7953 | } |
| 7954 | } |
| 7955 | } break; |
| 7956 | |
| 7957 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7958 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7959 | |
| 7960 | boolean nowVisible = msg.arg1 != 0; |
| 7961 | boolean nowGone = msg.arg2 != 0; |
| 7962 | |
| 7963 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7964 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7965 | TAG, "Reporting visible in " + wtoken |
| 7966 | + " visible=" + nowVisible |
| 7967 | + " gone=" + nowGone); |
| 7968 | if (nowVisible) { |
| 7969 | wtoken.appToken.windowsVisible(); |
| 7970 | } else { |
| 7971 | wtoken.appToken.windowsGone(); |
| 7972 | } |
| 7973 | } catch (RemoteException ex) { |
| 7974 | } |
| 7975 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7977 | case WINDOW_FREEZE_TIMEOUT: { |
| 7978 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7979 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7980 | int i = mWindows.size(); |
| 7981 | while (i > 0) { |
| 7982 | i--; |
| 7983 | WindowState w = (WindowState)mWindows.get(i); |
| 7984 | if (w.mOrientationChanging) { |
| 7985 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7986 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7987 | } |
| 7988 | } |
| 7989 | performLayoutAndPlaceSurfacesLocked(); |
| 7990 | } |
| 7991 | break; |
| 7992 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7994 | case HOLD_SCREEN_CHANGED: { |
| 7995 | Session oldHold; |
| 7996 | Session newHold; |
| 7997 | synchronized (mWindowMap) { |
| 7998 | oldHold = mLastReportedHold; |
| 7999 | newHold = (Session)msg.obj; |
| 8000 | mLastReportedHold = newHold; |
| 8001 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8003 | if (oldHold != newHold) { |
| 8004 | try { |
| 8005 | if (oldHold != null) { |
| 8006 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8007 | "window", |
| 8008 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8009 | } |
| 8010 | if (newHold != null) { |
| 8011 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8012 | "window", |
| 8013 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8014 | } |
| 8015 | } catch (RemoteException e) { |
| 8016 | } |
| 8017 | } |
| 8018 | break; |
| 8019 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8021 | case APP_TRANSITION_TIMEOUT: { |
| 8022 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8023 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8024 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8025 | "*** APP TRANSITION TIMEOUT"); |
| 8026 | mAppTransitionReady = true; |
| 8027 | mAppTransitionTimeout = true; |
| 8028 | performLayoutAndPlaceSurfacesLocked(); |
| 8029 | } |
| 8030 | } |
| 8031 | break; |
| 8032 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8034 | case PERSIST_ANIMATION_SCALE: { |
| 8035 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8036 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8037 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8038 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 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 FORCE_GC: { |
| 8043 | synchronized(mWindowMap) { |
| 8044 | if (mAnimationPending) { |
| 8045 | // If we are animating, don't do the gc now but |
| 8046 | // delay a bit so we don't interrupt the animation. |
| 8047 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8048 | 2000); |
| 8049 | return; |
| 8050 | } |
| 8051 | // If we are currently rotating the display, it will |
| 8052 | // schedule a new message when done. |
| 8053 | if (mDisplayFrozen) { |
| 8054 | return; |
| 8055 | } |
| 8056 | mFreezeGcPending = 0; |
| 8057 | } |
| 8058 | Runtime.getRuntime().gc(); |
| 8059 | break; |
| 8060 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8062 | case ENABLE_SCREEN: { |
| 8063 | performEnableScreen(); |
| 8064 | break; |
| 8065 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8067 | case APP_FREEZE_TIMEOUT: { |
| 8068 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8069 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8070 | int i = mAppTokens.size(); |
| 8071 | while (i > 0) { |
| 8072 | i--; |
| 8073 | AppWindowToken tok = mAppTokens.get(i); |
| 8074 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8075 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8076 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8077 | } |
| 8078 | } |
| 8079 | } |
| 8080 | break; |
| 8081 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8082 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8083 | case SEND_NEW_CONFIGURATION: { |
| 8084 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8085 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8086 | break; |
| 8087 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8088 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8089 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8090 | if (mWindowsChanged) { |
| 8091 | synchronized (mWindowMap) { |
| 8092 | mWindowsChanged = false; |
| 8093 | } |
| 8094 | notifyWindowsChanged(); |
| 8095 | } |
| 8096 | break; |
| 8097 | } |
| 8098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8099 | } |
| 8100 | } |
| 8101 | } |
| 8102 | |
| 8103 | // ------------------------------------------------------------- |
| 8104 | // IWindowManager API |
| 8105 | // ------------------------------------------------------------- |
| 8106 | |
| 8107 | public IWindowSession openSession(IInputMethodClient client, |
| 8108 | IInputContext inputContext) { |
| 8109 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8110 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8111 | Session session = new Session(client, inputContext); |
| 8112 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8113 | } |
| 8114 | |
| 8115 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8116 | synchronized (mWindowMap) { |
| 8117 | // The focus for the client is the window immediately below |
| 8118 | // where we would place the input method window. |
| 8119 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8120 | WindowState imFocus; |
| 8121 | if (idx > 0) { |
| 8122 | imFocus = (WindowState)mWindows.get(idx-1); |
| 8123 | if (imFocus != null) { |
| 8124 | if (imFocus.mSession.mClient != null && |
| 8125 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8126 | return true; |
| 8127 | } |
| 8128 | } |
| 8129 | } |
| 8130 | } |
| 8131 | return false; |
| 8132 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | // ------------------------------------------------------------- |
| 8135 | // Internals |
| 8136 | // ------------------------------------------------------------- |
| 8137 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8138 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8139 | boolean throwOnError) { |
| 8140 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8141 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8142 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8143 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8144 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8146 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8147 | TAG, "Looking up client " + client + ": " + win); |
| 8148 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8149 | RuntimeException ex = new IllegalArgumentException( |
| 8150 | "Requested window " + client + " does not exist"); |
| 8151 | if (throwOnError) { |
| 8152 | throw ex; |
| 8153 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8154 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8155 | return null; |
| 8156 | } |
| 8157 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8158 | RuntimeException ex = new IllegalArgumentException( |
| 8159 | "Requested window " + client + " is in session " + |
| 8160 | win.mSession + ", not " + session); |
| 8161 | if (throwOnError) { |
| 8162 | throw ex; |
| 8163 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8164 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8165 | return null; |
| 8166 | } |
| 8167 | |
| 8168 | return win; |
| 8169 | } |
| 8170 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8171 | final void rebuildAppWindowListLocked() { |
| 8172 | int NW = mWindows.size(); |
| 8173 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8174 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8175 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8176 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8177 | // First remove all existing app windows. |
| 8178 | i=0; |
| 8179 | while (i < NW) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8180 | WindowState w = (WindowState)mWindows.get(i); |
| 8181 | if (w.mAppToken != null) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8182 | WindowState win = (WindowState)mWindows.remove(i); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8183 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8184 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8185 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8186 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8187 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8188 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8189 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8190 | && lastWallpaper == i-1) { |
| 8191 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8192 | } |
| 8193 | i++; |
| 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 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8197 | // so skip them before adding app tokens. |
| 8198 | lastWallpaper++; |
| 8199 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8200 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8201 | // First add all of the exiting app tokens... these are no longer |
| 8202 | // in the main app list, but still have windows shown. We put them |
| 8203 | // in the back because now that the animation is over we no longer |
| 8204 | // will care about them. |
| 8205 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8206 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8207 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8208 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8209 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8210 | // And add in the still active app tokens in Z order. |
| 8211 | NT = mAppTokens.size(); |
| 8212 | for (int j=0; j<NT; j++) { |
| 8213 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8214 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8215 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8216 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8217 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8218 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8219 | + " windows but added " + i); |
| 8220 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8221 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8223 | private final void assignLayersLocked() { |
| 8224 | int N = mWindows.size(); |
| 8225 | int curBaseLayer = 0; |
| 8226 | int curLayer = 0; |
| 8227 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8229 | for (i=0; i<N; i++) { |
| 8230 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8231 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8232 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8233 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8234 | w.mLayer = curLayer; |
| 8235 | } else { |
| 8236 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8237 | w.mLayer = curLayer; |
| 8238 | } |
| 8239 | if (w.mTargetAppToken != null) { |
| 8240 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8241 | } else if (w.mAppToken != null) { |
| 8242 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8243 | } else { |
| 8244 | w.mAnimLayer = w.mLayer; |
| 8245 | } |
| 8246 | if (w.mIsImWindow) { |
| 8247 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8248 | } else if (w.mIsWallpaper) { |
| 8249 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8250 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8251 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8252 | + w.mAnimLayer); |
| 8253 | //System.out.println( |
| 8254 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8255 | } |
| 8256 | } |
| 8257 | |
| 8258 | private boolean mInLayout = false; |
| 8259 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8260 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8261 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | throw new RuntimeException("Recursive call!"); |
| 8263 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8264 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8265 | return; |
| 8266 | } |
| 8267 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8268 | if (mWaitingForConfig) { |
| 8269 | // Our configuration has changed (most likely rotation), but we |
| 8270 | // don't yet have the complete configuration to report to |
| 8271 | // applications. Don't do any window layout until we have it. |
| 8272 | return; |
| 8273 | } |
| 8274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8275 | boolean recoveringMemory = false; |
| 8276 | if (mForceRemoves != null) { |
| 8277 | recoveringMemory = true; |
| 8278 | // Wait a little it for things to settle down, and off we go. |
| 8279 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8280 | WindowState ws = mForceRemoves.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8281 | Slog.i(TAG, "Force removing: " + ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8282 | removeWindowInnerLocked(ws.mSession, ws); |
| 8283 | } |
| 8284 | mForceRemoves = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8285 | 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] | 8286 | Object tmp = new Object(); |
| 8287 | synchronized (tmp) { |
| 8288 | try { |
| 8289 | tmp.wait(250); |
| 8290 | } catch (InterruptedException e) { |
| 8291 | } |
| 8292 | } |
| 8293 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8295 | mInLayout = true; |
| 8296 | try { |
| 8297 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8299 | int i = mPendingRemove.size()-1; |
| 8300 | if (i >= 0) { |
| 8301 | while (i >= 0) { |
| 8302 | WindowState w = mPendingRemove.get(i); |
| 8303 | removeWindowInnerLocked(w.mSession, w); |
| 8304 | i--; |
| 8305 | } |
| 8306 | mPendingRemove.clear(); |
| 8307 | |
| 8308 | mInLayout = false; |
| 8309 | assignLayersLocked(); |
| 8310 | mLayoutNeeded = true; |
| 8311 | performLayoutAndPlaceSurfacesLocked(); |
| 8312 | |
| 8313 | } else { |
| 8314 | mInLayout = false; |
| 8315 | if (mLayoutNeeded) { |
| 8316 | requestAnimationLocked(0); |
| 8317 | } |
| 8318 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8319 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8320 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8321 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8322 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8323 | } catch (RuntimeException e) { |
| 8324 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8325 | 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] | 8326 | } |
| 8327 | } |
| 8328 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8329 | private final int performLayoutLockedInner() { |
| 8330 | if (!mLayoutNeeded) { |
| 8331 | return 0; |
| 8332 | } |
| 8333 | |
| 8334 | mLayoutNeeded = false; |
| 8335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8336 | final int dw = mDisplay.getWidth(); |
| 8337 | final int dh = mDisplay.getHeight(); |
| 8338 | |
| 8339 | final int N = mWindows.size(); |
| 8340 | int i; |
| 8341 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8342 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8343 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8344 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8345 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8346 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8347 | int seq = mLayoutSeq+1; |
| 8348 | if (seq < 0) seq = 0; |
| 8349 | mLayoutSeq = seq; |
| 8350 | |
| 8351 | // First perform layout of any root windows (not attached |
| 8352 | // to another window). |
| 8353 | int topAttached = -1; |
| 8354 | for (i = N-1; i >= 0; i--) { |
| 8355 | WindowState win = (WindowState) mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8356 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8357 | // Don't do layout of a window if it is not visible, or |
| 8358 | // soon won't be visible, to avoid wasting time and funky |
| 8359 | // changes while a window is animating away. |
| 8360 | final AppWindowToken atoken = win.mAppToken; |
| 8361 | final boolean gone = win.mViewVisibility == View.GONE |
| 8362 | || !win.mRelayoutCalled |
| 8363 | || win.mRootToken.hidden |
| 8364 | || (atoken != null && atoken.hiddenRequested) |
| 8365 | || win.mAttachedHidden |
| 8366 | || win.mExiting || win.mDestroying; |
| 8367 | |
| 8368 | if (!win.mLayoutAttached) { |
| 8369 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 8370 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8371 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 8372 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 8373 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8374 | + win.mRelayoutCalled + " hidden=" |
| 8375 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8376 | + (atoken != null && atoken.hiddenRequested) |
| 8377 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8378 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8379 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8380 | // If this view is GONE, then skip it -- keep the current |
| 8381 | // frame, and let the caller know so they can ignore it |
| 8382 | // if they want. (We do the normal layout for INVISIBLE |
| 8383 | // windows, since that means "perform layout as normal, |
| 8384 | // just don't display"). |
| 8385 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8386 | if (!win.mLayoutAttached) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8387 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8388 | win.mLayoutSeq = seq; |
| 8389 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8390 | + win.mFrame + " mContainingFrame=" |
| 8391 | + win.mContainingFrame + " mDisplayFrame=" |
| 8392 | + win.mDisplayFrame); |
| 8393 | } else { |
| 8394 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8395 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8396 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8397 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8398 | |
| 8399 | // Now perform layout of attached windows, which usually |
| 8400 | // depend on the position of the window they are attached to. |
| 8401 | // XXX does not deal with windows that are attached to windows |
| 8402 | // that are themselves attached. |
| 8403 | for (i = topAttached; i >= 0; i--) { |
| 8404 | WindowState win = (WindowState) mWindows.get(i); |
| 8405 | |
| 8406 | // If this view is GONE, then skip it -- keep the current |
| 8407 | // frame, and let the caller know so they can ignore it |
| 8408 | // if they want. (We do the normal layout for INVISIBLE |
| 8409 | // windows, since that means "perform layout as normal, |
| 8410 | // just don't display"). |
| 8411 | if (win.mLayoutAttached) { |
| 8412 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 8413 | + " mHaveFrame=" + win.mHaveFrame |
| 8414 | + " mViewVisibility=" + win.mViewVisibility |
| 8415 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 8416 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8417 | || !win.mHaveFrame) { |
| 8418 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8419 | win.mLayoutSeq = seq; |
| 8420 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8421 | + win.mFrame + " mContainingFrame=" |
| 8422 | + win.mContainingFrame + " mDisplayFrame=" |
| 8423 | + win.mDisplayFrame); |
| 8424 | } |
| 8425 | } |
| 8426 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8427 | |
| 8428 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8429 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8430 | |
| 8431 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8434 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 8435 | boolean recoveringMemory) { |
| 8436 | final long currentTime = SystemClock.uptimeMillis(); |
| 8437 | final int dw = mDisplay.getWidth(); |
| 8438 | final int dh = mDisplay.getHeight(); |
| 8439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8440 | int i; |
| 8441 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8442 | if (mFocusMayChange) { |
| 8443 | mFocusMayChange = false; |
| 8444 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 8445 | } |
| 8446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8447 | if (mFxSession == null) { |
| 8448 | mFxSession = new SurfaceSession(); |
| 8449 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8450 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8451 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8452 | |
| 8453 | // Initialize state of exiting tokens. |
| 8454 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8455 | mExitingTokens.get(i).hasVisible = false; |
| 8456 | } |
| 8457 | |
| 8458 | // Initialize state of exiting applications. |
| 8459 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8460 | mExitingAppTokens.get(i).hasVisible = false; |
| 8461 | } |
| 8462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8463 | boolean orientationChangeComplete = true; |
| 8464 | Session holdScreen = null; |
| 8465 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 8466 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8467 | boolean focusDisplayed = false; |
| 8468 | boolean animating = false; |
| 8469 | |
| 8470 | Surface.openTransaction(); |
| 8471 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8472 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8473 | int repeats = 0; |
| 8474 | int changes = 0; |
| 8475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8476 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8477 | repeats++; |
| 8478 | if (repeats > 6) { |
| 8479 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 8480 | mLayoutNeeded = false; |
| 8481 | break; |
| 8482 | } |
| 8483 | |
| 8484 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 8485 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 8486 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 8487 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 8488 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 8489 | assignLayersLocked(); |
| 8490 | mLayoutNeeded = true; |
| 8491 | } |
| 8492 | } |
| 8493 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 8494 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 8495 | if (updateOrientationFromAppTokensLocked()) { |
| 8496 | mLayoutNeeded = true; |
| 8497 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 8498 | } |
| 8499 | } |
| 8500 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 8501 | mLayoutNeeded = true; |
| 8502 | } |
| 8503 | } |
| 8504 | |
| 8505 | // FIRST LOOP: Perform a layout, if needed. |
| 8506 | if (repeats < 4) { |
| 8507 | changes = performLayoutLockedInner(); |
| 8508 | if (changes != 0) { |
| 8509 | continue; |
| 8510 | } |
| 8511 | } else { |
| 8512 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 8513 | changes = 0; |
| 8514 | } |
| 8515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8516 | final int transactionSequence = ++mTransactionSequence; |
| 8517 | |
| 8518 | // Update animations of all applications, including those |
| 8519 | // associated with exiting/removed apps |
| 8520 | boolean tokensAnimating = false; |
| 8521 | final int NAT = mAppTokens.size(); |
| 8522 | for (i=0; i<NAT; i++) { |
| 8523 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8524 | tokensAnimating = true; |
| 8525 | } |
| 8526 | } |
| 8527 | final int NEAT = mExitingAppTokens.size(); |
| 8528 | for (i=0; i<NEAT; i++) { |
| 8529 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8530 | tokensAnimating = true; |
| 8531 | } |
| 8532 | } |
| 8533 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8534 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 8535 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8536 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8537 | + transactionSequence + " tokensAnimating=" |
| 8538 | + tokensAnimating); |
| 8539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8540 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8541 | |
| 8542 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8543 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8544 | boolean forceHiding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8545 | |
| 8546 | mPolicy.beginAnimationLw(dw, dh); |
| 8547 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8548 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8550 | for (i=N-1; i>=0; i--) { |
| 8551 | WindowState w = (WindowState)mWindows.get(i); |
| 8552 | |
| 8553 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8554 | |
| 8555 | if (w.mSurface != null) { |
| 8556 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8557 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 8558 | if ((w.mAttrs.flags |
| 8559 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8560 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8561 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8562 | wallpaperMayChange = true; |
| 8563 | } |
| 8564 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8565 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8566 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8567 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 8568 | animating = true; |
| 8569 | //w.dump(" "); |
| 8570 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8571 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 8572 | wallpaperMayChange = true; |
| 8573 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8574 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8575 | if (mPolicy.doesForceHide(w, attrs)) { |
| 8576 | if (!wasAnimating && animating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8577 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8578 | "Animation done that could impact force hide: " |
| 8579 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8580 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8581 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8582 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 8583 | forceHiding = true; |
| 8584 | } |
| 8585 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 8586 | boolean changed; |
| 8587 | if (forceHiding) { |
| 8588 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8589 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8590 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8591 | } else { |
| 8592 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8593 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8594 | "Now policy shown: " + w); |
| 8595 | if (changed) { |
| 8596 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8597 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8598 | // Assume we will need to animate. If |
| 8599 | // we don't (because the wallpaper will |
| 8600 | // stay with the lock screen), then we will |
| 8601 | // clean up later. |
| 8602 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 8603 | if (a != null) { |
| 8604 | w.setAnimation(a); |
| 8605 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8606 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8607 | if (mCurrentFocus == null || |
| 8608 | mCurrentFocus.mLayer < w.mLayer) { |
| 8609 | // We are showing on to of the current |
| 8610 | // focus, so re-evaluate focus to make |
| 8611 | // sure it is correct. |
| 8612 | mFocusMayChange = true; |
| 8613 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8614 | } |
| 8615 | } |
| 8616 | if (changed && (attrs.flags |
| 8617 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 8618 | wallpaperMayChange = true; |
| 8619 | } |
| 8620 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8622 | mPolicy.animatingWindowLw(w, attrs); |
| 8623 | } |
| 8624 | |
| 8625 | final AppWindowToken atoken = w.mAppToken; |
| 8626 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 8627 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 8628 | atoken.lastTransactionSequence = transactionSequence; |
| 8629 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8630 | atoken.startingDisplayed = false; |
| 8631 | } |
| 8632 | if ((w.isOnScreen() || w.mAttrs.type |
| 8633 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8634 | && !w.mExiting && !w.mDestroying) { |
| 8635 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8636 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8637 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8639 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8640 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8641 | + " pv=" + w.mPolicyVisibility |
| 8642 | + " dp=" + w.mDrawPending |
| 8643 | + " cdp=" + w.mCommitDrawPending |
| 8644 | + " ah=" + w.mAttachedHidden |
| 8645 | + " th=" + atoken.hiddenRequested |
| 8646 | + " a=" + w.mAnimating); |
| 8647 | } |
| 8648 | } |
| 8649 | if (w != atoken.startingWindow) { |
| 8650 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 8651 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8652 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8653 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8654 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8655 | "tokenMayBeDrawn: " + atoken |
| 8656 | + " freezingScreen=" + atoken.freezingScreen |
| 8657 | + " mAppFreezing=" + w.mAppFreezing); |
| 8658 | tokenMayBeDrawn = true; |
| 8659 | } |
| 8660 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8661 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8662 | atoken.startingDisplayed = true; |
| 8663 | } |
| 8664 | } |
| 8665 | } else if (w.mReadyToShow) { |
| 8666 | w.performShowLocked(); |
| 8667 | } |
| 8668 | } |
| 8669 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8670 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8671 | |
| 8672 | if (tokenMayBeDrawn) { |
| 8673 | // See if any windows have been drawn, so they (and others |
| 8674 | // associated with them) can now be shown. |
| 8675 | final int NT = mTokenList.size(); |
| 8676 | for (i=0; i<NT; i++) { |
| 8677 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 8678 | if (wtoken == null) { |
| 8679 | continue; |
| 8680 | } |
| 8681 | if (wtoken.freezingScreen) { |
| 8682 | int numInteresting = wtoken.numInterestingWindows; |
| 8683 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8684 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8685 | "allDrawn: " + wtoken |
| 8686 | + " interesting=" + numInteresting |
| 8687 | + " drawn=" + wtoken.numDrawnWindows); |
| 8688 | wtoken.showAllWindowsLocked(); |
| 8689 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 8690 | orientationChangeComplete = true; |
| 8691 | } |
| 8692 | } else if (!wtoken.allDrawn) { |
| 8693 | int numInteresting = wtoken.numInterestingWindows; |
| 8694 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8695 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8696 | "allDrawn: " + wtoken |
| 8697 | + " interesting=" + numInteresting |
| 8698 | + " drawn=" + wtoken.numDrawnWindows); |
| 8699 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8700 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8701 | |
| 8702 | // We can now show all of the drawn windows! |
| 8703 | if (!mOpeningApps.contains(wtoken)) { |
| 8704 | wtoken.showAllWindowsLocked(); |
| 8705 | } |
| 8706 | } |
| 8707 | } |
| 8708 | } |
| 8709 | } |
| 8710 | |
| 8711 | // If we are ready to perform an app transition, check through |
| 8712 | // all of the app tokens to be shown and see if they are ready |
| 8713 | // to go. |
| 8714 | if (mAppTransitionReady) { |
| 8715 | int NN = mOpeningApps.size(); |
| 8716 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8717 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8718 | "Checking " + NN + " opening apps (frozen=" |
| 8719 | + mDisplayFrozen + " timeout=" |
| 8720 | + mAppTransitionTimeout + ")..."); |
| 8721 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8722 | // If the display isn't frozen, wait to do anything until |
| 8723 | // all of the apps are ready. Otherwise just go because |
| 8724 | // we'll unfreeze the display when everyone is ready. |
| 8725 | for (i=0; i<NN && goodToGo; i++) { |
| 8726 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8727 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8728 | "Check opening app" + wtoken + ": allDrawn=" |
| 8729 | + wtoken.allDrawn + " startingDisplayed=" |
| 8730 | + wtoken.startingDisplayed); |
| 8731 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8732 | && !wtoken.startingMoved) { |
| 8733 | goodToGo = false; |
| 8734 | } |
| 8735 | } |
| 8736 | } |
| 8737 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8738 | 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] | 8739 | int transit = mNextAppTransition; |
| 8740 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8741 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8742 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8743 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8744 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8745 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8746 | mAppTransitionTimeout = false; |
| 8747 | mStartingIconInTransition = false; |
| 8748 | mSkipAppTransitionAnimation = false; |
| 8749 | |
| 8750 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8751 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8752 | // If there are applications waiting to come to the |
| 8753 | // top of the stack, now is the time to move their windows. |
| 8754 | // (Note that we don't do apps going to the bottom |
| 8755 | // here -- we want to keep their windows in the old |
| 8756 | // Z-order until the animation completes.) |
| 8757 | if (mToTopApps.size() > 0) { |
| 8758 | NN = mAppTokens.size(); |
| 8759 | for (i=0; i<NN; i++) { |
| 8760 | AppWindowToken wtoken = mAppTokens.get(i); |
| 8761 | if (wtoken.sendingToTop) { |
| 8762 | wtoken.sendingToTop = false; |
| 8763 | moveAppWindowsLocked(wtoken, NN, false); |
| 8764 | } |
| 8765 | } |
| 8766 | mToTopApps.clear(); |
| 8767 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8768 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8769 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8770 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8771 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8772 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8773 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8774 | // The top-most window will supply the layout params, |
| 8775 | // and we will determine it below. |
| 8776 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8777 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8778 | int bestAnimLayer = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8779 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8780 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8781 | "New wallpaper target=" + mWallpaperTarget |
| 8782 | + ", lower target=" + mLowerWallpaperTarget |
| 8783 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8784 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8785 | // Do a first pass through the tokens for two |
| 8786 | // things: |
| 8787 | // (1) Determine if both the closing and opening |
| 8788 | // app token sets are wallpaper targets, in which |
| 8789 | // case special animations are needed |
| 8790 | // (since the wallpaper needs to stay static |
| 8791 | // behind them). |
| 8792 | // (2) Find the layout params of the top-most |
| 8793 | // application window in the tokens, which is |
| 8794 | // what will control the animation theme. |
| 8795 | final int NC = mClosingApps.size(); |
| 8796 | NN = NC + mOpeningApps.size(); |
| 8797 | for (i=0; i<NN; i++) { |
| 8798 | AppWindowToken wtoken; |
| 8799 | int mode; |
| 8800 | if (i < NC) { |
| 8801 | wtoken = mClosingApps.get(i); |
| 8802 | mode = 1; |
| 8803 | } else { |
| 8804 | wtoken = mOpeningApps.get(i-NC); |
| 8805 | mode = 2; |
| 8806 | } |
| 8807 | if (mLowerWallpaperTarget != null) { |
| 8808 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 8809 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 8810 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8811 | } |
| 8812 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8813 | if (wtoken.appFullscreen) { |
| 8814 | WindowState ws = wtoken.findMainWindow(); |
| 8815 | if (ws != null) { |
| 8816 | // If this is a compatibility mode |
| 8817 | // window, we will always use its anim. |
| 8818 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8819 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8820 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8821 | bestAnimLayer = Integer.MAX_VALUE; |
| 8822 | } else if (ws.mLayer > bestAnimLayer) { |
| 8823 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8824 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8825 | bestAnimLayer = ws.mLayer; |
| 8826 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8827 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8828 | } |
| 8829 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8830 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8831 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8832 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8833 | "Wallpaper animation!"); |
| 8834 | switch (transit) { |
| 8835 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 8836 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 8837 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 8838 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 8839 | break; |
| 8840 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 8841 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 8842 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 8843 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 8844 | break; |
| 8845 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8846 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8847 | "New transit: " + transit); |
| 8848 | } else if (oldWallpaper != null) { |
| 8849 | // We are transitioning from an activity with |
| 8850 | // a wallpaper to one without. |
| 8851 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8852 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8853 | "New transit away from wallpaper: " + transit); |
| 8854 | } else if (mWallpaperTarget != null) { |
| 8855 | // We are transitioning from an activity without |
| 8856 | // a wallpaper to now showing the wallpaper |
| 8857 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8858 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8859 | "New transit into wallpaper: " + transit); |
| 8860 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8861 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8862 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 8863 | mLastEnterAnimToken = animToken; |
| 8864 | mLastEnterAnimParams = animLp; |
| 8865 | } else if (mLastEnterAnimParams != null) { |
| 8866 | animLp = mLastEnterAnimParams; |
| 8867 | mLastEnterAnimToken = null; |
| 8868 | mLastEnterAnimParams = null; |
| 8869 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8870 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8871 | // If all closing windows are obscured, then there is |
| 8872 | // no need to do an animation. This is the case, for |
| 8873 | // example, when this transition is being done behind |
| 8874 | // the lock screen. |
| 8875 | if (!mPolicy.allowAppAnimationsLw()) { |
| 8876 | animLp = null; |
| 8877 | } |
| 8878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8879 | NN = mOpeningApps.size(); |
| 8880 | for (i=0; i<NN; i++) { |
| 8881 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8882 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8883 | "Now opening app" + wtoken); |
| 8884 | wtoken.reportedVisible = false; |
| 8885 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8886 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8887 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8888 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8889 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8890 | wtoken.showAllWindowsLocked(); |
| 8891 | } |
| 8892 | NN = mClosingApps.size(); |
| 8893 | for (i=0; i<NN; i++) { |
| 8894 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8895 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8896 | "Now closing app" + wtoken); |
| 8897 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8898 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8899 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8900 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8901 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8902 | // Force the allDrawn flag, because we want to start |
| 8903 | // this guy's animations regardless of whether it's |
| 8904 | // gotten drawn. |
| 8905 | wtoken.allDrawn = true; |
| 8906 | } |
| 8907 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 8908 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8910 | mOpeningApps.clear(); |
| 8911 | mClosingApps.clear(); |
| 8912 | |
| 8913 | // This has changed the visibility of windows, so perform |
| 8914 | // a new layout to get them all up-to-date. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8915 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8916 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 8917 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 8918 | assignLayersLocked(); |
| 8919 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8920 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8921 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8922 | } |
| 8923 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8924 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8925 | int adjResult = 0; |
| 8926 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8927 | if (!animating && mAppTransitionRunning) { |
| 8928 | // We have finished the animation of an app transition. To do |
| 8929 | // this, we have delayed a lot of operations like showing and |
| 8930 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 8931 | // reflects the correct Z-order, but the window list may now |
| 8932 | // be out of sync with it. So here we will just rebuild the |
| 8933 | // entire app window list. Fun! |
| 8934 | mAppTransitionRunning = false; |
| 8935 | // Clear information about apps that were moving. |
| 8936 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8937 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8938 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8939 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8940 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8941 | moveInputMethodWindowsIfNeededLocked(false); |
| 8942 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 8943 | // Since the window list has been rebuilt, focus might |
| 8944 | // have to be recomputed since the actual order of windows |
| 8945 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8946 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8947 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8948 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8949 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8950 | // At this point, there was a window with a wallpaper that |
| 8951 | // was force hiding other windows behind it, but now it |
| 8952 | // is going away. This may be simple -- just animate |
| 8953 | // away the wallpaper and its window -- or it may be |
| 8954 | // hard -- the wallpaper now needs to be shown behind |
| 8955 | // something that was hidden. |
| 8956 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8957 | if (mLowerWallpaperTarget != null |
| 8958 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8959 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8960 | "wallpaperForceHiding changed with lower=" |
| 8961 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8962 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8963 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 8964 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 8965 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 8966 | // The lower target has become hidden before we |
| 8967 | // actually started the animation... let's completely |
| 8968 | // re-evaluate everything. |
| 8969 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8970 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8971 | } |
| 8972 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8973 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8974 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8975 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8976 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8977 | + " NEW: " + mWallpaperTarget |
| 8978 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8979 | if (mLowerWallpaperTarget == null) { |
| 8980 | // Whoops, we don't need a special wallpaper animation. |
| 8981 | // Clear them out. |
| 8982 | forceHiding = false; |
| 8983 | for (i=N-1; i>=0; i--) { |
| 8984 | WindowState w = (WindowState)mWindows.get(i); |
| 8985 | if (w.mSurface != null) { |
| 8986 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 8987 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8988 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8989 | forceHiding = true; |
| 8990 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 8991 | if (!w.mAnimating) { |
| 8992 | // We set the animation above so it |
| 8993 | // is not yet running. |
| 8994 | w.clearAnimation(); |
| 8995 | } |
| 8996 | } |
| 8997 | } |
| 8998 | } |
| 8999 | } |
| 9000 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9001 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9002 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9003 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9004 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9005 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9006 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9007 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9008 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9009 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9010 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9011 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9012 | assignLayersLocked(); |
| 9013 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9014 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9015 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9016 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9017 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9018 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9019 | if (mFocusMayChange) { |
| 9020 | mFocusMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9021 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9022 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9023 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9024 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9025 | } |
| 9026 | |
| 9027 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9028 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9029 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9030 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9031 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9032 | + Integer.toHexString(changes)); |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9033 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9034 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9035 | |
| 9036 | // THIRD LOOP: Update the surfaces of all windows. |
| 9037 | |
| 9038 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9039 | |
| 9040 | boolean obscured = false; |
| 9041 | boolean blurring = false; |
| 9042 | boolean dimming = false; |
| 9043 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9044 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9045 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9046 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9047 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9049 | for (i=N-1; i>=0; i--) { |
| 9050 | WindowState w = (WindowState)mWindows.get(i); |
| 9051 | |
| 9052 | boolean displayed = false; |
| 9053 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9054 | final int attrFlags = attrs.flags; |
| 9055 | |
| 9056 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9057 | // XXX NOTE: The logic here could be improved. We have |
| 9058 | // the decision about whether to resize a window separated |
| 9059 | // from whether to hide the surface. This can cause us to |
| 9060 | // resize a surface even if we are going to hide it. You |
| 9061 | // can see this by (1) holding device in landscape mode on |
| 9062 | // home screen; (2) tapping browser icon (device will rotate |
| 9063 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9064 | // in step 2 but then immediately hidden, causing us to |
| 9065 | // have to resize and then redraw it again in step 3. It |
| 9066 | // would be nice to figure out how to avoid this, but it is |
| 9067 | // difficult because we do need to resize surfaces in some |
| 9068 | // cases while they are hidden such as when first showing a |
| 9069 | // window. |
| 9070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9071 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9072 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9073 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9074 | + ": new=" + w.mShownFrame + ", old=" |
| 9075 | + w.mLastShownFrame); |
| 9076 | |
| 9077 | boolean resize; |
| 9078 | int width, height; |
| 9079 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9080 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9081 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9082 | // for a scaled surface, we just want to use |
| 9083 | // the requested size. |
| 9084 | width = w.mRequestedWidth; |
| 9085 | height = w.mRequestedHeight; |
| 9086 | w.mLastRequestedWidth = width; |
| 9087 | w.mLastRequestedHeight = height; |
| 9088 | w.mLastShownFrame.set(w.mShownFrame); |
| 9089 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9090 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9091 | "POS " + w.mShownFrame.left |
| 9092 | + ", " + w.mShownFrame.top, null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9093 | w.mSurfaceX = w.mShownFrame.left; |
| 9094 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9095 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9096 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9097 | Slog.w(TAG, "Error positioning surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9098 | if (!recoveringMemory) { |
| 9099 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9100 | } |
| 9101 | } |
| 9102 | } else { |
| 9103 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9104 | width = w.mShownFrame.width(); |
| 9105 | height = w.mShownFrame.height(); |
| 9106 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9107 | } |
| 9108 | |
| 9109 | if (resize) { |
| 9110 | if (width < 1) width = 1; |
| 9111 | if (height < 1) height = 1; |
| 9112 | if (w.mSurface != null) { |
| 9113 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9114 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9115 | "POS " + w.mShownFrame.left + "," |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9116 | + w.mShownFrame.top + " SIZE " |
| 9117 | + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9118 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9119 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9120 | w.mSurfaceW = width; |
| 9121 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9122 | w.mSurface.setSize(width, height); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9123 | w.mSurfaceX = w.mShownFrame.left; |
| 9124 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9125 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9126 | w.mShownFrame.top); |
| 9127 | } catch (RuntimeException e) { |
| 9128 | // If something goes wrong with the surface (such |
| 9129 | // as running out of memory), don't take down the |
| 9130 | // entire system. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9131 | Slog.e(TAG, "Failure updating surface of " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9132 | + "size=(" + width + "x" + height |
| 9133 | + "), pos=(" + w.mShownFrame.left |
| 9134 | + "," + w.mShownFrame.top + ")", e); |
| 9135 | if (!recoveringMemory) { |
| 9136 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9137 | } |
| 9138 | } |
| 9139 | } |
| 9140 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9141 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9142 | w.mContentInsetsChanged = |
| 9143 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9144 | w.mVisibleInsetsChanged = |
| 9145 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9146 | boolean configChanged = |
| 9147 | w.mConfiguration != mCurConfiguration |
| 9148 | && (w.mConfiguration == null |
| 9149 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9150 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9151 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9152 | + mCurConfiguration); |
| 9153 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9154 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9155 | + ": configChanged=" + configChanged |
| 9156 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9157 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9158 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9159 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9160 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9161 | || configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9162 | w.mLastFrame.set(w.mFrame); |
| 9163 | w.mLastContentInsets.set(w.mContentInsets); |
| 9164 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9165 | // If the screen is currently frozen, then keep |
| 9166 | // it frozen until this window draws at its new |
| 9167 | // orientation. |
| 9168 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9169 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9170 | "Resizing while display frozen: " + w); |
| 9171 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9172 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9173 | mWindowsFreezingScreen = true; |
| 9174 | // XXX should probably keep timeout from |
| 9175 | // when we first froze the display. |
| 9176 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9177 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9178 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9179 | } |
| 9180 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9181 | // If the orientation is changing, then we need to |
| 9182 | // hold off on unfreezing the display until this |
| 9183 | // window has been redrawn; to do that, we need |
| 9184 | // to go through the process of getting informed |
| 9185 | // by the application when it has finished drawing. |
| 9186 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9187 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9188 | "Orientation start waiting for draw in " |
| 9189 | + w + ", surface " + w.mSurface); |
| 9190 | w.mDrawPending = true; |
| 9191 | w.mCommitDrawPending = false; |
| 9192 | w.mReadyToShow = false; |
| 9193 | if (w.mAppToken != null) { |
| 9194 | w.mAppToken.allDrawn = false; |
| 9195 | } |
| 9196 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9197 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9198 | "Resizing window " + w + " to " + w.mFrame); |
| 9199 | mResizingWindows.add(w); |
| 9200 | } else if (w.mOrientationChanging) { |
| 9201 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9202 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9203 | "Orientation not waiting for draw in " |
| 9204 | + w + ", surface " + w.mSurface); |
| 9205 | w.mOrientationChanging = false; |
| 9206 | } |
| 9207 | } |
| 9208 | } |
| 9209 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9210 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9211 | if (!w.mLastHidden) { |
| 9212 | //dump(); |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 9213 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow=" |
| 9214 | + w.mRootToken.waitingToShow + " polvis=" |
| 9215 | + w.mPolicyVisibility + " atthid=" |
| 9216 | + w.mAttachedHidden + " tokhid=" |
| 9217 | + w.mRootToken.hidden + " vis=" |
| 9218 | + w.mViewVisibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9219 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9220 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9221 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9223 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9224 | try { |
| 9225 | w.mSurface.hide(); |
| 9226 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9227 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9228 | } |
| 9229 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9230 | mInputMonitor.windowIsBecomingInvisibleLw(w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9231 | } |
| 9232 | // If we are waiting for this window to handle an |
| 9233 | // orientation change, well, it is hidden, so |
| 9234 | // doesn't really matter. Note that this does |
| 9235 | // introduce a potential glitch if the window |
| 9236 | // becomes unhidden before it has drawn for the |
| 9237 | // new orientation. |
| 9238 | if (w.mOrientationChanging) { |
| 9239 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9240 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9241 | "Orientation change skips hidden " + w); |
| 9242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9243 | } else if (w.mLastLayer != w.mAnimLayer |
| 9244 | || w.mLastAlpha != w.mShownAlpha |
| 9245 | || w.mLastDsDx != w.mDsDx |
| 9246 | || w.mLastDtDx != w.mDtDx |
| 9247 | || w.mLastDsDy != w.mDsDy |
| 9248 | || w.mLastDtDy != w.mDtDy |
| 9249 | || w.mLastHScale != w.mHScale |
| 9250 | || w.mLastVScale != w.mVScale |
| 9251 | || w.mLastHidden) { |
| 9252 | displayed = true; |
| 9253 | w.mLastAlpha = w.mShownAlpha; |
| 9254 | w.mLastLayer = w.mAnimLayer; |
| 9255 | w.mLastDsDx = w.mDsDx; |
| 9256 | w.mLastDtDx = w.mDtDx; |
| 9257 | w.mLastDsDy = w.mDsDy; |
| 9258 | w.mLastDtDy = w.mDtDy; |
| 9259 | w.mLastHScale = w.mHScale; |
| 9260 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9261 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9262 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9263 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9264 | + "," + (w.mDtDx*w.mVScale) |
| 9265 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9266 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9267 | if (w.mSurface != null) { |
| 9268 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9269 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9270 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9271 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9272 | w.mSurface.setLayer(w.mAnimLayer); |
| 9273 | w.mSurface.setMatrix( |
| 9274 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9275 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9276 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9277 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9278 | if (!recoveringMemory) { |
| 9279 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9280 | } |
| 9281 | } |
| 9282 | } |
| 9283 | |
| 9284 | if (w.mLastHidden && !w.mDrawPending |
| 9285 | && !w.mCommitDrawPending |
| 9286 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9287 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9288 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9289 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9290 | + " during relayout"); |
| 9291 | if (showSurfaceRobustlyLocked(w)) { |
| 9292 | w.mHasDrawn = true; |
| 9293 | w.mLastHidden = false; |
| 9294 | } else { |
| 9295 | w.mOrientationChanging = false; |
| 9296 | } |
| 9297 | } |
| 9298 | if (w.mSurface != null) { |
| 9299 | w.mToken.hasVisible = true; |
| 9300 | } |
| 9301 | } else { |
| 9302 | displayed = true; |
| 9303 | } |
| 9304 | |
| 9305 | if (displayed) { |
| 9306 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9307 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9308 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9309 | covered = true; |
| 9310 | } |
| 9311 | } |
| 9312 | if (w.mOrientationChanging) { |
| 9313 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9314 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9315 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9316 | "Orientation continue waiting for draw in " + w); |
| 9317 | } else { |
| 9318 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9319 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | "Orientation change complete in " + w); |
| 9321 | } |
| 9322 | } |
| 9323 | w.mToken.hasVisible = true; |
| 9324 | } |
| 9325 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9326 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9327 | "Orientation change skips hidden " + w); |
| 9328 | w.mOrientationChanging = false; |
| 9329 | } |
| 9330 | |
| 9331 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9332 | |
| 9333 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9334 | focusDisplayed = true; |
| 9335 | } |
| 9336 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9337 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9339 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9340 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9341 | if (w.mSurface != null) { |
| 9342 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9343 | holdScreen = w.mSession; |
| 9344 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9345 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9346 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9347 | screenBrightness = w.mAttrs.screenBrightness; |
| 9348 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9349 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 9350 | && buttonBrightness < 0) { |
| 9351 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 9352 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 9353 | if (canBeSeen |
| 9354 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9355 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9356 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9357 | syswin = true; |
| 9358 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9359 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9360 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9361 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9362 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9363 | // This window completely covers everything behind it, |
| 9364 | // so we want to leave all of them as unblurred (for |
| 9365 | // performance reasons). |
| 9366 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9367 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9368 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9369 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9370 | obscured = true; |
| 9371 | if (mBackgroundFillerSurface == null) { |
| 9372 | try { |
| 9373 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9374 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9375 | 0, dw, dh, |
| 9376 | PixelFormat.OPAQUE, |
| 9377 | Surface.FX_SURFACE_NORMAL); |
| 9378 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9379 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9380 | } |
| 9381 | } |
| 9382 | try { |
| 9383 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9384 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9385 | // Using the same layer as Dim because they will never be shown at the |
| 9386 | // same time. |
| 9387 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9388 | mBackgroundFillerSurface.show(); |
| 9389 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9390 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9391 | } |
| 9392 | backgroundFillerShown = true; |
| 9393 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9394 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9395 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9396 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9397 | + ": blurring=" + blurring |
| 9398 | + " obscured=" + obscured |
| 9399 | + " displayed=" + displayed); |
| 9400 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9401 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9402 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9403 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9404 | if (mDimAnimator == null) { |
| 9405 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9406 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9407 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9408 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9409 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9410 | } |
| 9411 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9412 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9413 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9414 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9415 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9416 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9417 | + mBlurSurface + ": CREATE"); |
| 9418 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9419 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9420 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9421 | -1, 16, 16, |
| 9422 | PixelFormat.OPAQUE, |
| 9423 | Surface.FX_SURFACE_BLUR); |
| 9424 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9425 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9426 | } |
| 9427 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9428 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9429 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9430 | + mBlurSurface + ": pos=(0,0) (" + |
| 9431 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9432 | mBlurSurface.setPosition(0, 0); |
| 9433 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9434 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9435 | if (!mBlurShown) { |
| 9436 | try { |
| 9437 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9438 | + mBlurSurface + ": SHOW"); |
| 9439 | mBlurSurface.show(); |
| 9440 | } catch (RuntimeException e) { |
| 9441 | Slog.w(TAG, "Failure showing blur surface", e); |
| 9442 | } |
| 9443 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9444 | } |
| 9445 | } |
| 9446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9447 | } |
| 9448 | } |
| 9449 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9450 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9451 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9452 | // This is the wallpaper target and its obscured state |
| 9453 | // changed... make sure the current wallaper's visibility |
| 9454 | // has been updated accordingly. |
| 9455 | updateWallpaperVisibilityLocked(); |
| 9456 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9457 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9458 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9459 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9460 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9461 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9462 | try { |
| 9463 | mBackgroundFillerSurface.hide(); |
| 9464 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9465 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9466 | } |
| 9467 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9468 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9469 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9470 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 9471 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9472 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9474 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9475 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9476 | + ": HIDE"); |
| 9477 | try { |
| 9478 | mBlurSurface.hide(); |
| 9479 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9480 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9481 | } |
| 9482 | mBlurShown = false; |
| 9483 | } |
| 9484 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9485 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9486 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9487 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9488 | } |
| 9489 | |
| 9490 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9491 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9492 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9493 | "With display frozen, orientationChangeComplete=" |
| 9494 | + orientationChangeComplete); |
| 9495 | if (orientationChangeComplete) { |
| 9496 | if (mWindowsFreezingScreen) { |
| 9497 | mWindowsFreezingScreen = false; |
| 9498 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9499 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9500 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | i = mResizingWindows.size(); |
| 9504 | if (i > 0) { |
| 9505 | do { |
| 9506 | i--; |
| 9507 | WindowState win = mResizingWindows.get(i); |
| 9508 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9509 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 9510 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9511 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9512 | boolean configChanged = |
| 9513 | win.mConfiguration != mCurConfiguration |
| 9514 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9515 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 9516 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 9517 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9518 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9519 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9520 | + " / " + mCurConfiguration + " / 0x" |
| 9521 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9522 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9523 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9524 | win.mClient.resized(win.mFrame.width(), |
| 9525 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9526 | win.mLastVisibleInsets, win.mDrawPending, |
| 9527 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9528 | win.mContentInsetsChanged = false; |
| 9529 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9530 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9531 | } catch (RemoteException e) { |
| 9532 | win.mOrientationChanging = false; |
| 9533 | } |
| 9534 | } while (i > 0); |
| 9535 | mResizingWindows.clear(); |
| 9536 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9538 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9539 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9540 | i = mDestroySurface.size(); |
| 9541 | if (i > 0) { |
| 9542 | do { |
| 9543 | i--; |
| 9544 | WindowState win = mDestroySurface.get(i); |
| 9545 | win.mDestroying = false; |
| 9546 | if (mInputMethodWindow == win) { |
| 9547 | mInputMethodWindow = null; |
| 9548 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9549 | if (win == mWallpaperTarget) { |
| 9550 | wallpaperDestroyed = true; |
| 9551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9552 | win.destroySurfaceLocked(); |
| 9553 | } while (i > 0); |
| 9554 | mDestroySurface.clear(); |
| 9555 | } |
| 9556 | |
| 9557 | // Time to remove any exiting tokens? |
| 9558 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9559 | WindowToken token = mExitingTokens.get(i); |
| 9560 | if (!token.hasVisible) { |
| 9561 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9562 | if (token.windowType == TYPE_WALLPAPER) { |
| 9563 | mWallpaperTokens.remove(token); |
| 9564 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9565 | } |
| 9566 | } |
| 9567 | |
| 9568 | // Time to remove any exiting applications? |
| 9569 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9570 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9571 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9572 | // Make sure there is no animation running on this token, |
| 9573 | // so any windows associated with it will be removed as |
| 9574 | // soon as their animations are complete |
| 9575 | token.animation = null; |
| 9576 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9577 | mAppTokens.remove(token); |
| 9578 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9579 | if (mLastEnterAnimToken == token) { |
| 9580 | mLastEnterAnimToken = null; |
| 9581 | mLastEnterAnimParams = null; |
| 9582 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9583 | } |
| 9584 | } |
| 9585 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9586 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9587 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9588 | if (!animating && mAppTransitionRunning) { |
| 9589 | // We have finished the animation of an app transition. To do |
| 9590 | // this, we have delayed a lot of operations like showing and |
| 9591 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9592 | // reflects the correct Z-order, but the window list may now |
| 9593 | // be out of sync with it. So here we will just rebuild the |
| 9594 | // entire app window list. Fun! |
| 9595 | mAppTransitionRunning = false; |
| 9596 | needRelayout = true; |
| 9597 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9598 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9599 | // Clear information about apps that were moving. |
| 9600 | mToBottomApps.clear(); |
| 9601 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9603 | if (focusDisplayed) { |
| 9604 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9605 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9606 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9607 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9608 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9609 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9610 | requestAnimationLocked(0); |
| 9611 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9612 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 9613 | } |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9614 | |
| 9615 | if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen |
| 9616 | + " holdScreen=" + holdScreen); |
| 9617 | if (!mDisplayFrozen) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9618 | setHoldScreenLocked(holdScreen != null); |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9619 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 9620 | mPowerManager.setScreenBrightnessOverride(-1); |
| 9621 | } else { |
| 9622 | mPowerManager.setScreenBrightnessOverride((int) |
| 9623 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 9624 | } |
| 9625 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 9626 | mPowerManager.setButtonBrightnessOverride(-1); |
| 9627 | } else { |
| 9628 | mPowerManager.setButtonBrightnessOverride((int) |
| 9629 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 9630 | } |
| 9631 | if (holdScreen != mHoldingScreenOn) { |
| 9632 | mHoldingScreenOn = holdScreen; |
| 9633 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 9634 | mH.sendMessage(m); |
| 9635 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9636 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9637 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9638 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9639 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9640 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 9641 | LocalPowerManager.BUTTON_EVENT, true); |
| 9642 | mTurnOnScreen = false; |
| 9643 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 9644 | |
| 9645 | // Check to see if we are now in a state where the screen should |
| 9646 | // be enabled, because the window obscured flags have changed. |
| 9647 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9648 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9649 | |
| 9650 | /** |
| 9651 | * Must be called with the main window manager lock held. |
| 9652 | */ |
| 9653 | void setHoldScreenLocked(boolean holding) { |
| 9654 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 9655 | if (holding != state) { |
| 9656 | if (holding) { |
| 9657 | mHoldingScreenWakeLock.acquire(); |
| 9658 | } else { |
| 9659 | mPolicy.screenOnStoppedLw(); |
| 9660 | mHoldingScreenWakeLock.release(); |
| 9661 | } |
| 9662 | } |
| 9663 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9664 | |
| 9665 | void requestAnimationLocked(long delay) { |
| 9666 | if (!mAnimationPending) { |
| 9667 | mAnimationPending = true; |
| 9668 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 9669 | } |
| 9670 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9672 | /** |
| 9673 | * Have the surface flinger show a surface, robustly dealing with |
| 9674 | * error conditions. In particular, if there is not enough memory |
| 9675 | * to show the surface, then we will try to get rid of other surfaces |
| 9676 | * in order to succeed. |
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 Returns true if the surface was successfully shown. |
| 9679 | */ |
| 9680 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 9681 | try { |
| 9682 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9683 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9684 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9685 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9686 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9687 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9688 | win.mTurnOnScreen = false; |
| 9689 | mTurnOnScreen = true; |
| 9690 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9691 | } |
| 9692 | return true; |
| 9693 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9694 | 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] | 9695 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9697 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9699 | return false; |
| 9700 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9702 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 9703 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9704 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9705 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9706 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9708 | if (mForceRemoves == null) { |
| 9709 | mForceRemoves = new ArrayList<WindowState>(); |
| 9710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9712 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9713 | try { |
| 9714 | // There was some problem... first, do a sanity check of the |
| 9715 | // window list to make sure we haven't left any dangling surfaces |
| 9716 | // around. |
| 9717 | int N = mWindows.size(); |
| 9718 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9719 | 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] | 9720 | for (int i=0; i<N; i++) { |
| 9721 | WindowState ws = (WindowState)mWindows.get(i); |
| 9722 | if (ws.mSurface != null) { |
| 9723 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9724 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9725 | + ws + " surface=" + ws.mSurface |
| 9726 | + " token=" + win.mToken |
| 9727 | + " pid=" + ws.mSession.mPid |
| 9728 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9729 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9730 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9731 | ws.mSurface = null; |
| 9732 | mForceRemoves.add(ws); |
| 9733 | i--; |
| 9734 | N--; |
| 9735 | leakedSurface = true; |
| 9736 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9737 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9738 | + ws + " surface=" + ws.mSurface |
| 9739 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9740 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9741 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9742 | ws.mSurface = null; |
| 9743 | leakedSurface = true; |
| 9744 | } |
| 9745 | } |
| 9746 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9748 | boolean killedApps = false; |
| 9749 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9750 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9751 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 9752 | for (int i=0; i<N; i++) { |
| 9753 | WindowState ws = (WindowState)mWindows.get(i); |
| 9754 | if (ws.mSurface != null) { |
| 9755 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 9756 | } |
| 9757 | } |
| 9758 | if (pidCandidates.size() > 0) { |
| 9759 | int[] pids = new int[pidCandidates.size()]; |
| 9760 | for (int i=0; i<pids.length; i++) { |
| 9761 | pids[i] = pidCandidates.keyAt(i); |
| 9762 | } |
| 9763 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9764 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9765 | killedApps = true; |
| 9766 | } |
| 9767 | } catch (RemoteException e) { |
| 9768 | } |
| 9769 | } |
| 9770 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9772 | if (leakedSurface || killedApps) { |
| 9773 | // We managed to reclaim some memory, so get rid of the trouble |
| 9774 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9775 | 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] | 9776 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9777 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9778 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9779 | win.mSurface = null; |
| 9780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9782 | try { |
| 9783 | win.mClient.dispatchGetNewSurface(); |
| 9784 | } catch (RemoteException e) { |
| 9785 | } |
| 9786 | } |
| 9787 | } finally { |
| 9788 | Binder.restoreCallingIdentity(callingIdentity); |
| 9789 | } |
| 9790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9792 | private boolean updateFocusedWindowLocked(int mode) { |
| 9793 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9794 | if (mCurrentFocus != newFocus) { |
| 9795 | // This check makes sure that we don't already have the focus |
| 9796 | // change message pending. |
| 9797 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9798 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9799 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9800 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9801 | final WindowState oldFocus = mCurrentFocus; |
| 9802 | mCurrentFocus = newFocus; |
| 9803 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9805 | final WindowState imWindow = mInputMethodWindow; |
| 9806 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9807 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9808 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9809 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 9810 | mLayoutNeeded = true; |
| 9811 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9812 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 9813 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9814 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9815 | // Client will do the layout, but we need to assign layers |
| 9816 | // for handleNewWindowLocked() below. |
| 9817 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9818 | } |
| 9819 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9820 | |
| 9821 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9822 | // If we defer assigning layers, then the caller is responsible for |
| 9823 | // doing this part. |
| 9824 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9825 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9826 | return true; |
| 9827 | } |
| 9828 | return false; |
| 9829 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9830 | |
| 9831 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9832 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9833 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9834 | |
| 9835 | private WindowState computeFocusedWindowLocked() { |
| 9836 | WindowState result = null; |
| 9837 | WindowState win; |
| 9838 | |
| 9839 | int i = mWindows.size() - 1; |
| 9840 | int nextAppIndex = mAppTokens.size()-1; |
| 9841 | WindowToken nextApp = nextAppIndex >= 0 |
| 9842 | ? mAppTokens.get(nextAppIndex) : null; |
| 9843 | |
| 9844 | while (i >= 0) { |
| 9845 | win = (WindowState)mWindows.get(i); |
| 9846 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9847 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9848 | TAG, "Looking for focus: " + i |
| 9849 | + " = " + win |
| 9850 | + ", flags=" + win.mAttrs.flags |
| 9851 | + ", canReceive=" + win.canReceiveKeys()); |
| 9852 | |
| 9853 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9855 | // If this window's application has been removed, just skip it. |
| 9856 | if (thisApp != null && thisApp.removed) { |
| 9857 | i--; |
| 9858 | continue; |
| 9859 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9860 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9861 | // If there is a focused app, don't allow focus to go to any |
| 9862 | // windows below it. If this is an application window, step |
| 9863 | // through the app tokens until we find its app. |
| 9864 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9865 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9866 | int origAppIndex = nextAppIndex; |
| 9867 | while (nextAppIndex > 0) { |
| 9868 | if (nextApp == mFocusedApp) { |
| 9869 | // Whoops, we are below the focused app... no focus |
| 9870 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9871 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9872 | TAG, "Reached focused app: " + mFocusedApp); |
| 9873 | return null; |
| 9874 | } |
| 9875 | nextAppIndex--; |
| 9876 | nextApp = mAppTokens.get(nextAppIndex); |
| 9877 | if (nextApp == thisApp) { |
| 9878 | break; |
| 9879 | } |
| 9880 | } |
| 9881 | if (thisApp != nextApp) { |
| 9882 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9883 | // happen, but if it does we can get totally hosed... |
| 9884 | // so restart at the original app. |
| 9885 | nextAppIndex = origAppIndex; |
| 9886 | nextApp = mAppTokens.get(nextAppIndex); |
| 9887 | } |
| 9888 | } |
| 9889 | |
| 9890 | // Dispatch to this window if it is wants key events. |
| 9891 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9892 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9893 | TAG, "Found focus @ " + i + " = " + win); |
| 9894 | result = win; |
| 9895 | break; |
| 9896 | } |
| 9897 | |
| 9898 | i--; |
| 9899 | } |
| 9900 | |
| 9901 | return result; |
| 9902 | } |
| 9903 | |
| 9904 | private void startFreezingDisplayLocked() { |
| 9905 | if (mDisplayFrozen) { |
| 9906 | return; |
| 9907 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9909 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9911 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9912 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9913 | if (mFreezeGcPending != 0) { |
| 9914 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9915 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9916 | mH.removeMessages(H.FORCE_GC); |
| 9917 | Runtime.getRuntime().gc(); |
| 9918 | mFreezeGcPending = now; |
| 9919 | } |
| 9920 | } else { |
| 9921 | mFreezeGcPending = now; |
| 9922 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9923 | |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9924 | if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException()); |
| 9925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9926 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9927 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9928 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9929 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9930 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 9931 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9932 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9933 | mAppTransitionReady = true; |
| 9934 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9936 | if (PROFILE_ORIENTATION) { |
| 9937 | File file = new File("/data/system/frozen"); |
| 9938 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9939 | } |
| 9940 | Surface.freezeDisplay(0); |
| 9941 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9943 | private void stopFreezingDisplayLocked() { |
| 9944 | if (!mDisplayFrozen) { |
| 9945 | return; |
| 9946 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9947 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9948 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 9949 | return; |
| 9950 | } |
| 9951 | |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9952 | if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException()); |
| 9953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9954 | mDisplayFrozen = false; |
| 9955 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 9956 | if (PROFILE_ORIENTATION) { |
| 9957 | Debug.stopMethodTracing(); |
| 9958 | } |
| 9959 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9960 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9961 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9962 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 9963 | // While the display is frozen we don't re-compute the orientation |
| 9964 | // to avoid inconsistent states. However, something interesting |
| 9965 | // could have actually changed during that time so re-evaluate it |
| 9966 | // now to catch that. |
| 9967 | if (updateOrientationFromAppTokensLocked()) { |
| 9968 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9969 | } |
| 9970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9971 | // A little kludge: a lot could have happened while the |
| 9972 | // display was frozen, so now that we are coming back we |
| 9973 | // do a gc so that any remote references the system |
| 9974 | // processes holds on others can be released if they are |
| 9975 | // no longer needed. |
| 9976 | mH.removeMessages(H.FORCE_GC); |
| 9977 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9978 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9980 | mScreenFrozenLock.release(); |
| 9981 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9983 | @Override |
| 9984 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 9985 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 9986 | != PackageManager.PERMISSION_GRANTED) { |
| 9987 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 9988 | + Binder.getCallingPid() |
| 9989 | + ", uid=" + Binder.getCallingUid()); |
| 9990 | return; |
| 9991 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9992 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9993 | pw.println("Input Dispatcher State:"); |
| 9994 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 9995 | pw.println(" "); |
| 9996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9997 | synchronized(mWindowMap) { |
| 9998 | pw.println("Current Window Manager state:"); |
| 9999 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 10000 | WindowState w = (WindowState)mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10001 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10002 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10003 | w.dump(pw, " "); |
| 10004 | } |
| 10005 | if (mInputMethodDialogs.size() > 0) { |
| 10006 | pw.println(" "); |
| 10007 | pw.println(" Input method dialogs:"); |
| 10008 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10009 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10010 | 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] | 10011 | } |
| 10012 | } |
| 10013 | if (mPendingRemove.size() > 0) { |
| 10014 | pw.println(" "); |
| 10015 | pw.println(" Remove pending for:"); |
| 10016 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10017 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10018 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10019 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10020 | w.dump(pw, " "); |
| 10021 | } |
| 10022 | } |
| 10023 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10024 | pw.println(" "); |
| 10025 | pw.println(" Windows force removing:"); |
| 10026 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10027 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10028 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10029 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10030 | w.dump(pw, " "); |
| 10031 | } |
| 10032 | } |
| 10033 | if (mDestroySurface.size() > 0) { |
| 10034 | pw.println(" "); |
| 10035 | pw.println(" Windows waiting to destroy their surface:"); |
| 10036 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10037 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10038 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10039 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10040 | w.dump(pw, " "); |
| 10041 | } |
| 10042 | } |
| 10043 | if (mLosingFocus.size() > 0) { |
| 10044 | pw.println(" "); |
| 10045 | pw.println(" Windows losing focus:"); |
| 10046 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10047 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10048 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10049 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10050 | w.dump(pw, " "); |
| 10051 | } |
| 10052 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10053 | if (mResizingWindows.size() > 0) { |
| 10054 | pw.println(" "); |
| 10055 | pw.println(" Windows waiting to resize:"); |
| 10056 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10057 | WindowState w = mResizingWindows.get(i); |
| 10058 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10059 | pw.print(w); pw.println(":"); |
| 10060 | w.dump(pw, " "); |
| 10061 | } |
| 10062 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10063 | if (mSessions.size() > 0) { |
| 10064 | pw.println(" "); |
| 10065 | pw.println(" All active sessions:"); |
| 10066 | Iterator<Session> it = mSessions.iterator(); |
| 10067 | while (it.hasNext()) { |
| 10068 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10069 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10070 | s.dump(pw, " "); |
| 10071 | } |
| 10072 | } |
| 10073 | if (mTokenMap.size() > 0) { |
| 10074 | pw.println(" "); |
| 10075 | pw.println(" All tokens:"); |
| 10076 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10077 | while (it.hasNext()) { |
| 10078 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10079 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10080 | token.dump(pw, " "); |
| 10081 | } |
| 10082 | } |
| 10083 | if (mTokenList.size() > 0) { |
| 10084 | pw.println(" "); |
| 10085 | pw.println(" Window token list:"); |
| 10086 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10087 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10088 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10089 | } |
| 10090 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10091 | if (mWallpaperTokens.size() > 0) { |
| 10092 | pw.println(" "); |
| 10093 | pw.println(" Wallpaper tokens:"); |
| 10094 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10095 | WindowToken token = mWallpaperTokens.get(i); |
| 10096 | pw.print(" Wallpaper #"); pw.print(i); |
| 10097 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10098 | token.dump(pw, " "); |
| 10099 | } |
| 10100 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10101 | if (mAppTokens.size() > 0) { |
| 10102 | pw.println(" "); |
| 10103 | pw.println(" Application tokens in Z order:"); |
| 10104 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10105 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10106 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10107 | } |
| 10108 | } |
| 10109 | if (mFinishedStarting.size() > 0) { |
| 10110 | pw.println(" "); |
| 10111 | pw.println(" Finishing start of application tokens:"); |
| 10112 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10113 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10114 | pw.print(" Finished Starting #"); pw.print(i); |
| 10115 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10116 | token.dump(pw, " "); |
| 10117 | } |
| 10118 | } |
| 10119 | if (mExitingTokens.size() > 0) { |
| 10120 | pw.println(" "); |
| 10121 | pw.println(" Exiting tokens:"); |
| 10122 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10123 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10124 | pw.print(" Exiting #"); pw.print(i); |
| 10125 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10126 | token.dump(pw, " "); |
| 10127 | } |
| 10128 | } |
| 10129 | if (mExitingAppTokens.size() > 0) { |
| 10130 | pw.println(" "); |
| 10131 | pw.println(" Exiting application tokens:"); |
| 10132 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10133 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10134 | pw.print(" Exiting App #"); pw.print(i); |
| 10135 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10136 | token.dump(pw, " "); |
| 10137 | } |
| 10138 | } |
| 10139 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10140 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10141 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10142 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10143 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10144 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10145 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10146 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10147 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10148 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10149 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10150 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10151 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10152 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10153 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10154 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10155 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10156 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10157 | if (mDimAnimator != null) { |
| 10158 | mDimAnimator.printTo(pw); |
| 10159 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10160 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10161 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10162 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10163 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10164 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10165 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10166 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10167 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10168 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10169 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10170 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10171 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10172 | pw.print(" mRotation="); pw.print(mRotation); |
| 10173 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10174 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10175 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10176 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10177 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10178 | pw.print(" mNextAppTransition=0x"); |
| 10179 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10180 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10181 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10182 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10183 | if (mNextAppTransitionPackage != null) { |
| 10184 | pw.print(" mNextAppTransitionPackage="); |
| 10185 | pw.print(mNextAppTransitionPackage); |
| 10186 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10187 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10188 | pw.print(", mNextAppTransitionExit=0x"); |
| 10189 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10190 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10191 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10192 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10193 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10194 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10195 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10196 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10197 | if (mOpeningApps.size() > 0) { |
| 10198 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10199 | } |
| 10200 | if (mClosingApps.size() > 0) { |
| 10201 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10202 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10203 | if (mToTopApps.size() > 0) { |
| 10204 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10205 | } |
| 10206 | if (mToBottomApps.size() > 0) { |
| 10207 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10208 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10209 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10210 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10211 | } |
| 10212 | } |
| 10213 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10214 | // 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] | 10215 | public void monitor() { |
| 10216 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10217 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10218 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10219 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10220 | /** |
| 10221 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10222 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10223 | */ |
| 10224 | private static class DimAnimator { |
| 10225 | Surface mDimSurface; |
| 10226 | boolean mDimShown = false; |
| 10227 | float mDimCurrentAlpha; |
| 10228 | float mDimTargetAlpha; |
| 10229 | float mDimDeltaPerMs; |
| 10230 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10231 | |
| 10232 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10233 | |
| 10234 | DimAnimator (SurfaceSession session) { |
| 10235 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10236 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10237 | + mDimSurface + ": CREATE"); |
| 10238 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10239 | mDimSurface = new Surface(session, 0, |
| 10240 | "DimSurface", |
| 10241 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10242 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 10243 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10244 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10245 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10246 | } |
| 10247 | } |
| 10248 | } |
| 10249 | |
| 10250 | /** |
| 10251 | * Show the dim surface. |
| 10252 | */ |
| 10253 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10254 | if (!mDimShown) { |
| 10255 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 10256 | dw + "x" + dh + ")"); |
| 10257 | mDimShown = true; |
| 10258 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10259 | mLastDimWidth = dw; |
| 10260 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10261 | mDimSurface.setPosition(0, 0); |
| 10262 | mDimSurface.setSize(dw, dh); |
| 10263 | mDimSurface.show(); |
| 10264 | } catch (RuntimeException e) { |
| 10265 | Slog.w(TAG, "Failure showing dim surface", e); |
| 10266 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10267 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 10268 | mLastDimWidth = dw; |
| 10269 | mLastDimHeight = dh; |
| 10270 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10271 | } |
| 10272 | } |
| 10273 | |
| 10274 | /** |
| 10275 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 10276 | * {@link updateSurface} after all windows are examined. |
| 10277 | */ |
| 10278 | void updateParameters(WindowState w, long currentTime) { |
| 10279 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 10280 | |
| 10281 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10282 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10283 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10284 | if (mDimTargetAlpha != target) { |
| 10285 | // If the desired dim level has changed, then |
| 10286 | // start an animation to it. |
| 10287 | mLastDimAnimTime = currentTime; |
| 10288 | long duration = (w.mAnimating && w.mAnimation != null) |
| 10289 | ? w.mAnimation.computeDurationHint() |
| 10290 | : DEFAULT_DIM_DURATION; |
| 10291 | if (target > mDimTargetAlpha) { |
| 10292 | // This is happening behind the activity UI, |
| 10293 | // so we can make it run a little longer to |
| 10294 | // give a stronger impression without disrupting |
| 10295 | // the user. |
| 10296 | duration *= DIM_DURATION_MULTIPLIER; |
| 10297 | } |
| 10298 | if (duration < 1) { |
| 10299 | // Don't divide by zero |
| 10300 | duration = 1; |
| 10301 | } |
| 10302 | mDimTargetAlpha = target; |
| 10303 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10304 | } |
| 10305 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10306 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10307 | /** |
| 10308 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10309 | * false when the animation is finished and the dim surface is hidden. |
| 10310 | */ |
| 10311 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10312 | if (!dimming) { |
| 10313 | if (mDimTargetAlpha != 0) { |
| 10314 | mLastDimAnimTime = currentTime; |
| 10315 | mDimTargetAlpha = 0; |
| 10316 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10317 | } |
| 10318 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10319 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10320 | boolean animating = false; |
| 10321 | if (mLastDimAnimTime != 0) { |
| 10322 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10323 | * (currentTime-mLastDimAnimTime); |
| 10324 | boolean more = true; |
| 10325 | if (displayFrozen) { |
| 10326 | // If the display is frozen, there is no reason to animate. |
| 10327 | more = false; |
| 10328 | } else if (mDimDeltaPerMs > 0) { |
| 10329 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10330 | more = false; |
| 10331 | } |
| 10332 | } else if (mDimDeltaPerMs < 0) { |
| 10333 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10334 | more = false; |
| 10335 | } |
| 10336 | } else { |
| 10337 | more = false; |
| 10338 | } |
| 10339 | |
| 10340 | // Do we need to continue animating? |
| 10341 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10342 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10343 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10344 | mLastDimAnimTime = currentTime; |
| 10345 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10346 | animating = true; |
| 10347 | } else { |
| 10348 | mDimCurrentAlpha = mDimTargetAlpha; |
| 10349 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10350 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10351 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 10352 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10353 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10354 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10355 | + ": HIDE"); |
| 10356 | try { |
| 10357 | mDimSurface.hide(); |
| 10358 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10359 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10360 | } |
| 10361 | mDimShown = false; |
| 10362 | } |
| 10363 | } |
| 10364 | } |
| 10365 | return animating; |
| 10366 | } |
| 10367 | |
| 10368 | public void printTo(PrintWriter pw) { |
| 10369 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 10370 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 10371 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 10372 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 10373 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 10374 | } |
| 10375 | } |
| 10376 | |
| 10377 | /** |
| 10378 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 10379 | * This is used for opening/closing transition for apps in compatible mode. |
| 10380 | */ |
| 10381 | private static class FadeInOutAnimation extends Animation { |
| 10382 | int mWidth; |
| 10383 | boolean mFadeIn; |
| 10384 | |
| 10385 | public FadeInOutAnimation(boolean fadeIn) { |
| 10386 | setInterpolator(new AccelerateInterpolator()); |
| 10387 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 10388 | mFadeIn = fadeIn; |
| 10389 | } |
| 10390 | |
| 10391 | @Override |
| 10392 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 10393 | float x = interpolatedTime; |
| 10394 | if (!mFadeIn) { |
| 10395 | x = 1.0f - x; // reverse the interpolation for fade out |
| 10396 | } |
| 10397 | if (x < 0.5) { |
| 10398 | // move the window out of the screen. |
| 10399 | t.getMatrix().setTranslate(mWidth, 0); |
| 10400 | } else { |
| 10401 | t.getMatrix().setTranslate(0, 0);// show |
| 10402 | t.setAlpha((x - 0.5f) * 2); |
| 10403 | } |
| 10404 | } |
| 10405 | |
| 10406 | @Override |
| 10407 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 10408 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 10409 | mWidth = width; |
| 10410 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10411 | |
| 10412 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 10413 | public int getZAdjustment() { |
| 10414 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10415 | } |
| 10416 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10417 | } |