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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 21 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 24 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 25 | 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] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 27 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 30 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | import com.android.internal.app.IBatteryStats; |
| 38 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 39 | import com.android.internal.policy.impl.PhoneWindowManager; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 40 | import com.android.internal.view.BaseInputHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import com.android.internal.view.IInputContext; |
| 42 | import com.android.internal.view.IInputMethodClient; |
| 43 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 44 | import com.android.internal.view.WindowManagerPolicyThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import com.android.server.am.BatteryStatsService; |
| 46 | |
| 47 | import android.Manifest; |
| 48 | import android.app.ActivityManagerNative; |
| 49 | import android.app.IActivityManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 50 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 51 | import android.content.BroadcastReceiver; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 52 | import android.content.ClipData; |
| 53 | import android.content.ClipDescription; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 55 | import android.content.Intent; |
| 56 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.content.pm.ActivityInfo; |
| 58 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 59 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.content.res.Configuration; |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 61 | import android.content.res.Resources; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 62 | import android.graphics.Bitmap; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 63 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.graphics.Matrix; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 65 | import android.graphics.Paint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.graphics.PixelFormat; |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 67 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.graphics.Rect; |
| 69 | import android.graphics.Region; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 70 | import android.graphics.Typeface; |
| 71 | import android.graphics.Paint.FontMetricsInt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.BatteryStats; |
| 73 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 74 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.Debug; |
| 76 | import android.os.Handler; |
| 77 | import android.os.IBinder; |
| 78 | import android.os.LocalPowerManager; |
| 79 | import android.os.Looper; |
| 80 | import android.os.Message; |
| 81 | import android.os.Parcel; |
| 82 | import android.os.ParcelFileDescriptor; |
| 83 | import android.os.Power; |
| 84 | import android.os.PowerManager; |
| 85 | import android.os.Process; |
| 86 | import android.os.RemoteException; |
| 87 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 88 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.os.SystemClock; |
| 90 | import android.os.SystemProperties; |
| 91 | import android.os.TokenWatcher; |
| 92 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 93 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 95 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 96 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 98 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.view.Display; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 100 | import android.view.DragEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.view.Gravity; |
| 102 | import android.view.IApplicationToken; |
| 103 | import android.view.IOnKeyguardExitResult; |
| 104 | import android.view.IRotationWatcher; |
| 105 | import android.view.IWindow; |
| 106 | import android.view.IWindowManager; |
| 107 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 109 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 110 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 111 | import android.view.InputHandler; |
| 112 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.KeyEvent; |
| 114 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.Surface; |
| 116 | import android.view.SurfaceSession; |
| 117 | import android.view.View; |
| 118 | import android.view.ViewTreeObserver; |
| 119 | import android.view.WindowManager; |
| 120 | import android.view.WindowManagerImpl; |
| 121 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 122 | import android.view.Surface.OutOfResourcesException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 124 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.animation.Animation; |
| 126 | import android.view.animation.AnimationUtils; |
| 127 | import android.view.animation.Transformation; |
| 128 | |
| 129 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 130 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.io.File; |
| 132 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 133 | import java.io.FileInputStream; |
| 134 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import java.io.IOException; |
| 136 | import java.io.OutputStream; |
| 137 | import java.io.OutputStreamWriter; |
| 138 | import java.io.PrintWriter; |
| 139 | import java.io.StringWriter; |
| 140 | import java.net.Socket; |
| 141 | import java.util.ArrayList; |
| 142 | import java.util.HashMap; |
| 143 | import java.util.HashSet; |
| 144 | import java.util.Iterator; |
| 145 | import java.util.List; |
| 146 | |
| 147 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 148 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 149 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | static final String TAG = "WindowManager"; |
| 151 | static final boolean DEBUG = false; |
| 152 | static final boolean DEBUG_FOCUS = false; |
| 153 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 154 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_LAYERS = false; |
| 157 | static final boolean DEBUG_INPUT = false; |
| 158 | static final boolean DEBUG_INPUT_METHOD = false; |
| 159 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 160 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 162 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 164 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 165 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 166 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 167 | static final boolean DEBUG_DRAG = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 169 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | static final boolean PROFILE_ORIENTATION = false; |
| 172 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 173 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | /** How much to multiply the policy's type layer, to reserve room |
| 176 | * for multiple windows of the same type and Z-ordering adjustment |
| 177 | * with TYPE_LAYER_OFFSET. */ |
| 178 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 181 | * or below others in the same layer. */ |
| 182 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | /** How much to increment the layer for each window, to reserve room |
| 185 | * for effect surfaces between them. |
| 186 | */ |
| 187 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | /** The maximum length we will accept for a loaded animation duration: |
| 190 | * this is 10 seconds. |
| 191 | */ |
| 192 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 193 | |
| 194 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 195 | * value to another, when no window animation is driving it. |
| 196 | */ |
| 197 | static final int DEFAULT_DIM_DURATION = 200; |
| 198 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 199 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 200 | * compatible windows. |
| 201 | */ |
| 202 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 203 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 204 | /** |
| 205 | * If true, the window manager will do its own custom freezing and general |
| 206 | * management of the screen during rotation. |
| 207 | */ |
| 208 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 209 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 210 | // Maximum number of milliseconds to wait for input event injection. |
| 211 | // FIXME is this value reasonable? |
| 212 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 213 | |
| 214 | // Default input dispatching timeout in nanoseconds. |
| 215 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 218 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 219 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 220 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 223 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 227 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 228 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 229 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 231 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 233 | private static final int ALLOW_DISABLE_YES = 1; |
| 234 | private static final int ALLOW_DISABLE_NO = 0; |
| 235 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 236 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 237 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 238 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 239 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 241 | if (shouldAllowDisableKeyguard()) { |
| 242 | mPolicy.enableKeyguard(false); |
| 243 | mKeyguardDisabled = true; |
| 244 | } else { |
| 245 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | } |
| 248 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 249 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 250 | synchronized (mKeyguardTokenWatcher) { |
| 251 | mKeyguardDisabled = false; |
| 252 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | }; |
| 256 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 257 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 258 | @Override |
| 259 | public void onReceive(Context context, Intent intent) { |
| 260 | mPolicy.enableKeyguard(true); |
| 261 | synchronized(mKeyguardTokenWatcher) { |
| 262 | // lazily evaluate this next time we're asked to disable keyguard |
| 263 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 264 | mKeyguardDisabled = false; |
| 265 | } |
| 266 | } |
| 267 | }; |
| 268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | final Context mContext; |
| 270 | |
| 271 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 276 | |
| 277 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | /** |
| 282 | * All currently active sessions with clients. |
| 283 | */ |
| 284 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | /** |
| 287 | * Mapping from an IWindow IBinder to the server's Window object. |
| 288 | * This is also used as the lock for all of our state. |
| 289 | */ |
| 290 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 291 | |
| 292 | /** |
| 293 | * Mapping from a token IBinder to a WindowToken object. |
| 294 | */ |
| 295 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 296 | new HashMap<IBinder, WindowToken>(); |
| 297 | |
| 298 | /** |
| 299 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 300 | * over them. |
| 301 | */ |
| 302 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | /** |
| 305 | * Window tokens that are in the process of exiting, but still |
| 306 | * on screen for animations. |
| 307 | */ |
| 308 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 309 | |
| 310 | /** |
| 311 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 312 | * controlling the ordering of windows in different applications. This |
| 313 | * contains WindowToken objects. |
| 314 | */ |
| 315 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 316 | |
| 317 | /** |
| 318 | * Application tokens that are in the process of exiting, but still |
| 319 | * on screen for animations. |
| 320 | */ |
| 321 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 322 | |
| 323 | /** |
| 324 | * List of window tokens that have finished starting their application, |
| 325 | * and now need to have the policy remove their windows. |
| 326 | */ |
| 327 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 328 | |
| 329 | /** |
| 330 | * Z-ordered (bottom-most first) list of all Window objects. |
| 331 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 332 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * Windows that are being resized. Used so we can tell the client about |
| 336 | * the resize after closing the transaction in which we resized the |
| 337 | * underlying surface. |
| 338 | */ |
| 339 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 340 | |
| 341 | /** |
| 342 | * Windows whose animations have ended and now must be removed. |
| 343 | */ |
| 344 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 345 | |
| 346 | /** |
| 347 | * Windows whose surface should be destroyed. |
| 348 | */ |
| 349 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 350 | |
| 351 | /** |
| 352 | * Windows that have lost input focus and are waiting for the new |
| 353 | * focus window to be displayed before they are told about this. |
| 354 | */ |
| 355 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 356 | |
| 357 | /** |
| 358 | * This is set when we have run out of memory, and will either be an empty |
| 359 | * list or contain windows that need to be force removed. |
| 360 | */ |
| 361 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 366 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | Surface mBlurSurface; |
| 368 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 369 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 370 | StrictModeFlash mStrictModeFlash; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 371 | ScreenRotationAnimation mScreenRotationAnimation; |
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 | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 456 | // Window currently running an animation that has requested it be detached |
| 457 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 458 | // visible behind it in case it animates in a way that would allow it to be |
| 459 | // seen. |
| 460 | WindowState mWindowDetachedWallpaper = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 461 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 462 | float mLastWallpaperX = -1; |
| 463 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 464 | float mLastWallpaperXStep = -1; |
| 465 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 466 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 467 | // changing its scroll position. |
| 468 | WindowState mWaitingOnWallpaper; |
| 469 | // The last time we had a timeout when waiting for a wallpaper. |
| 470 | long mLastWallpaperTimeoutTime; |
| 471 | // We give a wallpaper up to 150ms to finish scrolling. |
| 472 | static final long WALLPAPER_TIMEOUT = 150; |
| 473 | // Time we wait after a timeout before trying to wait again. |
| 474 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | AppWindowToken mFocusedApp = null; |
| 477 | |
| 478 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | float mWindowAnimationScale = 1.0f; |
| 481 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 482 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 483 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | |
| 485 | // Who is holding the screen on. |
| 486 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 487 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 488 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 489 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 492 | * Drag/drop state |
| 493 | */ |
| 494 | class DragState { |
| 495 | IBinder mToken; |
| 496 | Surface mSurface; |
| 497 | boolean mLocalOnly; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 498 | IBinder mLocalWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 499 | ClipData mData; |
| 500 | ClipDescription mDataDescription; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 501 | boolean mDragResult; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 502 | float mCurrentX, mCurrentY; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 503 | float mThumbOffsetX, mThumbOffsetY; |
| 504 | InputChannel mServerChannel, mClientChannel; |
| 505 | WindowState mTargetWindow; |
| 506 | ArrayList<WindowState> mNotifiedWindows; |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 507 | boolean mDragInProgress; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 508 | |
| 509 | private final Rect tmpRect = new Rect(); |
| 510 | |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 511 | DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 512 | mToken = token; |
| 513 | mSurface = surface; |
| 514 | mLocalOnly = localOnly; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 515 | mLocalWin = localWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 516 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 517 | } |
| 518 | |
| 519 | void reset() { |
| 520 | if (mSurface != null) { |
| 521 | mSurface.destroy(); |
| 522 | } |
| 523 | mSurface = null; |
| 524 | mLocalOnly = false; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 525 | mLocalWin = null; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 526 | mToken = null; |
| 527 | mData = null; |
| 528 | mThumbOffsetX = mThumbOffsetY = 0; |
| 529 | mNotifiedWindows = null; |
| 530 | } |
| 531 | |
| 532 | void register() { |
| 533 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 534 | if (mClientChannel != null) { |
| 535 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 536 | } else { |
| 537 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 538 | mServerChannel = channels[0]; |
| 539 | mClientChannel = channels[1]; |
| 540 | mInputManager.registerInputChannel(mServerChannel); |
| 541 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 542 | mH.getLooper().getQueue()); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | void unregister() { |
| 547 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 548 | if (mClientChannel == null) { |
| 549 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 550 | } else { |
| 551 | mInputManager.unregisterInputChannel(mServerChannel); |
| 552 | InputQueue.unregisterInputChannel(mClientChannel); |
| 553 | mClientChannel.dispose(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 554 | mServerChannel.dispose(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 555 | mClientChannel = null; |
| 556 | mServerChannel = null; |
| 557 | } |
| 558 | } |
| 559 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 560 | int getDragLayerLw() { |
| 561 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 562 | * TYPE_LAYER_MULTIPLIER |
| 563 | + TYPE_LAYER_OFFSET; |
| 564 | } |
| 565 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 566 | /* call out to each visible window/session informing it about the drag |
| 567 | */ |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 568 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 569 | // Cache a base-class instance of the clip metadata so that parceling |
| 570 | // works correctly in calling out to the apps. |
Dianne Hackborn | f834dfa | 2010-10-26 12:43:57 -0700 | [diff] [blame] | 571 | mDataDescription = mData.getDescription(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 572 | mNotifiedWindows.clear(); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 573 | mDragInProgress = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 574 | |
| 575 | if (DEBUG_DRAG) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 576 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 579 | final int N = mWindows.size(); |
| 580 | for (int i = 0; i < N; i++) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 581 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 582 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 586 | * designated window is potentially a drop recipient. There are race situations |
| 587 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 588 | * the drag has ended, we never send out another DRAG_STARTED for this drag action. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 589 | * |
| 590 | * This method clones the 'event' parameter if it's being delivered to the same |
| 591 | * process, so it's safe for the caller to call recycle() on the event afterwards. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 592 | */ |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 593 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 594 | ClipDescription desc) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 595 | // Don't actually send the event if the drag is supposed to be pinned |
| 596 | // to the originating window but 'newWin' is not that window. |
| 597 | if (mLocalOnly) { |
| 598 | final IBinder winBinder = newWin.mClient.asBinder(); |
| 599 | if (winBinder != mLocalWin) { |
| 600 | if (DEBUG_DRAG) { |
| 601 | Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin); |
| 602 | } |
| 603 | return; |
| 604 | } |
| 605 | } |
| 606 | |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 607 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 608 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 609 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 610 | null, desc, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 611 | try { |
| 612 | newWin.mClient.dispatchDragEvent(event); |
| 613 | // track each window that we've notified that the drag is starting |
| 614 | mNotifiedWindows.add(newWin); |
| 615 | } catch (RemoteException e) { |
| 616 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 617 | } finally { |
| 618 | // if the callee was local, the dispatch has already recycled the event |
| 619 | if (Process.myPid() != newWin.mSession.mPid) { |
| 620 | event.recycle(); |
| 621 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 627 | * previously been notified, i.e. it became visible after the drag operation |
| 628 | * was begun. This is a rare case. |
| 629 | */ |
| 630 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 631 | if (mDragInProgress) { |
| 632 | // If we have sent the drag-started, we needn't do so again |
| 633 | for (WindowState ws : mNotifiedWindows) { |
| 634 | if (ws == newWin) { |
| 635 | return; |
| 636 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 637 | } |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 638 | if (DEBUG_DRAG) { |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 639 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 640 | } |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 641 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 642 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 645 | void broadcastDragEndedLw() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 646 | if (DEBUG_DRAG) { |
| 647 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 648 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 649 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 650 | 0, 0, null, null, null, mDragResult); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 651 | for (WindowState ws: mNotifiedWindows) { |
| 652 | try { |
| 653 | ws.mClient.dispatchDragEvent(evt); |
| 654 | } catch (RemoteException e) { |
| 655 | Slog.w(TAG, "Unable to drag-end window " + ws); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 656 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 657 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 658 | mNotifiedWindows.clear(); |
| 659 | mDragInProgress = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 660 | evt.recycle(); |
| 661 | } |
| 662 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 663 | void endDragLw() { |
| 664 | mDragState.broadcastDragEndedLw(); |
| 665 | |
| 666 | // stop intercepting input |
| 667 | mDragState.unregister(); |
| 668 | mInputMonitor.updateInputWindowsLw(); |
| 669 | |
| 670 | // free our resources and drop all the object references |
| 671 | mDragState.reset(); |
| 672 | mDragState = null; |
| 673 | } |
| 674 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 675 | void notifyMoveLw(float x, float y) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 676 | final int myPid = Process.myPid(); |
| 677 | |
| 678 | // Move the surface to the given touch |
| 679 | mSurface.openTransaction(); |
| 680 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 681 | mSurface.closeTransaction(); |
| 682 | |
| 683 | // Tell the affected window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 684 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 685 | if (mLocalOnly) { |
| 686 | final IBinder touchedBinder = touchedWin.mClient.asBinder(); |
| 687 | if (touchedBinder != mLocalWin) { |
| 688 | // This drag is pinned only to the originating window, but the drag |
| 689 | // point is outside that window. Pretend it's over empty space. |
| 690 | touchedWin = null; |
| 691 | } |
| 692 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 693 | try { |
| 694 | // have we dragged over a new window? |
| 695 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 696 | if (DEBUG_DRAG) { |
| 697 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 698 | } |
| 699 | // force DRAG_EXITED_EVENT if appropriate |
| 700 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 701 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 702 | null, null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 703 | mTargetWindow.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 704 | if (myPid != mTargetWindow.mSession.mPid) { |
| 705 | evt.recycle(); |
| 706 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 707 | } |
| 708 | if (touchedWin != null) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 709 | if (false && DEBUG_DRAG) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 710 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 711 | } |
| 712 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 713 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 714 | null, null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 715 | touchedWin.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 716 | if (myPid != touchedWin.mSession.mPid) { |
| 717 | evt.recycle(); |
| 718 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 719 | } |
| 720 | } catch (RemoteException e) { |
| 721 | Slog.w(TAG, "can't send drag notification to windows"); |
| 722 | } |
| 723 | mTargetWindow = touchedWin; |
| 724 | } |
| 725 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 726 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 727 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 728 | // result from the recipient. |
| 729 | boolean notifyDropLw(float x, float y) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 730 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 731 | if (touchedWin == null) { |
| 732 | // "drop" outside a valid window -- no recipient to apply a |
| 733 | // timeout to, and we can send the drag-ended message immediately. |
| 734 | mDragResult = false; |
| 735 | return true; |
| 736 | } |
| 737 | |
| 738 | if (DEBUG_DRAG) { |
| 739 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 740 | } |
| 741 | final int myPid = Process.myPid(); |
| 742 | final IBinder token = touchedWin.mClient.asBinder(); |
| 743 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 744 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 745 | null, null, mData, false); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 746 | try { |
| 747 | touchedWin.mClient.dispatchDragEvent(evt); |
| 748 | |
| 749 | // 5 second timeout for this window to respond to the drop |
| 750 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 751 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 752 | mH.sendMessageDelayed(msg, 5000); |
| 753 | } catch (RemoteException e) { |
| 754 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 755 | return true; |
| 756 | } finally { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 757 | if (myPid != touchedWin.mSession.mPid) { |
| 758 | evt.recycle(); |
| 759 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 760 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 761 | mToken = token; |
| 762 | return false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // Find the visible, touch-deliverable window under the given point |
| 766 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 767 | WindowState touchedWin = null; |
| 768 | final int x = (int) xf; |
| 769 | final int y = (int) yf; |
| 770 | final ArrayList<WindowState> windows = mWindows; |
| 771 | final int N = windows.size(); |
| 772 | for (int i = N - 1; i >= 0; i--) { |
| 773 | WindowState child = windows.get(i); |
| 774 | final int flags = child.mAttrs.flags; |
| 775 | if (!child.isVisibleLw()) { |
| 776 | // not visible == don't tell about drags |
| 777 | continue; |
| 778 | } |
| 779 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 780 | // not touchable == don't tell about drags |
| 781 | continue; |
| 782 | } |
| 783 | // account for the window's decor etc |
| 784 | tmpRect.set(child.mFrame); |
| 785 | if (child.mTouchableInsets == ViewTreeObserver |
| 786 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 787 | // The point is inside of the window if it is |
| 788 | // inside the frame, AND the content part of that |
| 789 | // frame that was given by the application. |
| 790 | tmpRect.left += child.mGivenContentInsets.left; |
| 791 | tmpRect.top += child.mGivenContentInsets.top; |
| 792 | tmpRect.right -= child.mGivenContentInsets.right; |
| 793 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 794 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 795 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 796 | // The point is inside of the window if it is |
| 797 | // inside the frame, AND the visible part of that |
| 798 | // frame that was given by the application. |
| 799 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 800 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 801 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 802 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 803 | } |
| 804 | final int touchFlags = flags & |
| 805 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 806 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 807 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 808 | // Found it |
| 809 | touchedWin = child; |
| 810 | break; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | return touchedWin; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | DragState mDragState = null; |
| 819 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 820 | @Override |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 821 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 822 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 823 | try { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 824 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 825 | && mDragState != null) { |
| 826 | boolean endDrag = false; |
| 827 | final float newX = event.getRawX(); |
| 828 | final float newY = event.getRawY(); |
| 829 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 830 | switch (event.getAction()) { |
| 831 | case MotionEvent.ACTION_DOWN: { |
| 832 | if (DEBUG_DRAG) { |
| 833 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 834 | } |
| 835 | } break; |
| 836 | |
| 837 | case MotionEvent.ACTION_MOVE: { |
| 838 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 839 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 840 | mDragState.notifyMoveLw(newX, newY); |
| 841 | } |
| 842 | } break; |
| 843 | |
| 844 | case MotionEvent.ACTION_UP: { |
| 845 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 846 | + newX + "," + newY); |
| 847 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 848 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 849 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 850 | } break; |
| 851 | |
| 852 | case MotionEvent.ACTION_CANCEL: { |
| 853 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 854 | endDrag = true; |
| 855 | } break; |
| 856 | } |
| 857 | |
| 858 | if (endDrag) { |
| 859 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 860 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 861 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 862 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 863 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 864 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 865 | |
| 866 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 867 | } |
| 868 | } catch (Exception e) { |
| 869 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 870 | } finally { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 871 | finishedCallback.finished(handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | }; |
| 875 | |
| 876 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | * Whether the UI is currently running in touch mode (not showing |
| 878 | * navigational focus because the user is directly pressing the screen). |
| 879 | */ |
| 880 | boolean mInTouchMode = false; |
| 881 | |
| 882 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 883 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 884 | new ArrayList<WindowChangeListener>(); |
| 885 | private boolean mWindowsChanged = false; |
| 886 | |
| 887 | public interface WindowChangeListener { |
| 888 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 889 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 890 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 892 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 893 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 894 | |
| 895 | // The frame use to limit the size of the app running in compatibility mode. |
| 896 | Rect mCompatibleScreenFrame = new Rect(); |
| 897 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 898 | Surface mBackgroundFillerSurface = null; |
| 899 | boolean mBackgroundFillerShown = false; |
| 900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | public static WindowManagerService main(Context context, |
| 902 | PowerManagerService pm, boolean haveInputMethods) { |
| 903 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 904 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | synchronized (thr) { |
| 907 | while (thr.mService == null) { |
| 908 | try { |
| 909 | thr.wait(); |
| 910 | } catch (InterruptedException e) { |
| 911 | } |
| 912 | } |
| 913 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | return thr.mService; |
| 916 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | static class WMThread extends Thread { |
| 919 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | private final Context mContext; |
| 922 | private final PowerManagerService mPM; |
| 923 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | public WMThread(Context context, PowerManagerService pm, |
| 926 | boolean haveInputMethods) { |
| 927 | super("WindowManager"); |
| 928 | mContext = context; |
| 929 | mPM = pm; |
| 930 | mHaveInputMethods = haveInputMethods; |
| 931 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | public void run() { |
| 934 | Looper.prepare(); |
| 935 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 936 | mHaveInputMethods); |
| 937 | android.os.Process.setThreadPriority( |
| 938 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 939 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 940 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | synchronized (this) { |
| 942 | mService = s; |
| 943 | notifyAll(); |
| 944 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 945 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 946 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 947 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 948 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 949 | } |
| 950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | Looper.loop(); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | static class PolicyThread extends Thread { |
| 956 | private final WindowManagerPolicy mPolicy; |
| 957 | private final WindowManagerService mService; |
| 958 | private final Context mContext; |
| 959 | private final PowerManagerService mPM; |
| 960 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | public PolicyThread(WindowManagerPolicy policy, |
| 963 | WindowManagerService service, Context context, |
| 964 | PowerManagerService pm) { |
| 965 | super("WindowManagerPolicy"); |
| 966 | mPolicy = policy; |
| 967 | mService = service; |
| 968 | mContext = context; |
| 969 | mPM = pm; |
| 970 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | public void run() { |
| 973 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 974 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 977 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | android.os.Process.setThreadPriority( |
| 979 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 980 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | synchronized (this) { |
| 984 | mRunning = true; |
| 985 | notifyAll(); |
| 986 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 987 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 988 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 989 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 990 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 991 | } |
| 992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | Looper.loop(); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | private WindowManagerService(Context context, PowerManagerService pm, |
| 998 | boolean haveInputMethods) { |
| 999 | mContext = context; |
| 1000 | mHaveInputMethods = haveInputMethods; |
| 1001 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 1002 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | mPowerManager = pm; |
| 1005 | mPowerManager.setPolicy(mPolicy); |
| 1006 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1007 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1008 | "SCREEN_FROZEN"); |
| 1009 | mScreenFrozenLock.setReferenceCounted(false); |
| 1010 | |
| 1011 | mActivityManager = ActivityManagerNative.getDefault(); |
| 1012 | mBatteryStats = BatteryStatsService.getService(); |
| 1013 | |
| 1014 | // Get persisted window scale setting |
| 1015 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1016 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 1017 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1018 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1019 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1020 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 1021 | IntentFilter filter = new IntentFilter(); |
| 1022 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 1023 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 1024 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1025 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 1026 | "KEEP_SCREEN_ON_FLAG"); |
| 1027 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1029 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 1032 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | synchronized (thr) { |
| 1035 | while (!thr.mRunning) { |
| 1036 | try { |
| 1037 | thr.wait(); |
| 1038 | } catch (InterruptedException e) { |
| 1039 | } |
| 1040 | } |
| 1041 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1042 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1043 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | // Add ourself to the Watchdog monitors. |
| 1046 | Watchdog.getInstance().addMonitor(this); |
| 1047 | } |
| 1048 | |
| 1049 | @Override |
| 1050 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1051 | throws RemoteException { |
| 1052 | try { |
| 1053 | return super.onTransact(code, data, reply, flags); |
| 1054 | } catch (RuntimeException e) { |
| 1055 | // The window manager only throws security exceptions, so let's |
| 1056 | // log all others. |
| 1057 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1058 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | } |
| 1060 | throw e; |
| 1061 | } |
| 1062 | } |
| 1063 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1064 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1066 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | TAG, "Adding window " + window + " at " |
| 1068 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1069 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1070 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1073 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1075 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | TAG, "Adding window " + window + " at " |
| 1077 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1078 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1079 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | //This method finds out the index of a window that has the same app token as |
| 1083 | //win. used for z ordering the windows in mWindows |
| 1084 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1085 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1086 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | int jmax = localmWindows.size(); |
| 1088 | if(jmax == 0) { |
| 1089 | return -1; |
| 1090 | } |
| 1091 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1092 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | if(wentry.mAppToken == win.mAppToken) { |
| 1094 | return j; |
| 1095 | } |
| 1096 | } |
| 1097 | return -1; |
| 1098 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1101 | final IWindow client = win.mClient; |
| 1102 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1103 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | final int N = localmWindows.size(); |
| 1106 | final WindowState attached = win.mAttachedWindow; |
| 1107 | int i; |
| 1108 | if (attached == null) { |
| 1109 | int tokenWindowsPos = token.windows.size(); |
| 1110 | if (token.appWindowToken != null) { |
| 1111 | int index = tokenWindowsPos-1; |
| 1112 | if (index >= 0) { |
| 1113 | // If this application has existing windows, we |
| 1114 | // simply place the new window on top of them... but |
| 1115 | // keep the starting window on top. |
| 1116 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1117 | // Base windows go behind everything else. |
| 1118 | placeWindowBefore(token.windows.get(0), win); |
| 1119 | tokenWindowsPos = 0; |
| 1120 | } else { |
| 1121 | AppWindowToken atoken = win.mAppToken; |
| 1122 | if (atoken != null && |
| 1123 | token.windows.get(index) == atoken.startingWindow) { |
| 1124 | placeWindowBefore(token.windows.get(index), win); |
| 1125 | tokenWindowsPos--; |
| 1126 | } else { |
| 1127 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1128 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1129 | //there is a window above this one associated with the same |
| 1130 | //apptoken note that the window could be a floating window |
| 1131 | //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] | 1132 | //windows associated with this token. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1133 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1134 | TAG, "Adding window " + win + " at " |
| 1135 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1137 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1138 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1142 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | TAG, "Figuring out where to add app window " |
| 1144 | + client.asBinder() + " (token=" + token + ")"); |
| 1145 | // Figure out where the window should go, based on the |
| 1146 | // order of applications. |
| 1147 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1148 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | for (i=NA-1; i>=0; i--) { |
| 1150 | AppWindowToken t = mAppTokens.get(i); |
| 1151 | if (t == token) { |
| 1152 | i--; |
| 1153 | break; |
| 1154 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1155 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1156 | // We haven't reached the token yet; if this token |
| 1157 | // is not going to the bottom and has windows, we can |
| 1158 | // use it as an anchor for when we do reach the token. |
| 1159 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | pos = t.windows.get(0); |
| 1161 | } |
| 1162 | } |
| 1163 | // We now know the index into the apps. If we found |
| 1164 | // an app window above, that gives us the position; else |
| 1165 | // we need to look some more. |
| 1166 | if (pos != null) { |
| 1167 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1168 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | if (atoken != null) { |
| 1170 | final int NC = atoken.windows.size(); |
| 1171 | if (NC > 0) { |
| 1172 | WindowState bottom = atoken.windows.get(0); |
| 1173 | if (bottom.mSubLayer < 0) { |
| 1174 | pos = bottom; |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | placeWindowBefore(pos, win); |
| 1179 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1180 | // Continue looking down until we find the first |
| 1181 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | while (i >= 0) { |
| 1183 | AppWindowToken t = mAppTokens.get(i); |
| 1184 | final int NW = t.windows.size(); |
| 1185 | if (NW > 0) { |
| 1186 | pos = t.windows.get(NW-1); |
| 1187 | break; |
| 1188 | } |
| 1189 | i--; |
| 1190 | } |
| 1191 | if (pos != null) { |
| 1192 | // Move in front of any windows attached to this |
| 1193 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1194 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | if (atoken != null) { |
| 1196 | final int NC = atoken.windows.size(); |
| 1197 | if (NC > 0) { |
| 1198 | WindowState top = atoken.windows.get(NC-1); |
| 1199 | if (top.mSubLayer >= 0) { |
| 1200 | pos = top; |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | placeWindowAfter(pos, win); |
| 1205 | } else { |
| 1206 | // Just search for the start of this layer. |
| 1207 | final int myLayer = win.mBaseLayer; |
| 1208 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1209 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | if (w.mBaseLayer > myLayer) { |
| 1211 | break; |
| 1212 | } |
| 1213 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1214 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1215 | TAG, "Adding window " + win + " at " |
| 1216 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1217 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1218 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | } else { |
| 1223 | // Figure out where window should go, based on layer. |
| 1224 | final int myLayer = win.mBaseLayer; |
| 1225 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1226 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | i++; |
| 1228 | break; |
| 1229 | } |
| 1230 | } |
| 1231 | if (i < 0) i = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1232 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1233 | TAG, "Adding window " + win + " at " |
| 1234 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1236 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | } |
| 1238 | if (addToToken) { |
| 1239 | token.windows.add(tokenWindowsPos, win); |
| 1240 | } |
| 1241 | |
| 1242 | } else { |
| 1243 | // Figure out this window's ordering relative to the window |
| 1244 | // it is attached to. |
| 1245 | final int NA = token.windows.size(); |
| 1246 | final int sublayer = win.mSubLayer; |
| 1247 | int largestSublayer = Integer.MIN_VALUE; |
| 1248 | WindowState windowWithLargestSublayer = null; |
| 1249 | for (i=0; i<NA; i++) { |
| 1250 | WindowState w = token.windows.get(i); |
| 1251 | final int wSublayer = w.mSubLayer; |
| 1252 | if (wSublayer >= largestSublayer) { |
| 1253 | largestSublayer = wSublayer; |
| 1254 | windowWithLargestSublayer = w; |
| 1255 | } |
| 1256 | if (sublayer < 0) { |
| 1257 | // For negative sublayers, we go below all windows |
| 1258 | // in the same sublayer. |
| 1259 | if (wSublayer >= sublayer) { |
| 1260 | if (addToToken) { |
| 1261 | token.windows.add(i, win); |
| 1262 | } |
| 1263 | placeWindowBefore( |
| 1264 | wSublayer >= 0 ? attached : w, win); |
| 1265 | break; |
| 1266 | } |
| 1267 | } else { |
| 1268 | // For positive sublayers, we go above all windows |
| 1269 | // in the same sublayer. |
| 1270 | if (wSublayer > sublayer) { |
| 1271 | if (addToToken) { |
| 1272 | token.windows.add(i, win); |
| 1273 | } |
| 1274 | placeWindowBefore(w, win); |
| 1275 | break; |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | if (i >= NA) { |
| 1280 | if (addToToken) { |
| 1281 | token.windows.add(win); |
| 1282 | } |
| 1283 | if (sublayer < 0) { |
| 1284 | placeWindowBefore(attached, win); |
| 1285 | } else { |
| 1286 | placeWindowAfter(largestSublayer >= 0 |
| 1287 | ? windowWithLargestSublayer |
| 1288 | : attached, |
| 1289 | win); |
| 1290 | } |
| 1291 | } |
| 1292 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | if (win.mAppToken != null && addToToken) { |
| 1295 | win.mAppToken.allAppWindows.add(win); |
| 1296 | } |
| 1297 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | static boolean canBeImeTarget(WindowState w) { |
| 1300 | final int fl = w.mAttrs.flags |
| 1301 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1302 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1303 | return w.isVisibleOrAdding(); |
| 1304 | } |
| 1305 | return false; |
| 1306 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1309 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | final int N = localmWindows.size(); |
| 1311 | WindowState w = null; |
| 1312 | int i = N; |
| 1313 | while (i > 0) { |
| 1314 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1315 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1316 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1317 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1319 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1320 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | // Yet more tricksyness! If this window is a "starting" |
| 1323 | // window, we do actually want to be on top of it, but |
| 1324 | // it is not -really- where input will go. So if the caller |
| 1325 | // is not actually looking to move the IME, look down below |
| 1326 | // for a real window to target... |
| 1327 | if (!willMove |
| 1328 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1329 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1330 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1332 | i--; |
| 1333 | w = wb; |
| 1334 | } |
| 1335 | } |
| 1336 | break; |
| 1337 | } |
| 1338 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1341 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1342 | 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] | 1343 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1345 | if (willMove && w != null) { |
| 1346 | final WindowState curTarget = mInputMethodTarget; |
| 1347 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | // Now some fun for dealing with window animations that |
| 1350 | // modify the Z order. We need to look at all windows below |
| 1351 | // the current target that are in this app, finding the highest |
| 1352 | // visible one in layering. |
| 1353 | AppWindowToken token = curTarget.mAppToken; |
| 1354 | WindowState highestTarget = null; |
| 1355 | int highestPos = 0; |
| 1356 | if (token.animating || token.animation != null) { |
| 1357 | int pos = 0; |
| 1358 | pos = localmWindows.indexOf(curTarget); |
| 1359 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1360 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | if (win.mAppToken != token) { |
| 1362 | break; |
| 1363 | } |
| 1364 | if (!win.mRemoved) { |
| 1365 | if (highestTarget == null || win.mAnimLayer > |
| 1366 | highestTarget.mAnimLayer) { |
| 1367 | highestTarget = win; |
| 1368 | highestPos = pos; |
| 1369 | } |
| 1370 | } |
| 1371 | pos--; |
| 1372 | } |
| 1373 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1376 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | + mNextAppTransition + " " + highestTarget |
| 1378 | + " animating=" + highestTarget.isAnimating() |
| 1379 | + " layer=" + highestTarget.mAnimLayer |
| 1380 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1381 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1382 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | // If we are currently setting up for an animation, |
| 1384 | // hold everything until we can find out what will happen. |
| 1385 | mInputMethodTargetWaitingAnim = true; |
| 1386 | mInputMethodTarget = highestTarget; |
| 1387 | return highestPos + 1; |
| 1388 | } else if (highestTarget.isAnimating() && |
| 1389 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1390 | // If the window we are currently targeting is involved |
| 1391 | // with an animation, and it is on top of the next target |
| 1392 | // we will be over, then hold off on moving until |
| 1393 | // that is done. |
| 1394 | mInputMethodTarget = highestTarget; |
| 1395 | return highestPos + 1; |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1400 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1401 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | if (w != null) { |
| 1403 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1404 | if (DEBUG_INPUT_METHOD) { |
| 1405 | RuntimeException e = null; |
| 1406 | if (!HIDE_STACK_CRAWLS) { |
| 1407 | e = new RuntimeException(); |
| 1408 | e.fillInStackTrace(); |
| 1409 | } |
| 1410 | Slog.w(TAG, "Moving IM target from " |
| 1411 | + mInputMethodTarget + " to " + w, e); |
| 1412 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | mInputMethodTarget = w; |
| 1414 | if (w.mAppToken != null) { |
| 1415 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1416 | } else { |
| 1417 | setInputMethodAnimLayerAdjustment(0); |
| 1418 | } |
| 1419 | } |
| 1420 | return i+1; |
| 1421 | } |
| 1422 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1423 | if (DEBUG_INPUT_METHOD) { |
| 1424 | RuntimeException e = null; |
| 1425 | if (!HIDE_STACK_CRAWLS) { |
| 1426 | e = new RuntimeException(); |
| 1427 | e.fillInStackTrace(); |
| 1428 | } |
| 1429 | Slog.w(TAG, "Moving IM target from " |
| 1430 | + mInputMethodTarget + " to null", e); |
| 1431 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | mInputMethodTarget = null; |
| 1433 | setInputMethodAnimLayerAdjustment(0); |
| 1434 | } |
| 1435 | return -1; |
| 1436 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1438 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1439 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1440 | if (pos >= 0) { |
| 1441 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1442 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1443 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1445 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | moveInputMethodDialogsLocked(pos+1); |
| 1447 | return; |
| 1448 | } |
| 1449 | win.mTargetAppToken = null; |
| 1450 | addWindowToListInOrderLocked(win, true); |
| 1451 | moveInputMethodDialogsLocked(pos); |
| 1452 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1455 | 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] | 1456 | mInputMethodAnimLayerAdjustment = adj; |
| 1457 | WindowState imw = mInputMethodWindow; |
| 1458 | if (imw != null) { |
| 1459 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1460 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | + " anim layer: " + imw.mAnimLayer); |
| 1462 | int wi = imw.mChildWindows.size(); |
| 1463 | while (wi > 0) { |
| 1464 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1465 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1466 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1467 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | + " anim layer: " + cw.mAnimLayer); |
| 1469 | } |
| 1470 | } |
| 1471 | int di = mInputMethodDialogs.size(); |
| 1472 | while (di > 0) { |
| 1473 | di --; |
| 1474 | imw = mInputMethodDialogs.get(di); |
| 1475 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1476 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | + " anim layer: " + imw.mAnimLayer); |
| 1478 | } |
| 1479 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1482 | int wpos = mWindows.indexOf(win); |
| 1483 | if (wpos >= 0) { |
| 1484 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1485 | 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] | 1486 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1487 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | int NC = win.mChildWindows.size(); |
| 1489 | while (NC > 0) { |
| 1490 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1491 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1492 | int cpos = mWindows.indexOf(cw); |
| 1493 | if (cpos >= 0) { |
| 1494 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1495 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1496 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | mWindows.remove(cpos); |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | return interestingPos; |
| 1502 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1504 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1505 | addWindowToListInOrderLocked(win, false); |
| 1506 | // This is a hack to get all of the child windows added as well |
| 1507 | // at the right position. Child windows should be rare and |
| 1508 | // this case should be rare, so it shouldn't be that big a deal. |
| 1509 | int wpos = mWindows.indexOf(win); |
| 1510 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1511 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1512 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1514 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | reAddWindowLocked(wpos, win); |
| 1516 | } |
| 1517 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | void logWindowList(String prefix) { |
| 1520 | int N = mWindows.size(); |
| 1521 | while (N > 0) { |
| 1522 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1523 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | } |
| 1525 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | void moveInputMethodDialogsLocked(int pos) { |
| 1528 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1531 | 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] | 1532 | for (int i=0; i<N; i++) { |
| 1533 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1534 | } |
| 1535 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1536 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | logWindowList(" "); |
| 1538 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | if (pos >= 0) { |
| 1541 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1542 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1543 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | if (wp == mInputMethodWindow) { |
| 1545 | pos++; |
| 1546 | } |
| 1547 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1548 | 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] | 1549 | for (int i=0; i<N; i++) { |
| 1550 | WindowState win = dialogs.get(i); |
| 1551 | win.mTargetAppToken = targetAppToken; |
| 1552 | pos = reAddWindowLocked(pos, win); |
| 1553 | } |
| 1554 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1555 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | logWindowList(" "); |
| 1557 | } |
| 1558 | return; |
| 1559 | } |
| 1560 | for (int i=0; i<N; i++) { |
| 1561 | WindowState win = dialogs.get(i); |
| 1562 | win.mTargetAppToken = null; |
| 1563 | reAddWindowToListInOrderLocked(win); |
| 1564 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1565 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | logWindowList(" "); |
| 1567 | } |
| 1568 | } |
| 1569 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1572 | final WindowState imWin = mInputMethodWindow; |
| 1573 | final int DN = mInputMethodDialogs.size(); |
| 1574 | if (imWin == null && DN == 0) { |
| 1575 | return false; |
| 1576 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1579 | if (imPos >= 0) { |
| 1580 | // In this case, the input method windows are to be placed |
| 1581 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | // First check to see if the input method windows are already |
| 1584 | // located here, and contiguous. |
| 1585 | final int N = mWindows.size(); |
| 1586 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1587 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | // Figure out the actual input method window that should be |
| 1590 | // at the bottom of their stack. |
| 1591 | WindowState baseImWin = imWin != null |
| 1592 | ? imWin : mInputMethodDialogs.get(0); |
| 1593 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1594 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1596 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | if (firstImWin == baseImWin) { |
| 1599 | // The windows haven't moved... but are they still contiguous? |
| 1600 | // First find the top IM window. |
| 1601 | int pos = imPos+1; |
| 1602 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1603 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1604 | break; |
| 1605 | } |
| 1606 | pos++; |
| 1607 | } |
| 1608 | pos++; |
| 1609 | // Now there should be no more input method windows above. |
| 1610 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1611 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1612 | break; |
| 1613 | } |
| 1614 | pos++; |
| 1615 | } |
| 1616 | if (pos >= N) { |
| 1617 | // All is good! |
| 1618 | return false; |
| 1619 | } |
| 1620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | if (imWin != null) { |
| 1623 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1624 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | logWindowList(" "); |
| 1626 | } |
| 1627 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1628 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1629 | 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] | 1630 | logWindowList(" "); |
| 1631 | } |
| 1632 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1633 | reAddWindowLocked(imPos, imWin); |
| 1634 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1635 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | logWindowList(" "); |
| 1637 | } |
| 1638 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1639 | } else { |
| 1640 | moveInputMethodDialogsLocked(imPos); |
| 1641 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | } else { |
| 1644 | // In this case, the input method windows go in a fixed layer, |
| 1645 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1647 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1648 | 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] | 1649 | tmpRemoveWindowLocked(0, imWin); |
| 1650 | imWin.mTargetAppToken = null; |
| 1651 | reAddWindowToListInOrderLocked(imWin); |
| 1652 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1653 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1654 | logWindowList(" "); |
| 1655 | } |
| 1656 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1657 | } else { |
| 1658 | moveInputMethodDialogsLocked(-1);; |
| 1659 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | if (needAssignLayers) { |
| 1664 | assignLayersLocked(); |
| 1665 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | return true; |
| 1668 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | void adjustInputMethodDialogsLocked() { |
| 1671 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1672 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1673 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1674 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1675 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1676 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1677 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1678 | ? wallpaperTarget.mAppToken.animation : null) |
| 1679 | + " upper=" + mUpperWallpaperTarget |
| 1680 | + " lower=" + mLowerWallpaperTarget); |
| 1681 | return (wallpaperTarget != null |
| 1682 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1683 | && wallpaperTarget.mAppToken.animation != null))) |
| 1684 | || mUpperWallpaperTarget != null |
| 1685 | || mLowerWallpaperTarget != null; |
| 1686 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1687 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1688 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1689 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1690 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1691 | int adjustWallpaperWindowsLocked() { |
| 1692 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1693 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1694 | final int dw = mDisplay.getWidth(); |
| 1695 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1696 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1697 | // First find top-most window that has asked to be on top of the |
| 1698 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1699 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1700 | int N = localmWindows.size(); |
| 1701 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1702 | WindowState foundW = null; |
| 1703 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1704 | WindowState topCurW = null; |
| 1705 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1706 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1707 | int i = N; |
| 1708 | while (i > 0) { |
| 1709 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1710 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1711 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1712 | if (topCurW == null) { |
| 1713 | topCurW = w; |
| 1714 | topCurI = i; |
| 1715 | } |
| 1716 | continue; |
| 1717 | } |
| 1718 | topCurW = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1719 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1720 | // If this window's app token is hidden and not animating, |
| 1721 | // it is of no interest to us. |
| 1722 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1723 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1724 | "Skipping not hidden or animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1725 | continue; |
| 1726 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1727 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1728 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1729 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1730 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1731 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1732 | && (mWallpaperTarget == w |
| 1733 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1734 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1735 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1736 | foundW = w; |
| 1737 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1738 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1739 | && w.mAppToken.animation != null) |
| 1740 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1741 | // The current wallpaper target is animating, so we'll |
| 1742 | // look behind it for another possible target and figure |
| 1743 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1744 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1745 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1746 | continue; |
| 1747 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1748 | break; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1749 | } else if (w == mWindowDetachedWallpaper) { |
| 1750 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1751 | } |
| 1752 | } |
| 1753 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1754 | if (foundW == null && windowDetachedI >= 0) { |
| 1755 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1756 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1757 | foundW = w; |
| 1758 | foundI = windowDetachedI; |
| 1759 | } |
| 1760 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1761 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1762 | // If we are currently waiting for an app transition, and either |
| 1763 | // the current target or the next target are involved with it, |
| 1764 | // then hold off on doing anything with the wallpaper. |
| 1765 | // Note that we are checking here for just whether the target |
| 1766 | // is part of an app token... which is potentially overly aggressive |
| 1767 | // (the app token may not be involved in the transition), but good |
| 1768 | // enough (we'll just wait until whatever transition is pending |
| 1769 | // executes). |
| 1770 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1771 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1772 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1773 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1774 | } |
| 1775 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1776 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1777 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1778 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1779 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1780 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1781 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1782 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1783 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1784 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1785 | + " oldTarget: " + mWallpaperTarget); |
| 1786 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1787 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1788 | mLowerWallpaperTarget = null; |
| 1789 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1790 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1791 | WindowState oldW = mWallpaperTarget; |
| 1792 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1793 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1794 | // Now what is happening... if the current and new targets are |
| 1795 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1796 | if (foundW != null && oldW != null) { |
| 1797 | boolean oldAnim = oldW.mAnimation != null |
| 1798 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1799 | boolean foundAnim = foundW.mAnimation != null |
| 1800 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1801 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1802 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1803 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1804 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1805 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1806 | int oldI = localmWindows.indexOf(oldW); |
| 1807 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1808 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1809 | } |
| 1810 | if (oldI >= 0) { |
| 1811 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1812 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1813 | + "=" + oldW + "; new#" + foundI |
| 1814 | + "=" + foundW); |
| 1815 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1816 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1817 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1818 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1819 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1820 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1821 | } |
| 1822 | mWallpaperTarget = oldW; |
| 1823 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1824 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1825 | // Now set the upper and lower wallpaper targets |
| 1826 | // correctly, and make sure that we are positioning |
| 1827 | // the wallpaper below the lower. |
| 1828 | if (foundI > oldI) { |
| 1829 | // The new target is on top of the old one. |
| 1830 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1831 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1832 | } |
| 1833 | mUpperWallpaperTarget = foundW; |
| 1834 | mLowerWallpaperTarget = oldW; |
| 1835 | foundW = oldW; |
| 1836 | foundI = oldI; |
| 1837 | } else { |
| 1838 | // The new target is below the old one. |
| 1839 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1840 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1841 | } |
| 1842 | mUpperWallpaperTarget = oldW; |
| 1843 | mLowerWallpaperTarget = foundW; |
| 1844 | } |
| 1845 | } |
| 1846 | } |
| 1847 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1848 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1849 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1850 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1851 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1852 | || (mLowerWallpaperTarget.mAppToken != null |
| 1853 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1854 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1855 | || (mUpperWallpaperTarget.mAppToken != null |
| 1856 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1857 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1858 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1859 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1860 | } |
| 1861 | mLowerWallpaperTarget = null; |
| 1862 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1863 | } |
| 1864 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1865 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1866 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1867 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1868 | // The window is visible to the compositor... but is it visible |
| 1869 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1870 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1871 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1872 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1873 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1874 | // its layer adjustment. Only do this if we are not transfering |
| 1875 | // between two wallpaper targets. |
| 1876 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1877 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1878 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1879 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1880 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1881 | * TYPE_LAYER_MULTIPLIER |
| 1882 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1883 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1884 | // Now w is the window we are supposed to be behind... but we |
| 1885 | // 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] | 1886 | // AND any starting window associated with it, AND below the |
| 1887 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1888 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1889 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1890 | if (wb.mBaseLayer < maxLayer && |
| 1891 | wb.mAttachedWindow != foundW && |
Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1892 | wb.mAttachedWindow != foundW.mAttachedWindow && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1893 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1894 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1895 | // This window is not related to the previous one in any |
| 1896 | // interesting way, so stop here. |
| 1897 | break; |
| 1898 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1899 | foundW = wb; |
| 1900 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1901 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1902 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1903 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1904 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1905 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1906 | if (foundW == null && topCurW != null) { |
| 1907 | // There is no wallpaper target, so it goes at the bottom. |
| 1908 | // We will assume it is the same place as last time, if known. |
| 1909 | foundW = topCurW; |
| 1910 | foundI = topCurI+1; |
| 1911 | } else { |
| 1912 | // Okay i is the position immediately above the wallpaper. Look at |
| 1913 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1914 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1915 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1916 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1917 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1918 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1919 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1920 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1921 | } |
| 1922 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1923 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1924 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1925 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1926 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1927 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1928 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1929 | // are correctly placed. |
| 1930 | int curTokenIndex = mWallpaperTokens.size(); |
| 1931 | while (curTokenIndex > 0) { |
| 1932 | curTokenIndex--; |
| 1933 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1934 | if (token.hidden == visible) { |
| 1935 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1936 | token.hidden = !visible; |
| 1937 | // Need to do a layout to ensure the wallpaper now has the |
| 1938 | // correct size. |
| 1939 | mLayoutNeeded = true; |
| 1940 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1941 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1942 | int curWallpaperIndex = token.windows.size(); |
| 1943 | while (curWallpaperIndex > 0) { |
| 1944 | curWallpaperIndex--; |
| 1945 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1946 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1947 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1948 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1949 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1950 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1951 | // First, make sure the client has the current visibility |
| 1952 | // state. |
| 1953 | if (wallpaper.mWallpaperVisible != visible) { |
| 1954 | wallpaper.mWallpaperVisible = visible; |
| 1955 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1956 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1957 | "Setting visibility of wallpaper " + wallpaper |
| 1958 | + ": " + visible); |
| 1959 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1960 | } catch (RemoteException e) { |
| 1961 | } |
| 1962 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1963 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1964 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1965 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1966 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1967 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1968 | // First, if this window is at the current index, then all |
| 1969 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1970 | if (wallpaper == foundW) { |
| 1971 | foundI--; |
| 1972 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1973 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1974 | continue; |
| 1975 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1976 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1977 | // The window didn't match... the current wallpaper window, |
| 1978 | // wherever it is, is in the wrong place, so make sure it is |
| 1979 | // not in the list. |
| 1980 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1981 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1982 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1983 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1984 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1985 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1986 | if (oldIndex < foundI) { |
| 1987 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1988 | } |
| 1989 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1990 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1991 | // Now stick it in. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1992 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1993 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1994 | + " from " + oldIndex + " to " + foundI); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1995 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1996 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1997 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1998 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1999 | } |
| 2000 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2001 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2002 | return changed; |
| 2003 | } |
| 2004 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2005 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2006 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2007 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2008 | mWallpaperAnimLayerAdjustment = adj; |
| 2009 | int curTokenIndex = mWallpaperTokens.size(); |
| 2010 | while (curTokenIndex > 0) { |
| 2011 | curTokenIndex--; |
| 2012 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2013 | int curWallpaperIndex = token.windows.size(); |
| 2014 | while (curWallpaperIndex > 0) { |
| 2015 | curWallpaperIndex--; |
| 2016 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2017 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2018 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2019 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2020 | } |
| 2021 | } |
| 2022 | } |
| 2023 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2024 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 2025 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2026 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2027 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2028 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2029 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2030 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 2031 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 2032 | changed = wallpaperWin.mXOffset != offset; |
| 2033 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2034 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2035 | + wallpaperWin + " x: " + offset); |
| 2036 | wallpaperWin.mXOffset = offset; |
| 2037 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2038 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2039 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2040 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2041 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2042 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2043 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2044 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2045 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2046 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2047 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2048 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2049 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2050 | + wallpaperWin + " y: " + offset); |
| 2051 | changed = true; |
| 2052 | wallpaperWin.mYOffset = offset; |
| 2053 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2054 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2055 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2056 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2057 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2058 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2059 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2060 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2061 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2062 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2063 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2064 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2065 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2066 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2067 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2068 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2069 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2070 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2071 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2072 | if (mWaitingOnWallpaper != null) { |
| 2073 | long start = SystemClock.uptimeMillis(); |
| 2074 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2075 | < start) { |
| 2076 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2077 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2078 | "Waiting for offset complete..."); |
| 2079 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2080 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2081 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2082 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2083 | if ((start+WALLPAPER_TIMEOUT) |
| 2084 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2085 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2086 | + wallpaperWin); |
| 2087 | mLastWallpaperTimeoutTime = start; |
| 2088 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2089 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2090 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2091 | } |
| 2092 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2093 | } catch (RemoteException e) { |
| 2094 | } |
| 2095 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2096 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2097 | return changed; |
| 2098 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2099 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2100 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2101 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2102 | if (mWaitingOnWallpaper != null && |
| 2103 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2104 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2105 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2106 | } |
| 2107 | } |
| 2108 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2109 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2110 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2111 | final int dw = mDisplay.getWidth(); |
| 2112 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2113 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2114 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2115 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2116 | WindowState target = mWallpaperTarget; |
| 2117 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2118 | if (target.mWallpaperX >= 0) { |
| 2119 | mLastWallpaperX = target.mWallpaperX; |
| 2120 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2121 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2122 | } |
| 2123 | if (target.mWallpaperY >= 0) { |
| 2124 | mLastWallpaperY = target.mWallpaperY; |
| 2125 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2126 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2127 | } |
| 2128 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2129 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2130 | int curTokenIndex = mWallpaperTokens.size(); |
| 2131 | while (curTokenIndex > 0) { |
| 2132 | curTokenIndex--; |
| 2133 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2134 | int curWallpaperIndex = token.windows.size(); |
| 2135 | while (curWallpaperIndex > 0) { |
| 2136 | curWallpaperIndex--; |
| 2137 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2138 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2139 | wallpaper.computeShownFrameLocked(); |
| 2140 | changed = true; |
| 2141 | // We only want to be synchronous with one wallpaper. |
| 2142 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2143 | } |
| 2144 | } |
| 2145 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2146 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2147 | return changed; |
| 2148 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2149 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2150 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2151 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2152 | final int dw = mDisplay.getWidth(); |
| 2153 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2154 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2155 | int curTokenIndex = mWallpaperTokens.size(); |
| 2156 | while (curTokenIndex > 0) { |
| 2157 | curTokenIndex--; |
| 2158 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2159 | if (token.hidden == visible) { |
| 2160 | token.hidden = !visible; |
| 2161 | // Need to do a layout to ensure the wallpaper now has the |
| 2162 | // correct size. |
| 2163 | mLayoutNeeded = true; |
| 2164 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2165 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2166 | int curWallpaperIndex = token.windows.size(); |
| 2167 | while (curWallpaperIndex > 0) { |
| 2168 | curWallpaperIndex--; |
| 2169 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2170 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2171 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2172 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2173 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2174 | if (wallpaper.mWallpaperVisible != visible) { |
| 2175 | wallpaper.mWallpaperVisible = visible; |
| 2176 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2177 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2178 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2179 | + ": " + visible); |
| 2180 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2181 | } catch (RemoteException e) { |
| 2182 | } |
| 2183 | } |
| 2184 | } |
| 2185 | } |
| 2186 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | public int addWindow(Session session, IWindow client, |
| 2189 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2190 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | int res = mPolicy.checkAddPermission(attrs); |
| 2192 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2193 | return res; |
| 2194 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2196 | boolean reportNewConfig = false; |
| 2197 | WindowState attachedWindow = null; |
| 2198 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2199 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2202 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2203 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2204 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2207 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2208 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2209 | } |
| 2210 | |
| 2211 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2212 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2213 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2214 | 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] | 2215 | + attrs.token + ". Aborting."); |
| 2216 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2217 | } |
| 2218 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2219 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2220 | 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] | 2221 | + attrs.token + ". Aborting."); |
| 2222 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | boolean addToken = false; |
| 2227 | WindowToken token = mTokenMap.get(attrs.token); |
| 2228 | if (token == null) { |
| 2229 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2230 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2231 | 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] | 2232 | + attrs.token + ". Aborting."); |
| 2233 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2234 | } |
| 2235 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2236 | 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] | 2237 | + attrs.token + ". Aborting."); |
| 2238 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2239 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2240 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2241 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2242 | + attrs.token + ". Aborting."); |
| 2243 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2244 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | token = new WindowToken(attrs.token, -1, false); |
| 2246 | addToken = true; |
| 2247 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2248 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2249 | AppWindowToken atoken = token.appWindowToken; |
| 2250 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2251 | 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] | 2252 | + token + ". Aborting."); |
| 2253 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2254 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2255 | 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] | 2256 | + token + ". Aborting."); |
| 2257 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2258 | } |
| 2259 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2260 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2261 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2263 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2264 | } |
| 2265 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2266 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2267 | 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] | 2268 | + attrs.token + ". Aborting."); |
| 2269 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2270 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2271 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2272 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2273 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2274 | + attrs.token + ". Aborting."); |
| 2275 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | win = new WindowState(session, client, token, |
| 2280 | attachedWindow, attrs, viewVisibility); |
| 2281 | if (win.mDeathRecipient == null) { |
| 2282 | // Client has apparently died, so there is no reason to |
| 2283 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2284 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | + " that is dead, aborting."); |
| 2286 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2287 | } |
| 2288 | |
| 2289 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2292 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2293 | return res; |
| 2294 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2295 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2296 | if (outInputChannel != null) { |
| 2297 | String name = win.makeInputChannelName(); |
| 2298 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2299 | win.mInputChannel = inputChannels[0]; |
| 2300 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2301 | |
| 2302 | mInputManager.registerInputChannel(win.mInputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2303 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2304 | |
| 2305 | // From now on, no exceptions or errors allowed! |
| 2306 | |
| 2307 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2308 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2309 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2311 | if (addToken) { |
| 2312 | mTokenMap.put(attrs.token, token); |
| 2313 | mTokenList.add(token); |
| 2314 | } |
| 2315 | win.attach(); |
| 2316 | mWindowMap.put(client.asBinder(), win); |
| 2317 | |
| 2318 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2319 | token.appWindowToken != null) { |
| 2320 | token.appWindowToken.startingWindow = win; |
| 2321 | } |
| 2322 | |
| 2323 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2326 | mInputMethodWindow = win; |
| 2327 | addInputMethodWindowToListLocked(win); |
| 2328 | imMayMove = false; |
| 2329 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2330 | mInputMethodDialogs.add(win); |
| 2331 | addWindowToListInOrderLocked(win, true); |
| 2332 | adjustInputMethodDialogsLocked(); |
| 2333 | imMayMove = false; |
| 2334 | } else { |
| 2335 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2336 | if (attrs.type == TYPE_WALLPAPER) { |
| 2337 | mLastWallpaperTimeoutTime = 0; |
| 2338 | adjustWallpaperWindowsLocked(); |
| 2339 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2340 | adjustWallpaperWindowsLocked(); |
| 2341 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2346 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | if (mInTouchMode) { |
| 2349 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2350 | } |
| 2351 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2352 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2353 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2354 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2355 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2356 | if (win.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2357 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2358 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | imMayMove = false; |
| 2360 | } |
| 2361 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2363 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2364 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | assignLayersLocked(); |
| 2368 | // Don't do layout here, the window must call |
| 2369 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | //dump(); |
| 2372 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2373 | if (focusChanged) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2374 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2375 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2376 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2377 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2378 | TAG, "New client " + client.asBinder() |
| 2379 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2380 | |
| 2381 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2382 | reportNewConfig = true; |
| 2383 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2384 | } |
| 2385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2386 | if (reportNewConfig) { |
| 2387 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2388 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2389 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2392 | return res; |
| 2393 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | public void removeWindow(Session session, IWindow client) { |
| 2396 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2397 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | if (win == null) { |
| 2399 | return; |
| 2400 | } |
| 2401 | removeWindowLocked(session, win); |
| 2402 | } |
| 2403 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2405 | public void removeWindowLocked(Session session, WindowState win) { |
| 2406 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2407 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | TAG, "Remove " + win + " client=" |
| 2409 | + Integer.toHexString(System.identityHashCode( |
| 2410 | win.mClient.asBinder())) |
| 2411 | + ", surface=" + win.mSurface); |
| 2412 | |
| 2413 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2414 | |
| 2415 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2416 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2417 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2419 | + " mExiting=" + win.mExiting |
| 2420 | + " isAnimating=" + win.isAnimating() |
| 2421 | + " app-animation=" |
| 2422 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2423 | + " inPendingTransaction=" |
| 2424 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2425 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2426 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2427 | boolean wasVisible = false; |
| 2428 | // First, see if we need to run an animation. If we do, we have |
| 2429 | // to hold off on removing the window until the animation is done. |
| 2430 | // If the display is frozen, just remove immediately, since the |
| 2431 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2432 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | // If we are not currently running the exit animation, we |
| 2434 | // need to see about starting one. |
| 2435 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2438 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2439 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2440 | } |
| 2441 | // Try starting an animation. |
| 2442 | if (applyAnimationLocked(win, transit, false)) { |
| 2443 | win.mExiting = true; |
| 2444 | } |
| 2445 | } |
| 2446 | if (win.mExiting || win.isAnimating()) { |
| 2447 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2448 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | win.mExiting = true; |
| 2450 | win.mRemoveOnExit = true; |
| 2451 | mLayoutNeeded = true; |
| 2452 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2453 | performLayoutAndPlaceSurfacesLocked(); |
| 2454 | if (win.mAppToken != null) { |
| 2455 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2456 | } |
| 2457 | //dump(); |
| 2458 | Binder.restoreCallingIdentity(origId); |
| 2459 | return; |
| 2460 | } |
| 2461 | } |
| 2462 | |
| 2463 | removeWindowInnerLocked(session, win); |
| 2464 | // Removing a visible window will effect the computed orientation |
| 2465 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2466 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2467 | != mForcedAppOrientation |
| 2468 | && updateOrientationFromAppTokensLocked()) { |
| 2469 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | } |
| 2471 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2472 | Binder.restoreCallingIdentity(origId); |
| 2473 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2475 | private void removeWindowInnerLocked(Session session, WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2476 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | if (mInputMethodTarget == win) { |
| 2479 | moveInputMethodWindowsIfNeededLocked(false); |
| 2480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2481 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2482 | if (false) { |
| 2483 | RuntimeException e = new RuntimeException("here"); |
| 2484 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2485 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2486 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2488 | mPolicy.removeWindowLw(win); |
| 2489 | win.removeLocked(); |
| 2490 | |
| 2491 | mWindowMap.remove(win.mClient.asBinder()); |
| 2492 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2493 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2494 | 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] | 2495 | |
| 2496 | if (mInputMethodWindow == win) { |
| 2497 | mInputMethodWindow = null; |
| 2498 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2499 | mInputMethodDialogs.remove(win); |
| 2500 | } |
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 | final WindowToken token = win.mToken; |
| 2503 | final AppWindowToken atoken = win.mAppToken; |
| 2504 | token.windows.remove(win); |
| 2505 | if (atoken != null) { |
| 2506 | atoken.allAppWindows.remove(win); |
| 2507 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2508 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2509 | TAG, "**** Removing window " + win + ": count=" |
| 2510 | + token.windows.size()); |
| 2511 | if (token.windows.size() == 0) { |
| 2512 | if (!token.explicit) { |
| 2513 | mTokenMap.remove(token.token); |
| 2514 | mTokenList.remove(token); |
| 2515 | } else if (atoken != null) { |
| 2516 | atoken.firstWindowDrawn = false; |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | if (atoken != null) { |
| 2521 | if (atoken.startingWindow == win) { |
| 2522 | atoken.startingWindow = null; |
| 2523 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2524 | // If this is the last window and we had requested a starting |
| 2525 | // transition window, well there is no point now. |
| 2526 | atoken.startingData = null; |
| 2527 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2528 | // If this is the last window except for a starting transition |
| 2529 | // window, we need to get rid of the starting transition. |
| 2530 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2531 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2532 | + ": no more real windows"); |
| 2533 | } |
| 2534 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2535 | mH.sendMessage(m); |
| 2536 | } |
| 2537 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2538 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2539 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2540 | mLastWallpaperTimeoutTime = 0; |
| 2541 | adjustWallpaperWindowsLocked(); |
| 2542 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2543 | adjustWallpaperWindowsLocked(); |
| 2544 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | if (!mInLayout) { |
| 2547 | assignLayersLocked(); |
| 2548 | mLayoutNeeded = true; |
| 2549 | performLayoutAndPlaceSurfacesLocked(); |
| 2550 | if (win.mAppToken != null) { |
| 2551 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2552 | } |
| 2553 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2554 | |
| 2555 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2556 | } |
| 2557 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2558 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2559 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2560 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2561 | if (where != null) { |
| 2562 | Slog.i(TAG, str, where); |
| 2563 | } else { |
| 2564 | Slog.i(TAG, str); |
| 2565 | } |
| 2566 | } |
| 2567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2569 | long origId = Binder.clearCallingIdentity(); |
| 2570 | try { |
| 2571 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2572 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | if ((w != null) && (w.mSurface != null)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2574 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2575 | Surface.openTransaction(); |
| 2576 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2577 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2578 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2579 | w.mSurface.setTransparentRegionHint(region); |
| 2580 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2581 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2582 | Surface.closeTransaction(); |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | } finally { |
| 2587 | Binder.restoreCallingIdentity(origId); |
| 2588 | } |
| 2589 | } |
| 2590 | |
| 2591 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2592 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | Rect visibleInsets) { |
| 2594 | long origId = Binder.clearCallingIdentity(); |
| 2595 | try { |
| 2596 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2597 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | if (w != null) { |
| 2599 | w.mGivenInsetsPending = false; |
| 2600 | w.mGivenContentInsets.set(contentInsets); |
| 2601 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2602 | w.mTouchableInsets = touchableInsets; |
| 2603 | mLayoutNeeded = true; |
| 2604 | performLayoutAndPlaceSurfacesLocked(); |
| 2605 | } |
| 2606 | } |
| 2607 | } finally { |
| 2608 | Binder.restoreCallingIdentity(origId); |
| 2609 | } |
| 2610 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2613 | Rect outDisplayFrame) { |
| 2614 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2615 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2616 | if (win == null) { |
| 2617 | outDisplayFrame.setEmpty(); |
| 2618 | return; |
| 2619 | } |
| 2620 | outDisplayFrame.set(win.mDisplayFrame); |
| 2621 | } |
| 2622 | } |
| 2623 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2624 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2625 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2626 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2627 | window.mWallpaperX = x; |
| 2628 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2629 | window.mWallpaperXStep = xStep; |
| 2630 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2631 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2632 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2636 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2637 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2638 | synchronized (mWindowMap) { |
| 2639 | if (mWaitingOnWallpaper != null && |
| 2640 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2641 | mWaitingOnWallpaper = null; |
| 2642 | mWindowMap.notifyAll(); |
| 2643 | } |
| 2644 | } |
| 2645 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2646 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2647 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2648 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2649 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2650 | || window == mUpperWallpaperTarget) { |
| 2651 | boolean doWait = sync; |
| 2652 | int curTokenIndex = mWallpaperTokens.size(); |
| 2653 | while (curTokenIndex > 0) { |
| 2654 | curTokenIndex--; |
| 2655 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2656 | int curWallpaperIndex = token.windows.size(); |
| 2657 | while (curWallpaperIndex > 0) { |
| 2658 | curWallpaperIndex--; |
| 2659 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2660 | try { |
| 2661 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2662 | x, y, z, extras, sync); |
| 2663 | // We only want to be synchronous with one wallpaper. |
| 2664 | sync = false; |
| 2665 | } catch (RemoteException e) { |
| 2666 | } |
| 2667 | } |
| 2668 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2669 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2670 | if (doWait) { |
| 2671 | // XXX Need to wait for result. |
| 2672 | } |
| 2673 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2674 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2675 | return null; |
| 2676 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2678 | public int relayoutWindow(Session session, IWindow client, |
| 2679 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2680 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2681 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2682 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | boolean displayed = false; |
| 2684 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2685 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2688 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2689 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | if (win == null) { |
| 2691 | return 0; |
| 2692 | } |
| 2693 | win.mRequestedWidth = requestedWidth; |
| 2694 | win.mRequestedHeight = requestedHeight; |
| 2695 | |
| 2696 | if (attrs != null) { |
| 2697 | mPolicy.adjustWindowParamsLw(attrs); |
| 2698 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | int attrChanges = 0; |
| 2701 | int flagChanges = 0; |
| 2702 | if (attrs != null) { |
| 2703 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2704 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2705 | } |
| 2706 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2707 | 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] | 2708 | |
| 2709 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2710 | win.mAlpha = attrs.alpha; |
| 2711 | } |
| 2712 | |
| 2713 | final boolean scaledWindow = |
| 2714 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2715 | |
| 2716 | if (scaledWindow) { |
| 2717 | // requested{Width|Height} Surface's physical size |
| 2718 | // attrs.{width|height} Size on screen |
| 2719 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2720 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2721 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2722 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2723 | } else { |
| 2724 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | boolean imMayMove = (flagChanges&( |
| 2728 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2729 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2732 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2733 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2734 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2735 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2736 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | win.mRelayoutCalled = true; |
| 2739 | final int oldVisibility = win.mViewVisibility; |
| 2740 | win.mViewVisibility = viewVisibility; |
| 2741 | if (viewVisibility == View.VISIBLE && |
| 2742 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2743 | displayed = !win.isVisibleLw(); |
| 2744 | if (win.mExiting) { |
| 2745 | win.mExiting = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2746 | if (win.mAnimation != null) { |
| 2747 | win.mAnimation.cancel(); |
| 2748 | win.mAnimation = null; |
| 2749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | } |
| 2751 | if (win.mDestroying) { |
| 2752 | win.mDestroying = false; |
| 2753 | mDestroySurface.remove(win); |
| 2754 | } |
| 2755 | if (oldVisibility == View.GONE) { |
| 2756 | win.mEnterAnimationPending = true; |
| 2757 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2758 | if (displayed) { |
| 2759 | if (win.mSurface != null && !win.mDrawPending |
| 2760 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2761 | && mPolicy.isScreenOn()) { |
| 2762 | applyEnterAnimationLocked(win); |
| 2763 | } |
| 2764 | if ((win.mAttrs.flags |
| 2765 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2766 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2767 | "Relayout window turning screen on: " + win); |
| 2768 | win.mTurnOnScreen = true; |
| 2769 | } |
| 2770 | int diff = 0; |
| 2771 | if (win.mConfiguration != mCurConfiguration |
| 2772 | && (win.mConfiguration == null |
| 2773 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2774 | win.mConfiguration = mCurConfiguration; |
| 2775 | if (DEBUG_CONFIGURATION) { |
| 2776 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2777 | + win.mConfiguration + " / 0x" |
| 2778 | + Integer.toHexString(diff)); |
| 2779 | } |
| 2780 | outConfig.setTo(mCurConfiguration); |
| 2781 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2782 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2783 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2784 | // To change the format, we need to re-build the surface. |
| 2785 | win.destroySurfaceLocked(); |
| 2786 | displayed = true; |
| 2787 | } |
| 2788 | try { |
| 2789 | Surface surface = win.createSurfaceLocked(); |
| 2790 | if (surface != null) { |
| 2791 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2792 | win.mReportDestroySurface = false; |
| 2793 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2794 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2795 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2796 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2797 | // For some reason there isn't a surface. Clear the |
| 2798 | // caller's object so they see the same state. |
| 2799 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | } |
| 2801 | } catch (Exception e) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2802 | mInputMonitor.updateInputWindowsLw(); |
| 2803 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2804 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2805 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2806 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2807 | Binder.restoreCallingIdentity(origId); |
| 2808 | return 0; |
| 2809 | } |
| 2810 | if (displayed) { |
| 2811 | focusMayChange = true; |
| 2812 | } |
| 2813 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2814 | && mInputMethodWindow == null) { |
| 2815 | mInputMethodWindow = win; |
| 2816 | imMayMove = true; |
| 2817 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2818 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2819 | && win.mAppToken != null |
| 2820 | && win.mAppToken.startingWindow != null) { |
| 2821 | // Special handling of starting window over the base |
| 2822 | // window of the app: propagate lock screen flags to it, |
| 2823 | // to provide the correct semantics while starting. |
| 2824 | final int mask = |
| 2825 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2826 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2827 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2828 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2829 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2830 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2831 | } else { |
| 2832 | win.mEnterAnimationPending = false; |
| 2833 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2834 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2835 | + ": mExiting=" + win.mExiting |
| 2836 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | // If we are not currently running the exit animation, we |
| 2838 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2839 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | // Try starting an animation; if there isn't one, we |
| 2841 | // can destroy the surface right away. |
| 2842 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2843 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2844 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2845 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2846 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2847 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2848 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2849 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | } else if (win.isAnimating()) { |
| 2851 | // Currently in a hide animation... turn this into |
| 2852 | // an exit. |
| 2853 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2854 | } else if (win == mWallpaperTarget) { |
| 2855 | // If the wallpaper is currently behind this |
| 2856 | // window, we need to change both of them inside |
| 2857 | // of a transaction to avoid artifacts. |
| 2858 | win.mExiting = true; |
| 2859 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | } else { |
| 2861 | if (mInputMethodWindow == win) { |
| 2862 | mInputMethodWindow = null; |
| 2863 | } |
| 2864 | win.destroySurfaceLocked(); |
| 2865 | } |
| 2866 | } |
| 2867 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2868 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2869 | if (win.mSurface == null || (win.getAttrs().flags |
| 2870 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2871 | || win.mSurfacePendingDestroy) { |
| 2872 | // We are being called from a local process, which |
| 2873 | // means outSurface holds its current surface. Ensure the |
| 2874 | // surface object is cleared, but we don't want it actually |
| 2875 | // destroyed at this point. |
| 2876 | win.mSurfacePendingDestroy = false; |
| 2877 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2878 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2879 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2880 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2881 | "Keeping surface, will report destroy: " + win); |
| 2882 | win.mReportDestroySurface = true; |
| 2883 | outSurface.copyFrom(win.mSurface); |
| 2884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2885 | } |
| 2886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | if (focusMayChange) { |
| 2888 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2889 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | imMayMove = false; |
| 2891 | } |
| 2892 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2893 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2894 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2895 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2896 | // reassign them at this point if the IM window state gets shuffled |
| 2897 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2900 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2901 | // Little hack here -- we -should- be able to rely on the |
| 2902 | // function to return true if the IME has moved and needs |
| 2903 | // its layer recomputed. However, if the IME was hidden |
| 2904 | // and isn't actually moved in the list, its layer may be |
| 2905 | // 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] | 2906 | assignLayers = true; |
| 2907 | } |
| 2908 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2909 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2910 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2911 | assignLayers = true; |
| 2912 | } |
| 2913 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | mLayoutNeeded = true; |
| 2916 | win.mGivenInsetsPending = insetsPending; |
| 2917 | if (assignLayers) { |
| 2918 | assignLayersLocked(); |
| 2919 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2920 | configChanged = updateOrientationFromAppTokensLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2922 | if (displayed && win.mIsWallpaper) { |
| 2923 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2924 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2925 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2926 | if (win.mAppToken != null) { |
| 2927 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2928 | } |
| 2929 | outFrame.set(win.mFrame); |
| 2930 | outContentInsets.set(win.mContentInsets); |
| 2931 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2932 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2934 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | + ", requestedHeight=" + requestedHeight |
| 2936 | + ", viewVisibility=" + viewVisibility |
| 2937 | + "\nRelayout returning frame=" + outFrame |
| 2938 | + ", surface=" + outSurface); |
| 2939 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2940 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2941 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2942 | |
| 2943 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2944 | |
| 2945 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2946 | } |
| 2947 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2948 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | sendNewConfiguration(); |
| 2950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2954 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2955 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2956 | } |
| 2957 | |
| 2958 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2959 | final long origId = Binder.clearCallingIdentity(); |
| 2960 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2961 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2963 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2964 | adjustWallpaperWindowsLocked(); |
| 2965 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | mLayoutNeeded = true; |
| 2967 | performLayoutAndPlaceSurfacesLocked(); |
| 2968 | } |
| 2969 | } |
| 2970 | Binder.restoreCallingIdentity(origId); |
| 2971 | } |
| 2972 | |
| 2973 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2974 | 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] | 2975 | + (lp != null ? lp.packageName : null) |
| 2976 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2977 | if (lp != null && lp.windowAnimations != 0) { |
| 2978 | // If this is a system resource, don't try to load it from the |
| 2979 | // application resources. It is nice to avoid loading application |
| 2980 | // resources if we can. |
| 2981 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2982 | int resId = lp.windowAnimations; |
| 2983 | if ((resId&0xFF000000) == 0x01000000) { |
| 2984 | packageName = "android"; |
| 2985 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2986 | 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] | 2987 | + packageName); |
| 2988 | return AttributeCache.instance().get(packageName, resId, |
| 2989 | com.android.internal.R.styleable.WindowAnimation); |
| 2990 | } |
| 2991 | return null; |
| 2992 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2993 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2994 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2995 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2996 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2997 | if (packageName != null) { |
| 2998 | if ((resId&0xFF000000) == 0x01000000) { |
| 2999 | packageName = "android"; |
| 3000 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3001 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3002 | + packageName); |
| 3003 | return AttributeCache.instance().get(packageName, resId, |
| 3004 | com.android.internal.R.styleable.WindowAnimation); |
| 3005 | } |
| 3006 | return null; |
| 3007 | } |
| 3008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | private void applyEnterAnimationLocked(WindowState win) { |
| 3010 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 3011 | if (win.mEnterAnimationPending) { |
| 3012 | win.mEnterAnimationPending = false; |
| 3013 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 3014 | } |
| 3015 | |
| 3016 | applyAnimationLocked(win, transit, true); |
| 3017 | } |
| 3018 | |
| 3019 | private boolean applyAnimationLocked(WindowState win, |
| 3020 | int transit, boolean isEntrance) { |
| 3021 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 3022 | // If we are trying to apply an animation, but already running |
| 3023 | // an animation of the same type, then just leave that one alone. |
| 3024 | return true; |
| 3025 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | // Only apply an animation if the display isn't frozen. If it is |
| 3028 | // frozen, there is no reason to animate and it can cause strange |
| 3029 | // artifacts when we unfreeze the display if some different animation |
| 3030 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3031 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3032 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 3033 | int attr = -1; |
| 3034 | Animation a = null; |
| 3035 | if (anim != 0) { |
| 3036 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 3037 | } else { |
| 3038 | switch (transit) { |
| 3039 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 3040 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 3041 | break; |
| 3042 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 3043 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 3044 | break; |
| 3045 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3046 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3047 | break; |
| 3048 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3049 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3050 | break; |
| 3051 | } |
| 3052 | if (attr >= 0) { |
| 3053 | a = loadAnimation(win.mAttrs, attr); |
| 3054 | } |
| 3055 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3056 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3058 | + " mAnimation=" + win.mAnimation |
| 3059 | + " isEntrance=" + isEntrance); |
| 3060 | if (a != null) { |
| 3061 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3062 | RuntimeException e = null; |
| 3063 | if (!HIDE_STACK_CRAWLS) { |
| 3064 | e = new RuntimeException(); |
| 3065 | e.fillInStackTrace(); |
| 3066 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3067 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3068 | } |
| 3069 | win.setAnimation(a); |
| 3070 | win.mAnimationIsEntrance = isEntrance; |
| 3071 | } |
| 3072 | } else { |
| 3073 | win.clearAnimation(); |
| 3074 | } |
| 3075 | |
| 3076 | return win.mAnimation != null; |
| 3077 | } |
| 3078 | |
| 3079 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3080 | int anim = 0; |
| 3081 | Context context = mContext; |
| 3082 | if (animAttr >= 0) { |
| 3083 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3084 | if (ent != null) { |
| 3085 | context = ent.context; |
| 3086 | anim = ent.array.getResourceId(animAttr, 0); |
| 3087 | } |
| 3088 | } |
| 3089 | if (anim != 0) { |
| 3090 | return AnimationUtils.loadAnimation(context, anim); |
| 3091 | } |
| 3092 | return null; |
| 3093 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3094 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3095 | private Animation loadAnimation(String packageName, int resId) { |
| 3096 | int anim = 0; |
| 3097 | Context context = mContext; |
| 3098 | if (resId >= 0) { |
| 3099 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3100 | if (ent != null) { |
| 3101 | context = ent.context; |
| 3102 | anim = resId; |
| 3103 | } |
| 3104 | } |
| 3105 | if (anim != 0) { |
| 3106 | return AnimationUtils.loadAnimation(context, anim); |
| 3107 | } |
| 3108 | return null; |
| 3109 | } |
| 3110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3111 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3112 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3113 | // Only apply an animation if the display isn't frozen. If it is |
| 3114 | // frozen, there is no reason to animate and it can cause strange |
| 3115 | // artifacts when we unfreeze the display if some different animation |
| 3116 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3117 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3118 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3119 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3120 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3121 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3122 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3123 | } else if (mNextAppTransitionPackage != null) { |
| 3124 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3125 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3126 | } else { |
| 3127 | int animAttr = 0; |
| 3128 | switch (transit) { |
| 3129 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3130 | animAttr = enter |
| 3131 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3132 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3133 | break; |
| 3134 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3135 | animAttr = enter |
| 3136 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3137 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3138 | break; |
| 3139 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3140 | animAttr = enter |
| 3141 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3142 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3143 | break; |
| 3144 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3145 | animAttr = enter |
| 3146 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3147 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3148 | break; |
| 3149 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3150 | animAttr = enter |
| 3151 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3152 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3153 | break; |
| 3154 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3155 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3156 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3157 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3158 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3159 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3160 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3161 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3162 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3163 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3164 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3165 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3166 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3167 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3168 | break; |
| 3169 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3170 | animAttr = enter |
| 3171 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3172 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3173 | break; |
| 3174 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3175 | animAttr = enter |
| 3176 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3177 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3178 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3179 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3180 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3181 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3182 | + " anim=" + a |
| 3183 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3184 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | if (a != null) { |
| 3187 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3188 | RuntimeException e = null; |
| 3189 | if (!HIDE_STACK_CRAWLS) { |
| 3190 | e = new RuntimeException(); |
| 3191 | e.fillInStackTrace(); |
| 3192 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3193 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | } |
| 3195 | wtoken.setAnimation(a); |
| 3196 | } |
| 3197 | } else { |
| 3198 | wtoken.clearAnimation(); |
| 3199 | } |
| 3200 | |
| 3201 | return wtoken.animation != null; |
| 3202 | } |
| 3203 | |
| 3204 | // ------------------------------------------------------------- |
| 3205 | // Application Window Tokens |
| 3206 | // ------------------------------------------------------------- |
| 3207 | |
| 3208 | public void validateAppTokens(List tokens) { |
| 3209 | int v = tokens.size()-1; |
| 3210 | int m = mAppTokens.size()-1; |
| 3211 | while (v >= 0 && m >= 0) { |
| 3212 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3213 | if (wtoken.removed) { |
| 3214 | m--; |
| 3215 | continue; |
| 3216 | } |
| 3217 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3218 | 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] | 3219 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3220 | } |
| 3221 | v--; |
| 3222 | m--; |
| 3223 | } |
| 3224 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3225 | 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] | 3226 | v--; |
| 3227 | } |
| 3228 | while (m >= 0) { |
| 3229 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3230 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3231 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | } |
| 3233 | m--; |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | boolean checkCallingPermission(String permission, String func) { |
| 3238 | // Quick check: if the calling permission is me, it's all okay. |
| 3239 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3240 | return true; |
| 3241 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | if (mContext.checkCallingPermission(permission) |
| 3244 | == PackageManager.PERMISSION_GRANTED) { |
| 3245 | return true; |
| 3246 | } |
| 3247 | String msg = "Permission Denial: " + func + " from pid=" |
| 3248 | + Binder.getCallingPid() |
| 3249 | + ", uid=" + Binder.getCallingUid() |
| 3250 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3251 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | return false; |
| 3253 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3255 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3256 | WindowToken wtoken = mTokenMap.get(token); |
| 3257 | if (wtoken == null) { |
| 3258 | return null; |
| 3259 | } |
| 3260 | return wtoken.appWindowToken; |
| 3261 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | public void addWindowToken(IBinder token, int type) { |
| 3264 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3265 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3266 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | synchronized(mWindowMap) { |
| 3270 | WindowToken wtoken = mTokenMap.get(token); |
| 3271 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3272 | 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] | 3273 | return; |
| 3274 | } |
| 3275 | wtoken = new WindowToken(token, type, true); |
| 3276 | mTokenMap.put(token, wtoken); |
| 3277 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3278 | if (type == TYPE_WALLPAPER) { |
| 3279 | mWallpaperTokens.add(wtoken); |
| 3280 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | } |
| 3282 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | public void removeWindowToken(IBinder token) { |
| 3285 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3286 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3287 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | final long origId = Binder.clearCallingIdentity(); |
| 3291 | synchronized(mWindowMap) { |
| 3292 | WindowToken wtoken = mTokenMap.remove(token); |
| 3293 | mTokenList.remove(wtoken); |
| 3294 | if (wtoken != null) { |
| 3295 | boolean delayed = false; |
| 3296 | if (!wtoken.hidden) { |
| 3297 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3299 | final int N = wtoken.windows.size(); |
| 3300 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3302 | for (int i=0; i<N; i++) { |
| 3303 | WindowState win = wtoken.windows.get(i); |
| 3304 | |
| 3305 | if (win.isAnimating()) { |
| 3306 | delayed = true; |
| 3307 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3309 | if (win.isVisibleNow()) { |
| 3310 | applyAnimationLocked(win, |
| 3311 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | changed = true; |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | if (changed) { |
| 3317 | mLayoutNeeded = true; |
| 3318 | performLayoutAndPlaceSurfacesLocked(); |
| 3319 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3320 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | if (delayed) { |
| 3323 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3324 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3325 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | } |
| 3327 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3328 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3329 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3330 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3331 | 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] | 3332 | } |
| 3333 | } |
| 3334 | Binder.restoreCallingIdentity(origId); |
| 3335 | } |
| 3336 | |
| 3337 | public void addAppToken(int addPos, IApplicationToken token, |
| 3338 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3339 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3340 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3341 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3343 | |
| 3344 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3345 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3346 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3347 | // here we would run the chance of introducing a deadlock between the window manager |
| 3348 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3349 | // (which holds locks while querying the application token). |
| 3350 | long inputDispatchingTimeoutNanos; |
| 3351 | try { |
| 3352 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3353 | } catch (RemoteException ex) { |
| 3354 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3355 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3358 | synchronized(mWindowMap) { |
| 3359 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3360 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3361 | 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] | 3362 | return; |
| 3363 | } |
| 3364 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3365 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3366 | wtoken.groupId = groupId; |
| 3367 | wtoken.appFullscreen = fullscreen; |
| 3368 | wtoken.requestedOrientation = requestedOrientation; |
| 3369 | mAppTokens.add(addPos, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3370 | 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] | 3371 | mTokenMap.put(token.asBinder(), wtoken); |
| 3372 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | // Application tokens start out hidden. |
| 3375 | wtoken.hidden = true; |
| 3376 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | //dump(); |
| 3379 | } |
| 3380 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3382 | public void setAppGroupId(IBinder token, int groupId) { |
| 3383 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3384 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3385 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | synchronized(mWindowMap) { |
| 3389 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3390 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3391 | 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] | 3392 | return; |
| 3393 | } |
| 3394 | wtoken.groupId = groupId; |
| 3395 | } |
| 3396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3398 | public int getOrientationFromWindowsLocked() { |
| 3399 | int pos = mWindows.size() - 1; |
| 3400 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3401 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3402 | pos--; |
| 3403 | if (wtoken.mAppToken != null) { |
| 3404 | // We hit an application window. so the orientation will be determined by the |
| 3405 | // app window. No point in continuing further. |
| 3406 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3407 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3408 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | continue; |
| 3410 | } |
| 3411 | int req = wtoken.mAttrs.screenOrientation; |
| 3412 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3413 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3414 | continue; |
| 3415 | } else { |
| 3416 | return req; |
| 3417 | } |
| 3418 | } |
| 3419 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3420 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3423 | int pos = mAppTokens.size() - 1; |
| 3424 | int curGroup = 0; |
| 3425 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3426 | boolean findingBehind = false; |
| 3427 | boolean haveGroup = false; |
| 3428 | boolean lastFullscreen = false; |
| 3429 | while (pos >= 0) { |
| 3430 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3431 | pos--; |
| 3432 | // if we're about to tear down this window and not seek for |
| 3433 | // the behind activity, don't use it for orientation |
| 3434 | if (!findingBehind |
| 3435 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3436 | continue; |
| 3437 | } |
| 3438 | |
| 3439 | if (!haveGroup) { |
| 3440 | // We ignore any hidden applications on the top. |
| 3441 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3442 | continue; |
| 3443 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3444 | haveGroup = true; |
| 3445 | curGroup = wtoken.groupId; |
| 3446 | lastOrientation = wtoken.requestedOrientation; |
| 3447 | } else if (curGroup != wtoken.groupId) { |
| 3448 | // If we have hit a new application group, and the bottom |
| 3449 | // of the previous group didn't explicitly say to use |
| 3450 | // the orientation behind it, and the last app was |
| 3451 | // full screen, then we'll stick with the |
| 3452 | // user's orientation. |
| 3453 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3454 | && lastFullscreen) { |
| 3455 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3456 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3457 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3458 | int or = wtoken.requestedOrientation; |
| 3459 | // If this application is fullscreen, and didn't explicitly say |
| 3460 | // to use the orientation behind it, then just take whatever |
| 3461 | // orientation it has and ignores whatever is under it. |
| 3462 | lastFullscreen = wtoken.appFullscreen; |
| 3463 | if (lastFullscreen |
| 3464 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3465 | return or; |
| 3466 | } |
| 3467 | // If this application has requested an explicit orientation, |
| 3468 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3469 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3470 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3471 | return or; |
| 3472 | } |
| 3473 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3474 | } |
| 3475 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3479 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3480 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3481 | "updateOrientationFromAppTokens()")) { |
| 3482 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3483 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3484 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3485 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3486 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3487 | |
| 3488 | synchronized(mWindowMap) { |
| 3489 | if (updateOrientationFromAppTokensLocked()) { |
| 3490 | if (freezeThisOneIfNeeded != null) { |
| 3491 | AppWindowToken wtoken = findAppWindowToken( |
| 3492 | freezeThisOneIfNeeded); |
| 3493 | if (wtoken != null) { |
| 3494 | startAppFreezingScreenLocked(wtoken, |
| 3495 | ActivityInfo.CONFIG_ORIENTATION); |
| 3496 | } |
| 3497 | } |
| 3498 | config = computeNewConfigurationLocked(); |
| 3499 | |
| 3500 | } else if (currentConfig != null) { |
| 3501 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3502 | // state mismatches the activity manager's, update it, |
| 3503 | // disregarding font scale, which should remain set to |
| 3504 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3505 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3506 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3507 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3508 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3509 | mWaitingForConfig = true; |
| 3510 | mLayoutNeeded = true; |
| 3511 | startFreezingDisplayLocked(); |
| 3512 | config = new Configuration(mTempConfiguration); |
| 3513 | } |
| 3514 | } |
| 3515 | } |
| 3516 | } |
| 3517 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3518 | Binder.restoreCallingIdentity(ident); |
| 3519 | return config; |
| 3520 | } |
| 3521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3522 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3523 | * Determine the new desired orientation of the display, returning |
| 3524 | * a non-null new Configuration if it has changed from the current |
| 3525 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3526 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3527 | * SCREEN. This will typically be done for you if you call |
| 3528 | * sendNewConfiguration(). |
| 3529 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | * The orientation is computed from non-application windows first. If none of |
| 3531 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3532 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3534 | * android.os.IBinder) |
| 3535 | */ |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3536 | boolean updateOrientationFromAppTokensLocked() { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3537 | if (mDisplayFrozen) { |
| 3538 | // If the display is frozen, some activities may be in the middle |
| 3539 | // of restarting, and thus have removed their old window. If the |
| 3540 | // window has the flag to hide the lock screen, then the lock screen |
| 3541 | // can re-appear and inflict its own orientation on us. Keep the |
| 3542 | // orientation stable until this all settles down. |
| 3543 | return false; |
| 3544 | } |
| 3545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | long ident = Binder.clearCallingIdentity(); |
| 3548 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3549 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3551 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3552 | mForcedAppOrientation = req; |
| 3553 | //send a message to Policy indicating orientation change to take |
| 3554 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3555 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3556 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3557 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3558 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | } |
| 3560 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3561 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3562 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3563 | } finally { |
| 3564 | Binder.restoreCallingIdentity(ident); |
| 3565 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3567 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3568 | int computeForcedAppOrientationLocked() { |
| 3569 | int req = getOrientationFromWindowsLocked(); |
| 3570 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3571 | req = getOrientationFromAppTokensLocked(); |
| 3572 | } |
| 3573 | return req; |
| 3574 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3575 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3576 | public void setNewConfiguration(Configuration config) { |
| 3577 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3578 | "setNewConfiguration()")) { |
| 3579 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3580 | } |
| 3581 | |
| 3582 | synchronized(mWindowMap) { |
| 3583 | mCurConfiguration = new Configuration(config); |
| 3584 | mWaitingForConfig = false; |
| 3585 | performLayoutAndPlaceSurfacesLocked(); |
| 3586 | } |
| 3587 | } |
| 3588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3589 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3590 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3591 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3592 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3593 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3595 | synchronized(mWindowMap) { |
| 3596 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3597 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3598 | 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] | 3599 | return; |
| 3600 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | wtoken.requestedOrientation = requestedOrientation; |
| 3603 | } |
| 3604 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | public int getAppOrientation(IApplicationToken token) { |
| 3607 | synchronized(mWindowMap) { |
| 3608 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3609 | if (wtoken == null) { |
| 3610 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3611 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | return wtoken.requestedOrientation; |
| 3614 | } |
| 3615 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3618 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3619 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3620 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | synchronized(mWindowMap) { |
| 3624 | boolean changed = false; |
| 3625 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3626 | 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] | 3627 | changed = mFocusedApp != null; |
| 3628 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3629 | if (changed) { |
| 3630 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3631 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | } else { |
| 3633 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3634 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3635 | 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] | 3636 | return; |
| 3637 | } |
| 3638 | changed = mFocusedApp != newFocus; |
| 3639 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3640 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3641 | if (changed) { |
| 3642 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3643 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | if (moveFocusNow && changed) { |
| 3647 | final long origId = Binder.clearCallingIdentity(); |
| 3648 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3649 | Binder.restoreCallingIdentity(origId); |
| 3650 | } |
| 3651 | } |
| 3652 | } |
| 3653 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3654 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3655 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3656 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3657 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3661 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | TAG, "Prepare app transition: transit=" + transit |
| 3663 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3664 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3665 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3666 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3668 | } else if (!alwaysKeepCurrent) { |
| 3669 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3670 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3671 | // Opening a new task always supersedes a close for the anim. |
| 3672 | mNextAppTransition = transit; |
| 3673 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3674 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3675 | // Opening a new activity always supersedes a close for the anim. |
| 3676 | mNextAppTransition = transit; |
| 3677 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3678 | } |
| 3679 | mAppTransitionReady = false; |
| 3680 | mAppTransitionTimeout = false; |
| 3681 | mStartingIconInTransition = false; |
| 3682 | mSkipAppTransitionAnimation = false; |
| 3683 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3684 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3685 | 5000); |
| 3686 | } |
| 3687 | } |
| 3688 | } |
| 3689 | |
| 3690 | public int getPendingAppTransition() { |
| 3691 | return mNextAppTransition; |
| 3692 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3693 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3694 | public void overridePendingAppTransition(String packageName, |
| 3695 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3696 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3697 | mNextAppTransitionPackage = packageName; |
| 3698 | mNextAppTransitionEnter = enterAnim; |
| 3699 | mNextAppTransitionExit = exitAnim; |
| 3700 | } |
| 3701 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3703 | public void executeAppTransition() { |
| 3704 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3705 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3706 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3710 | if (DEBUG_APP_TRANSITIONS) { |
| 3711 | RuntimeException e = new RuntimeException("here"); |
| 3712 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3713 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3714 | + mNextAppTransition, e); |
| 3715 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3716 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | mAppTransitionReady = true; |
| 3718 | final long origId = Binder.clearCallingIdentity(); |
| 3719 | performLayoutAndPlaceSurfacesLocked(); |
| 3720 | Binder.restoreCallingIdentity(origId); |
| 3721 | } |
| 3722 | } |
| 3723 | } |
| 3724 | |
| 3725 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3726 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3727 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3729 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3730 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3734 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3736 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3738 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3739 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3740 | 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] | 3741 | return; |
| 3742 | } |
| 3743 | |
| 3744 | // If the display is frozen, we won't do anything until the |
| 3745 | // actual window is displayed so there is no reason to put in |
| 3746 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3747 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | return; |
| 3749 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3751 | if (wtoken.startingData != null) { |
| 3752 | return; |
| 3753 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | if (transferFrom != null) { |
| 3756 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3757 | if (ttoken != null) { |
| 3758 | WindowState startingWindow = ttoken.startingWindow; |
| 3759 | if (startingWindow != null) { |
| 3760 | if (mStartingIconInTransition) { |
| 3761 | // In this case, the starting icon has already |
| 3762 | // been displayed, so start letting windows get |
| 3763 | // shown immediately without any more transitions. |
| 3764 | mSkipAppTransitionAnimation = true; |
| 3765 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3766 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | "Moving existing starting from " + ttoken |
| 3768 | + " to " + wtoken); |
| 3769 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3771 | // Transfer the starting window over to the new |
| 3772 | // token. |
| 3773 | wtoken.startingData = ttoken.startingData; |
| 3774 | wtoken.startingView = ttoken.startingView; |
| 3775 | wtoken.startingWindow = startingWindow; |
| 3776 | ttoken.startingData = null; |
| 3777 | ttoken.startingView = null; |
| 3778 | ttoken.startingWindow = null; |
| 3779 | ttoken.startingMoved = true; |
| 3780 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3781 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | startingWindow.mAppToken = wtoken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3783 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3784 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3785 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3786 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | ttoken.windows.remove(startingWindow); |
| 3788 | ttoken.allAppWindows.remove(startingWindow); |
| 3789 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3791 | // Propagate other interesting state between the |
| 3792 | // tokens. If the old token is displayed, we should |
| 3793 | // immediately force the new one to be displayed. If |
| 3794 | // it is animating, we need to move that animation to |
| 3795 | // the new one. |
| 3796 | if (ttoken.allDrawn) { |
| 3797 | wtoken.allDrawn = true; |
| 3798 | } |
| 3799 | if (ttoken.firstWindowDrawn) { |
| 3800 | wtoken.firstWindowDrawn = true; |
| 3801 | } |
| 3802 | if (!ttoken.hidden) { |
| 3803 | wtoken.hidden = false; |
| 3804 | wtoken.hiddenRequested = false; |
| 3805 | wtoken.willBeHidden = false; |
| 3806 | } |
| 3807 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3808 | wtoken.clientHidden = ttoken.clientHidden; |
| 3809 | wtoken.sendAppVisibilityToClients(); |
| 3810 | } |
| 3811 | if (ttoken.animation != null) { |
| 3812 | wtoken.animation = ttoken.animation; |
| 3813 | wtoken.animating = ttoken.animating; |
| 3814 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3815 | ttoken.animation = null; |
| 3816 | ttoken.animLayerAdjustment = 0; |
| 3817 | wtoken.updateLayers(); |
| 3818 | ttoken.updateLayers(); |
| 3819 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3820 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3822 | mLayoutNeeded = true; |
| 3823 | performLayoutAndPlaceSurfacesLocked(); |
| 3824 | Binder.restoreCallingIdentity(origId); |
| 3825 | return; |
| 3826 | } else if (ttoken.startingData != null) { |
| 3827 | // The previous app was getting ready to show a |
| 3828 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3829 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | "Moving pending starting from " + ttoken |
| 3831 | + " to " + wtoken); |
| 3832 | wtoken.startingData = ttoken.startingData; |
| 3833 | ttoken.startingData = null; |
| 3834 | ttoken.startingMoved = true; |
| 3835 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3836 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3837 | // want to process the message ASAP, before any other queued |
| 3838 | // messages. |
| 3839 | mH.sendMessageAtFrontOfQueue(m); |
| 3840 | return; |
| 3841 | } |
| 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | // There is no existing starting window, and the caller doesn't |
| 3846 | // want us to create one, so that's it! |
| 3847 | if (!createIfNeeded) { |
| 3848 | return; |
| 3849 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3850 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3851 | // If this is a translucent or wallpaper window, then don't |
| 3852 | // show a starting window -- the current effect (a full-screen |
| 3853 | // opaque starting window that fades away to the real contents |
| 3854 | // when it is ready) does not work for this. |
| 3855 | if (theme != 0) { |
| 3856 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3857 | com.android.internal.R.styleable.Window); |
| 3858 | if (ent.array.getBoolean( |
| 3859 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3860 | return; |
| 3861 | } |
| 3862 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3863 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3864 | return; |
| 3865 | } |
| 3866 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3867 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3868 | return; |
| 3869 | } |
| 3870 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | mStartingIconInTransition = true; |
| 3873 | wtoken.startingData = new StartingData( |
| 3874 | pkg, theme, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3875 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3876 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3877 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3878 | // want to process the message ASAP, before any other queued |
| 3879 | // messages. |
| 3880 | mH.sendMessageAtFrontOfQueue(m); |
| 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | public void setAppWillBeHidden(IBinder token) { |
| 3885 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3886 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3887 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | AppWindowToken wtoken; |
| 3891 | |
| 3892 | synchronized(mWindowMap) { |
| 3893 | wtoken = findAppWindowToken(token); |
| 3894 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3895 | 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] | 3896 | return; |
| 3897 | } |
| 3898 | wtoken.willBeHidden = true; |
| 3899 | } |
| 3900 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3903 | boolean visible, int transit, boolean performLayout) { |
| 3904 | boolean delayed = false; |
| 3905 | |
| 3906 | if (wtoken.clientHidden == visible) { |
| 3907 | wtoken.clientHidden = !visible; |
| 3908 | wtoken.sendAppVisibilityToClients(); |
| 3909 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3911 | wtoken.willBeHidden = false; |
| 3912 | if (wtoken.hidden == visible) { |
| 3913 | final int N = wtoken.allAppWindows.size(); |
| 3914 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3915 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3917 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3919 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3920 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3921 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | if (wtoken.animation == sDummyAnimation) { |
| 3923 | wtoken.animation = null; |
| 3924 | } |
| 3925 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3926 | changed = true; |
| 3927 | if (wtoken.animation != null) { |
| 3928 | delayed = runningAppAnimation = true; |
| 3929 | } |
| 3930 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | for (int i=0; i<N; i++) { |
| 3933 | WindowState win = wtoken.allAppWindows.get(i); |
| 3934 | if (win == wtoken.startingWindow) { |
| 3935 | continue; |
| 3936 | } |
| 3937 | |
| 3938 | if (win.isAnimating()) { |
| 3939 | delayed = true; |
| 3940 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3941 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3942 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3943 | //win.dump(" "); |
| 3944 | if (visible) { |
| 3945 | if (!win.isVisibleNow()) { |
| 3946 | if (!runningAppAnimation) { |
| 3947 | applyAnimationLocked(win, |
| 3948 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3949 | } |
| 3950 | changed = true; |
| 3951 | } |
| 3952 | } else if (win.isVisibleNow()) { |
| 3953 | if (!runningAppAnimation) { |
| 3954 | applyAnimationLocked(win, |
| 3955 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3956 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | changed = true; |
| 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3962 | if (!visible) { |
| 3963 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3964 | } else { |
| 3965 | // If we are being set visible, and the starting window is |
| 3966 | // not yet displayed, then make sure it doesn't get displayed. |
| 3967 | WindowState swin = wtoken.startingWindow; |
| 3968 | if (swin != null && (swin.mDrawPending |
| 3969 | || swin.mCommitDrawPending)) { |
| 3970 | swin.mPolicyVisibility = false; |
| 3971 | swin.mPolicyVisibilityAfterAnim = false; |
| 3972 | } |
| 3973 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3974 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3975 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3977 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3978 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3979 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | mLayoutNeeded = true; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3981 | if (performLayout) { |
| 3982 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3983 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3984 | } else { |
| 3985 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3986 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | if (wtoken.animation != null) { |
| 3991 | delayed = true; |
| 3992 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | return delayed; |
| 3995 | } |
| 3996 | |
| 3997 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3998 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3999 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4000 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | } |
| 4002 | |
| 4003 | AppWindowToken wtoken; |
| 4004 | |
| 4005 | synchronized(mWindowMap) { |
| 4006 | wtoken = findAppWindowToken(token); |
| 4007 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4008 | 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] | 4009 | return; |
| 4010 | } |
| 4011 | |
| 4012 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4013 | RuntimeException e = null; |
| 4014 | if (!HIDE_STACK_CRAWLS) { |
| 4015 | e = new RuntimeException(); |
| 4016 | e.fillInStackTrace(); |
| 4017 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4018 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4019 | + "): mNextAppTransition=" + mNextAppTransition |
| 4020 | + " hidden=" + wtoken.hidden |
| 4021 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4022 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | // If we are preparing an app transition, then delay changing |
| 4025 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4026 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 4027 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | // Already in requested state, don't do anything more. |
| 4029 | if (wtoken.hiddenRequested != visible) { |
| 4030 | return; |
| 4031 | } |
| 4032 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4033 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4034 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | TAG, "Setting dummy animation on: " + wtoken); |
| 4036 | wtoken.setDummyAnimation(); |
| 4037 | mOpeningApps.remove(wtoken); |
| 4038 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4039 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | wtoken.inPendingTransaction = true; |
| 4041 | if (visible) { |
| 4042 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | wtoken.startingDisplayed = false; |
| 4044 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4045 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4046 | // If the token is currently hidden (should be the |
| 4047 | // common case), then we need to set up to wait for |
| 4048 | // its windows to be ready. |
| 4049 | if (wtoken.hidden) { |
| 4050 | wtoken.allDrawn = false; |
| 4051 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4052 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4053 | if (wtoken.clientHidden) { |
| 4054 | // In the case where we are making an app visible |
| 4055 | // but holding off for a transition, we still need |
| 4056 | // to tell the client to make its windows visible so |
| 4057 | // they get drawn. Otherwise, we will wait on |
| 4058 | // performing the transition until all windows have |
| 4059 | // been drawn, they never will be, and we are sad. |
| 4060 | wtoken.clientHidden = false; |
| 4061 | wtoken.sendAppVisibilityToClients(); |
| 4062 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | } |
| 4064 | } else { |
| 4065 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4066 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4067 | // If the token is currently visible (should be the |
| 4068 | // common case), then set up to wait for it to be hidden. |
| 4069 | if (!wtoken.hidden) { |
| 4070 | wtoken.waitingToHide = true; |
| 4071 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | } |
| 4073 | return; |
| 4074 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4076 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4077 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | wtoken.updateReportedVisibilityLocked(); |
| 4079 | Binder.restoreCallingIdentity(origId); |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4084 | boolean unfreezeSurfaceNow, boolean force) { |
| 4085 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4086 | 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] | 4087 | + " force=" + force); |
| 4088 | final int N = wtoken.allAppWindows.size(); |
| 4089 | boolean unfrozeWindows = false; |
| 4090 | for (int i=0; i<N; i++) { |
| 4091 | WindowState w = wtoken.allAppWindows.get(i); |
| 4092 | if (w.mAppFreezing) { |
| 4093 | w.mAppFreezing = false; |
| 4094 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4095 | w.mOrientationChanging = true; |
| 4096 | } |
| 4097 | unfrozeWindows = true; |
| 4098 | } |
| 4099 | } |
| 4100 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4101 | 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] | 4102 | wtoken.freezingScreen = false; |
| 4103 | mAppsFreezingScreen--; |
| 4104 | } |
| 4105 | if (unfreezeSurfaceNow) { |
| 4106 | if (unfrozeWindows) { |
| 4107 | mLayoutNeeded = true; |
| 4108 | performLayoutAndPlaceSurfacesLocked(); |
| 4109 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4110 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4111 | } |
| 4112 | } |
| 4113 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4116 | int configChanges) { |
| 4117 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4118 | RuntimeException e = null; |
| 4119 | if (!HIDE_STACK_CRAWLS) { |
| 4120 | e = new RuntimeException(); |
| 4121 | e.fillInStackTrace(); |
| 4122 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4123 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4125 | + wtoken.freezingScreen, e); |
| 4126 | } |
| 4127 | if (!wtoken.hiddenRequested) { |
| 4128 | if (!wtoken.freezingScreen) { |
| 4129 | wtoken.freezingScreen = true; |
| 4130 | mAppsFreezingScreen++; |
| 4131 | if (mAppsFreezingScreen == 1) { |
| 4132 | startFreezingDisplayLocked(); |
| 4133 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4134 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4135 | 5000); |
| 4136 | } |
| 4137 | } |
| 4138 | final int N = wtoken.allAppWindows.size(); |
| 4139 | for (int i=0; i<N; i++) { |
| 4140 | WindowState w = wtoken.allAppWindows.get(i); |
| 4141 | w.mAppFreezing = true; |
| 4142 | } |
| 4143 | } |
| 4144 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4147 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4148 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4149 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4153 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4154 | 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] | 4155 | return; |
| 4156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4158 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4159 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4160 | 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] | 4161 | return; |
| 4162 | } |
| 4163 | final long origId = Binder.clearCallingIdentity(); |
| 4164 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4165 | Binder.restoreCallingIdentity(origId); |
| 4166 | } |
| 4167 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4170 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4171 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4172 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | synchronized(mWindowMap) { |
| 4176 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4177 | if (wtoken == null || wtoken.appToken == null) { |
| 4178 | return; |
| 4179 | } |
| 4180 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4181 | 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] | 4182 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4183 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4184 | Binder.restoreCallingIdentity(origId); |
| 4185 | } |
| 4186 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | public void removeAppToken(IBinder token) { |
| 4189 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4190 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4191 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | AppWindowToken wtoken = null; |
| 4195 | AppWindowToken startingToken = null; |
| 4196 | boolean delayed = false; |
| 4197 | |
| 4198 | final long origId = Binder.clearCallingIdentity(); |
| 4199 | synchronized(mWindowMap) { |
| 4200 | WindowToken basewtoken = mTokenMap.remove(token); |
| 4201 | mTokenList.remove(basewtoken); |
| 4202 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4203 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4204 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | wtoken.inPendingTransaction = false; |
| 4206 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4207 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4208 | if (mClosingApps.contains(wtoken)) { |
| 4209 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4210 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4212 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4213 | delayed = true; |
| 4214 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4215 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4217 | + " animation=" + wtoken.animation |
| 4218 | + " animating=" + wtoken.animating); |
| 4219 | if (delayed) { |
| 4220 | // set the token aside because it has an active animation to be finished |
| 4221 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4222 | } else { |
| 4223 | // Make sure there is no animation running on this token, |
| 4224 | // so any windows associated with it will be removed as |
| 4225 | // soon as their animations are complete |
| 4226 | wtoken.animation = null; |
| 4227 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | } |
| 4229 | mAppTokens.remove(wtoken); |
| 4230 | wtoken.removed = true; |
| 4231 | if (wtoken.startingData != null) { |
| 4232 | startingToken = wtoken; |
| 4233 | } |
| 4234 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4235 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4236 | 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] | 4237 | mFocusedApp = null; |
| 4238 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4239 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | } |
| 4241 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4242 | 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] | 4243 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4245 | if (!delayed && wtoken != null) { |
| 4246 | wtoken.updateReportedVisibilityLocked(); |
| 4247 | } |
| 4248 | } |
| 4249 | Binder.restoreCallingIdentity(origId); |
| 4250 | |
| 4251 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4252 | 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] | 4253 | + startingToken + ": app token removed"); |
| 4254 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4255 | mH.sendMessage(m); |
| 4256 | } |
| 4257 | } |
| 4258 | |
| 4259 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4260 | final int NW = token.windows.size(); |
| 4261 | for (int i=0; i<NW; i++) { |
| 4262 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4263 | 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] | 4264 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4265 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | int j = win.mChildWindows.size(); |
| 4267 | while (j > 0) { |
| 4268 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4269 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4270 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4271 | "Tmp removing child window " + cwin); |
| 4272 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4273 | } |
| 4274 | } |
| 4275 | return NW > 0; |
| 4276 | } |
| 4277 | |
| 4278 | void dumpAppTokensLocked() { |
| 4279 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4280 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | } |
| 4282 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | void dumpWindowsLocked() { |
| 4285 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4286 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | } |
| 4288 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | private int findWindowOffsetLocked(int tokenPos) { |
| 4291 | final int NW = mWindows.size(); |
| 4292 | |
| 4293 | if (tokenPos >= mAppTokens.size()) { |
| 4294 | int i = NW; |
| 4295 | while (i > 0) { |
| 4296 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4297 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | if (win.getAppToken() != null) { |
| 4299 | return i+1; |
| 4300 | } |
| 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | while (tokenPos > 0) { |
| 4305 | // Find the first app token below the new position that has |
| 4306 | // a window displayed. |
| 4307 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4308 | 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] | 4309 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4310 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4311 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4312 | "Skipping token -- currently sending to bottom"); |
| 4313 | tokenPos--; |
| 4314 | continue; |
| 4315 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4316 | int i = wtoken.windows.size(); |
| 4317 | while (i > 0) { |
| 4318 | i--; |
| 4319 | WindowState win = wtoken.windows.get(i); |
| 4320 | int j = win.mChildWindows.size(); |
| 4321 | while (j > 0) { |
| 4322 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4323 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4324 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | for (int pos=NW-1; pos>=0; pos--) { |
| 4326 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4327 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4328 | "Found child win @" + (pos+1)); |
| 4329 | return pos+1; |
| 4330 | } |
| 4331 | } |
| 4332 | } |
| 4333 | } |
| 4334 | for (int pos=NW-1; pos>=0; pos--) { |
| 4335 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4336 | 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] | 4337 | return pos+1; |
| 4338 | } |
| 4339 | } |
| 4340 | } |
| 4341 | tokenPos--; |
| 4342 | } |
| 4343 | |
| 4344 | return 0; |
| 4345 | } |
| 4346 | |
| 4347 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4348 | final int NCW = win.mChildWindows.size(); |
| 4349 | boolean added = false; |
| 4350 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4351 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4352 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4353 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4354 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | mWindows.add(index, win); |
| 4356 | index++; |
| 4357 | added = true; |
| 4358 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4359 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4360 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4361 | mWindows.add(index, cwin); |
| 4362 | index++; |
| 4363 | } |
| 4364 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4365 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4366 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | mWindows.add(index, win); |
| 4368 | index++; |
| 4369 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4370 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | return index; |
| 4372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4374 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4375 | final int NW = token.windows.size(); |
| 4376 | for (int i=0; i<NW; i++) { |
| 4377 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4378 | } |
| 4379 | return index; |
| 4380 | } |
| 4381 | |
| 4382 | public void moveAppToken(int index, IBinder token) { |
| 4383 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4384 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4385 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4389 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4391 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4392 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4393 | 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] | 4394 | + token + " (" + wtoken + ")"); |
| 4395 | return; |
| 4396 | } |
| 4397 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4398 | 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] | 4399 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4402 | 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] | 4403 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4404 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4405 | 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] | 4406 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4407 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4408 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4409 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4410 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | mLayoutNeeded = true; |
| 4412 | performLayoutAndPlaceSurfacesLocked(); |
| 4413 | } |
| 4414 | Binder.restoreCallingIdentity(origId); |
| 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4419 | // XXX This should be done more efficiently! |
| 4420 | // (take advantage of the fact that both lists should be |
| 4421 | // ordered in the same way.) |
| 4422 | int N = tokens.size(); |
| 4423 | for (int i=0; i<N; i++) { |
| 4424 | IBinder token = tokens.get(i); |
| 4425 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4426 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4427 | 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] | 4428 | + token + " (" + wtoken + ")"); |
| 4429 | i--; |
| 4430 | N--; |
| 4431 | } |
| 4432 | } |
| 4433 | } |
| 4434 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4435 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4436 | boolean updateFocusAndLayout) { |
| 4437 | // First remove all of the windows from the list. |
| 4438 | tmpRemoveAppWindowsLocked(wtoken); |
| 4439 | |
| 4440 | // Where to start adding? |
| 4441 | int pos = findWindowOffsetLocked(tokenPos); |
| 4442 | |
| 4443 | // And now add them back at the correct place. |
| 4444 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4445 | |
| 4446 | if (updateFocusAndLayout) { |
| 4447 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4448 | assignLayersLocked(); |
| 4449 | } |
| 4450 | mLayoutNeeded = true; |
| 4451 | performLayoutAndPlaceSurfacesLocked(); |
| 4452 | } |
| 4453 | } |
| 4454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4456 | // First remove all of the windows from the list. |
| 4457 | final int N = tokens.size(); |
| 4458 | int i; |
| 4459 | for (i=0; i<N; i++) { |
| 4460 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4461 | if (token != null) { |
| 4462 | tmpRemoveAppWindowsLocked(token); |
| 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | // Where to start adding? |
| 4467 | int pos = findWindowOffsetLocked(tokenPos); |
| 4468 | |
| 4469 | // And now add them back at the correct place. |
| 4470 | for (i=0; i<N; i++) { |
| 4471 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4472 | if (token != null) { |
| 4473 | pos = reAddAppWindowsLocked(pos, token); |
| 4474 | } |
| 4475 | } |
| 4476 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4477 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4478 | assignLayersLocked(); |
| 4479 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | mLayoutNeeded = true; |
| 4481 | performLayoutAndPlaceSurfacesLocked(); |
| 4482 | |
| 4483 | //dump(); |
| 4484 | } |
| 4485 | |
| 4486 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4487 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4488 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4489 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | final long origId = Binder.clearCallingIdentity(); |
| 4493 | synchronized(mWindowMap) { |
| 4494 | removeAppTokensLocked(tokens); |
| 4495 | final int N = tokens.size(); |
| 4496 | for (int i=0; i<N; i++) { |
| 4497 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4498 | if (wt != null) { |
| 4499 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4500 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4501 | mToTopApps.remove(wt); |
| 4502 | mToBottomApps.remove(wt); |
| 4503 | mToTopApps.add(wt); |
| 4504 | wt.sendingToBottom = false; |
| 4505 | wt.sendingToTop = true; |
| 4506 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | } |
| 4508 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4509 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4510 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4511 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4512 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | } |
| 4514 | Binder.restoreCallingIdentity(origId); |
| 4515 | } |
| 4516 | |
| 4517 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4518 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4519 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4520 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | final long origId = Binder.clearCallingIdentity(); |
| 4524 | synchronized(mWindowMap) { |
| 4525 | removeAppTokensLocked(tokens); |
| 4526 | final int N = tokens.size(); |
| 4527 | int pos = 0; |
| 4528 | for (int i=0; i<N; i++) { |
| 4529 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4530 | if (wt != null) { |
| 4531 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4532 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4533 | mToTopApps.remove(wt); |
| 4534 | mToBottomApps.remove(wt); |
| 4535 | mToBottomApps.add(i, wt); |
| 4536 | wt.sendingToTop = false; |
| 4537 | wt.sendingToBottom = true; |
| 4538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4539 | pos++; |
| 4540 | } |
| 4541 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4542 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4543 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4544 | moveAppWindowsLocked(tokens, 0); |
| 4545 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4546 | } |
| 4547 | Binder.restoreCallingIdentity(origId); |
| 4548 | } |
| 4549 | |
| 4550 | // ------------------------------------------------------------- |
| 4551 | // Misc IWindowSession methods |
| 4552 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4553 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4554 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4555 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4556 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4557 | // called before DevicePolicyManagerService has started. |
| 4558 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4559 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4560 | Context.DEVICE_POLICY_SERVICE); |
| 4561 | if (dpm != null) { |
| 4562 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4563 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4564 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4565 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4566 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4567 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4568 | } |
| 4569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4570 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4571 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4572 | != PackageManager.PERMISSION_GRANTED) { |
| 4573 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4574 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4575 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4576 | synchronized (mKeyguardTokenWatcher) { |
| 4577 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4578 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4582 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4583 | != PackageManager.PERMISSION_GRANTED) { |
| 4584 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4587 | synchronized (mKeyguardTokenWatcher) { |
| 4588 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4589 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4590 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4591 | // If we are the last one to reenable the keyguard wait until |
| 4592 | // we have actually finished reenabling until returning. |
| 4593 | // It is possible that reenableKeyguard() can be called before |
| 4594 | // the previous disableKeyguard() is handled, in which case |
| 4595 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4596 | // be called. In that case mKeyguardDisabled will be false here |
| 4597 | // and we have nothing to wait for. |
| 4598 | while (mKeyguardDisabled) { |
| 4599 | try { |
| 4600 | mKeyguardTokenWatcher.wait(); |
| 4601 | } catch (InterruptedException e) { |
| 4602 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4603 | } |
| 4604 | } |
| 4605 | } |
| 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | /** |
| 4610 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4611 | */ |
| 4612 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4613 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | != PackageManager.PERMISSION_GRANTED) { |
| 4615 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4616 | } |
| 4617 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4618 | public void onKeyguardExitResult(boolean success) { |
| 4619 | try { |
| 4620 | callback.onKeyguardExitResult(success); |
| 4621 | } catch (RemoteException e) { |
| 4622 | // Client has died, we don't care. |
| 4623 | } |
| 4624 | } |
| 4625 | }); |
| 4626 | } |
| 4627 | |
| 4628 | public boolean inKeyguardRestrictedInputMode() { |
| 4629 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4630 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4631 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4632 | public void closeSystemDialogs(String reason) { |
| 4633 | synchronized(mWindowMap) { |
| 4634 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4635 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4636 | if (w.mSurface != null) { |
| 4637 | try { |
| 4638 | w.mClient.closeSystemDialogs(reason); |
| 4639 | } catch (RemoteException e) { |
| 4640 | } |
| 4641 | } |
| 4642 | } |
| 4643 | } |
| 4644 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | static float fixScale(float scale) { |
| 4647 | if (scale < 0) scale = 0; |
| 4648 | else if (scale > 20) scale = 20; |
| 4649 | return Math.abs(scale); |
| 4650 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4652 | public void setAnimationScale(int which, float scale) { |
| 4653 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4654 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4655 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | if (scale < 0) scale = 0; |
| 4659 | else if (scale > 20) scale = 20; |
| 4660 | scale = Math.abs(scale); |
| 4661 | switch (which) { |
| 4662 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4663 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4664 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | // Persist setting |
| 4667 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4668 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | public void setAnimationScales(float[] scales) { |
| 4671 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4672 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4673 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | if (scales != null) { |
| 4677 | if (scales.length >= 1) { |
| 4678 | mWindowAnimationScale = fixScale(scales[0]); |
| 4679 | } |
| 4680 | if (scales.length >= 2) { |
| 4681 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4682 | } |
| 4683 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | // Persist setting |
| 4686 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4687 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | public float getAnimationScale(int which) { |
| 4690 | switch (which) { |
| 4691 | case 0: return mWindowAnimationScale; |
| 4692 | case 1: return mTransitionAnimationScale; |
| 4693 | } |
| 4694 | return 0; |
| 4695 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4697 | public float[] getAnimationScales() { |
| 4698 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4699 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4701 | public int getSwitchState(int sw) { |
| 4702 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4703 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4704 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4705 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4706 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4707 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4709 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4710 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4711 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4712 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4713 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4714 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4715 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4717 | public int getScancodeState(int sw) { |
| 4718 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4719 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4720 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4721 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4722 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4725 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4726 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4727 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4728 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4729 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4730 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4732 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4733 | public int getTrackballScancodeState(int sw) { |
| 4734 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4735 | "getTrackballScancodeState()")) { |
| 4736 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4737 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4738 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | public int getDPadScancodeState(int sw) { |
| 4742 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4743 | "getDPadScancodeState()")) { |
| 4744 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4745 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4746 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4747 | } |
| 4748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4749 | public int getKeycodeState(int sw) { |
| 4750 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4751 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4752 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4753 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4754 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4755 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4757 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4758 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4759 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4760 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4761 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4762 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4763 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4764 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4765 | public int getTrackballKeycodeState(int sw) { |
| 4766 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4767 | "getTrackballKeycodeState()")) { |
| 4768 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4769 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4770 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4771 | } |
| 4772 | |
| 4773 | public int getDPadKeycodeState(int sw) { |
| 4774 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4775 | "getDPadKeycodeState()")) { |
| 4776 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4777 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4778 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4779 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4781 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4782 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4784 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4785 | public InputChannel monitorInput(String inputChannelName) { |
| 4786 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4787 | "monitorInput()")) { |
| 4788 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4789 | } |
| 4790 | return mInputManager.monitorInput(inputChannelName); |
| 4791 | } |
| 4792 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4793 | public InputDevice getInputDevice(int deviceId) { |
| 4794 | return mInputManager.getInputDevice(deviceId); |
| 4795 | } |
| 4796 | |
| 4797 | public int[] getInputDeviceIds() { |
| 4798 | return mInputManager.getInputDeviceIds(); |
| 4799 | } |
| 4800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4801 | public void enableScreenAfterBoot() { |
| 4802 | synchronized(mWindowMap) { |
| 4803 | if (mSystemBooted) { |
| 4804 | return; |
| 4805 | } |
| 4806 | mSystemBooted = true; |
| 4807 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4809 | performEnableScreen(); |
| 4810 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4812 | public void enableScreenIfNeededLocked() { |
| 4813 | if (mDisplayEnabled) { |
| 4814 | return; |
| 4815 | } |
| 4816 | if (!mSystemBooted) { |
| 4817 | return; |
| 4818 | } |
| 4819 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4820 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | public void performEnableScreen() { |
| 4823 | synchronized(mWindowMap) { |
| 4824 | if (mDisplayEnabled) { |
| 4825 | return; |
| 4826 | } |
| 4827 | if (!mSystemBooted) { |
| 4828 | return; |
| 4829 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4831 | // Don't enable the screen until all existing windows |
| 4832 | // have been drawn. |
| 4833 | final int N = mWindows.size(); |
| 4834 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4835 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4836 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4837 | return; |
| 4838 | } |
| 4839 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4841 | mDisplayEnabled = true; |
| 4842 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4843 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4844 | StringWriter sw = new StringWriter(); |
| 4845 | PrintWriter pw = new PrintWriter(sw); |
| 4846 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4847 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | } |
| 4849 | try { |
| 4850 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4851 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4852 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4853 | Parcel data = Parcel.obtain(); |
| 4854 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4855 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4856 | data, null, 0); |
| 4857 | data.recycle(); |
| 4858 | } |
| 4859 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4860 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4861 | } |
| 4862 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4864 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4866 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4867 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4868 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4869 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | public void setInTouchMode(boolean mode) { |
| 4872 | synchronized(mWindowMap) { |
| 4873 | mInTouchMode = mode; |
| 4874 | } |
| 4875 | } |
| 4876 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4877 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4878 | // only allow disables from pids which have count on, etc. |
| 4879 | public void showStrictModeViolation(boolean on) { |
| 4880 | int pid = Binder.getCallingPid(); |
| 4881 | synchronized(mWindowMap) { |
| 4882 | // Ignoring requests to enable the red border from clients |
| 4883 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 4884 | // the background..) |
| 4885 | if (on) { |
| 4886 | boolean isVisible = false; |
| 4887 | for (WindowState ws : mWindows) { |
| 4888 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 4889 | isVisible = true; |
| 4890 | break; |
| 4891 | } |
| 4892 | } |
| 4893 | if (!isVisible) { |
| 4894 | return; |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | Surface.openTransaction(); |
| 4899 | if (mStrictModeFlash == null) { |
| 4900 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 4901 | } |
| 4902 | mStrictModeFlash.setVisibility(on); |
| 4903 | Surface.closeTransaction(); |
| 4904 | } |
| 4905 | } |
| 4906 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 4907 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 4908 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 4909 | } |
| 4910 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4911 | public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4912 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 4913 | "screenshotApplications()")) { |
| 4914 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 4915 | } |
| 4916 | |
| 4917 | Bitmap rawss; |
| 4918 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4919 | int maxLayer = 0; |
| 4920 | boolean foundApp; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4921 | final Rect frame = new Rect(); |
| 4922 | |
| 4923 | float scale; |
| 4924 | int sw, sh, dw, dh; |
| 4925 | int rot; |
| 4926 | |
| 4927 | synchronized(mWindowMap) { |
| 4928 | long ident = Binder.clearCallingIdentity(); |
| 4929 | |
| 4930 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 4931 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 4932 | + TYPE_LAYER_OFFSET; |
| 4933 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 4934 | |
| 4935 | // Figure out the part of the screen that is actually the app. |
| 4936 | for (int i=0; i<mWindows.size(); i++) { |
| 4937 | WindowState ws = mWindows.get(i); |
| 4938 | if (ws.mSurface == null) { |
| 4939 | continue; |
| 4940 | } |
| 4941 | if (ws.mLayer >= aboveAppLayer) { |
| 4942 | break; |
| 4943 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4944 | if (appToken != null && (ws.mAppToken == null |
| 4945 | || ws.mAppToken.token != appToken)) { |
| 4946 | continue; |
| 4947 | } |
| 4948 | if (maxLayer < ws.mAnimLayer) { |
| 4949 | maxLayer = ws.mAnimLayer; |
| 4950 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4951 | final Rect wf = ws.mFrame; |
| 4952 | final Rect cr = ws.mContentInsets; |
| 4953 | int left = wf.left + cr.left; |
| 4954 | int top = wf.top + cr.top; |
| 4955 | int right = wf.right - cr.right; |
| 4956 | int bottom = wf.bottom - cr.bottom; |
| 4957 | frame.union(left, top, right, bottom); |
| 4958 | } |
| 4959 | Binder.restoreCallingIdentity(ident); |
| 4960 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame^] | 4961 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4962 | return null; |
| 4963 | } |
| 4964 | |
| 4965 | // The screenshot API does not apply the current screen rotation. |
| 4966 | rot = mDisplay.getRotation(); |
| 4967 | int fw = frame.width(); |
| 4968 | int fh = frame.height(); |
| 4969 | |
| 4970 | // First try reducing to fit in x dimension. |
| 4971 | scale = maxWidth/(float)fw; |
| 4972 | sw = maxWidth; |
| 4973 | sh = (int)(fh*scale); |
| 4974 | if (sh > maxHeight) { |
| 4975 | // y dimension became too long; constrain by that. |
| 4976 | scale = maxHeight/(float)fh; |
| 4977 | sw = (int)(fw*scale); |
| 4978 | sh = maxHeight; |
| 4979 | } |
| 4980 | |
| 4981 | // The screen shot will contain the entire screen. |
| 4982 | dw = (int)(mDisplay.getWidth()*scale); |
| 4983 | dh = (int)(mDisplay.getHeight()*scale); |
| 4984 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 4985 | int tmp = dw; |
| 4986 | dw = dh; |
| 4987 | dh = tmp; |
| 4988 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 4989 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4990 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4991 | } |
| 4992 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame^] | 4993 | if (rawss == null) { |
| 4994 | return null; |
| 4995 | } |
| 4996 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4997 | Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig()); |
| 4998 | Matrix matrix = new Matrix(); |
| 4999 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 5000 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 5001 | Canvas canvas = new Canvas(bm); |
| 5002 | canvas.drawBitmap(rawss, matrix, null); |
| 5003 | |
| 5004 | rawss.recycle(); |
| 5005 | return bm; |
| 5006 | } |
| 5007 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5008 | public void freezeRotation() { |
| 5009 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5010 | "setRotation()")) { |
| 5011 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5012 | } |
| 5013 | |
| 5014 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 5015 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5016 | } |
| 5017 | |
| 5018 | public void thawRotation() { |
| 5019 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5020 | "setRotation()")) { |
| 5021 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5022 | } |
| 5023 | |
| 5024 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 5025 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5026 | } |
| 5027 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5028 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5029 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5030 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5031 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5032 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | } |
| 5034 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5035 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5036 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5037 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5038 | public void setRotationUnchecked(int rotation, |
| 5039 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5040 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5041 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5042 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5043 | long origId = Binder.clearCallingIdentity(); |
| 5044 | boolean changed; |
| 5045 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5046 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5048 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5049 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5050 | sendNewConfiguration(); |
| 5051 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5053 | Binder.restoreCallingIdentity(origId); |
| 5054 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5055 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5056 | /** |
| 5057 | * Apply a new rotation to the screen, respecting the requests of |
| 5058 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 5059 | * re-evaluate the desired rotation. |
| 5060 | * |
| 5061 | * Returns null if the rotation has been changed. In this case YOU |
| 5062 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 5063 | */ |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5064 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5065 | boolean changed; |
| 5066 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5067 | rotation = mRequestedRotation; |
| 5068 | } else { |
| 5069 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 5070 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5071 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5072 | 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] | 5073 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5074 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5075 | 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] | 5076 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5078 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5079 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5080 | "Rotation changed to " + rotation |
| 5081 | + " from " + mRotation |
| 5082 | + " (forceApp=" + mForcedAppOrientation |
| 5083 | + ", req=" + mRequestedRotation + ")"); |
| 5084 | mRotation = rotation; |
| 5085 | mWindowsFreezingScreen = true; |
| 5086 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 5087 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 5088 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5089 | mWaitingForConfig = true; |
| 5090 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5091 | startFreezingDisplayLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5092 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5093 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5094 | if (mDisplayEnabled) { |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5095 | if (CUSTOM_SCREEN_ROTATION) { |
| 5096 | Surface.freezeDisplay(0); |
| 5097 | Surface.openTransaction(); |
| 5098 | if (mScreenRotationAnimation != null) { |
| 5099 | mScreenRotationAnimation.setRotation(rotation); |
| 5100 | } |
| 5101 | Surface.closeTransaction(); |
| 5102 | Surface.setOrientation(0, rotation, animFlags); |
| 5103 | Surface.unfreezeDisplay(0); |
| 5104 | } else { |
| 5105 | Surface.setOrientation(0, rotation, animFlags); |
| 5106 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5107 | } |
| 5108 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5109 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5110 | if (w.mSurface != null) { |
| 5111 | w.mOrientationChanging = true; |
| 5112 | } |
| 5113 | } |
| 5114 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5115 | try { |
| 5116 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5117 | } catch (RemoteException e) { |
| 5118 | } |
| 5119 | } |
| 5120 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5122 | return changed; |
| 5123 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5125 | public int getRotation() { |
| 5126 | return mRotation; |
| 5127 | } |
| 5128 | |
| 5129 | public int watchRotation(IRotationWatcher watcher) { |
| 5130 | final IBinder watcherBinder = watcher.asBinder(); |
| 5131 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5132 | public void binderDied() { |
| 5133 | synchronized (mWindowMap) { |
| 5134 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5135 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5136 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5137 | if (removed != null) { |
| 5138 | removed.asBinder().unlinkToDeath(this, 0); |
| 5139 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5140 | i--; |
| 5141 | } |
| 5142 | } |
| 5143 | } |
| 5144 | } |
| 5145 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5147 | synchronized (mWindowMap) { |
| 5148 | try { |
| 5149 | watcher.asBinder().linkToDeath(dr, 0); |
| 5150 | mRotationWatchers.add(watcher); |
| 5151 | } catch (RemoteException e) { |
| 5152 | // Client died, no cleanup needed. |
| 5153 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5155 | return mRotation; |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | /** |
| 5160 | * Starts the view server on the specified port. |
| 5161 | * |
| 5162 | * @param port The port to listener to. |
| 5163 | * |
| 5164 | * @return True if the server was successfully started, false otherwise. |
| 5165 | * |
| 5166 | * @see com.android.server.ViewServer |
| 5167 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 5168 | */ |
| 5169 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5170 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5171 | return false; |
| 5172 | } |
| 5173 | |
| 5174 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5175 | return false; |
| 5176 | } |
| 5177 | |
| 5178 | if (port < 1024) { |
| 5179 | return false; |
| 5180 | } |
| 5181 | |
| 5182 | if (mViewServer != null) { |
| 5183 | if (!mViewServer.isRunning()) { |
| 5184 | try { |
| 5185 | return mViewServer.start(); |
| 5186 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5187 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5188 | } |
| 5189 | } |
| 5190 | return false; |
| 5191 | } |
| 5192 | |
| 5193 | try { |
| 5194 | mViewServer = new ViewServer(this, port); |
| 5195 | return mViewServer.start(); |
| 5196 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5197 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5198 | } |
| 5199 | return false; |
| 5200 | } |
| 5201 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5202 | private boolean isSystemSecure() { |
| 5203 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5204 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5205 | } |
| 5206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5207 | /** |
| 5208 | * Stops the view server if it exists. |
| 5209 | * |
| 5210 | * @return True if the server stopped, false if it wasn't started or |
| 5211 | * couldn't be stopped. |
| 5212 | * |
| 5213 | * @see com.android.server.ViewServer |
| 5214 | */ |
| 5215 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5216 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5217 | return false; |
| 5218 | } |
| 5219 | |
| 5220 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5221 | return false; |
| 5222 | } |
| 5223 | |
| 5224 | if (mViewServer != null) { |
| 5225 | return mViewServer.stop(); |
| 5226 | } |
| 5227 | return false; |
| 5228 | } |
| 5229 | |
| 5230 | /** |
| 5231 | * Indicates whether the view server is running. |
| 5232 | * |
| 5233 | * @return True if the server is running, false otherwise. |
| 5234 | * |
| 5235 | * @see com.android.server.ViewServer |
| 5236 | */ |
| 5237 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5238 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5239 | return false; |
| 5240 | } |
| 5241 | |
| 5242 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5243 | return false; |
| 5244 | } |
| 5245 | |
| 5246 | return mViewServer != null && mViewServer.isRunning(); |
| 5247 | } |
| 5248 | |
| 5249 | /** |
| 5250 | * Lists all availble windows in the system. The listing is written in the |
| 5251 | * specified Socket's output stream with the following syntax: |
| 5252 | * windowHashCodeInHexadecimal windowName |
| 5253 | * Each line of the ouput represents a different window. |
| 5254 | * |
| 5255 | * @param client The remote client to send the listing to. |
| 5256 | * @return False if an error occured, true otherwise. |
| 5257 | */ |
| 5258 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5259 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5260 | return false; |
| 5261 | } |
| 5262 | |
| 5263 | boolean result = true; |
| 5264 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5265 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5266 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5267 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5268 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | BufferedWriter out = null; |
| 5272 | |
| 5273 | // Any uncaught exception will crash the system process |
| 5274 | try { |
| 5275 | OutputStream clientStream = client.getOutputStream(); |
| 5276 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5277 | |
| 5278 | final int count = windows.length; |
| 5279 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5280 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5282 | out.write(' '); |
| 5283 | out.append(w.mAttrs.getTitle()); |
| 5284 | out.write('\n'); |
| 5285 | } |
| 5286 | |
| 5287 | out.write("DONE.\n"); |
| 5288 | out.flush(); |
| 5289 | } catch (Exception e) { |
| 5290 | result = false; |
| 5291 | } finally { |
| 5292 | if (out != null) { |
| 5293 | try { |
| 5294 | out.close(); |
| 5295 | } catch (IOException e) { |
| 5296 | result = false; |
| 5297 | } |
| 5298 | } |
| 5299 | } |
| 5300 | |
| 5301 | return result; |
| 5302 | } |
| 5303 | |
| 5304 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5305 | * Returns the focused window in the following format: |
| 5306 | * windowHashCodeInHexadecimal windowName |
| 5307 | * |
| 5308 | * @param client The remote client to send the listing to. |
| 5309 | * @return False if an error occurred, true otherwise. |
| 5310 | */ |
| 5311 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5312 | if (isSystemSecure()) { |
| 5313 | return false; |
| 5314 | } |
| 5315 | |
| 5316 | boolean result = true; |
| 5317 | |
| 5318 | WindowState focusedWindow = getFocusedWindow(); |
| 5319 | |
| 5320 | BufferedWriter out = null; |
| 5321 | |
| 5322 | // Any uncaught exception will crash the system process |
| 5323 | try { |
| 5324 | OutputStream clientStream = client.getOutputStream(); |
| 5325 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5326 | |
| 5327 | if(focusedWindow != null) { |
| 5328 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5329 | out.write(' '); |
| 5330 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5331 | } |
| 5332 | out.write('\n'); |
| 5333 | out.flush(); |
| 5334 | } catch (Exception e) { |
| 5335 | result = false; |
| 5336 | } finally { |
| 5337 | if (out != null) { |
| 5338 | try { |
| 5339 | out.close(); |
| 5340 | } catch (IOException e) { |
| 5341 | result = false; |
| 5342 | } |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | return result; |
| 5347 | } |
| 5348 | |
| 5349 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5350 | * Sends a command to a target window. The result of the command, if any, will be |
| 5351 | * written in the output stream of the specified socket. |
| 5352 | * |
| 5353 | * The parameters must follow this syntax: |
| 5354 | * windowHashcode extra |
| 5355 | * |
| 5356 | * Where XX is the length in characeters of the windowTitle. |
| 5357 | * |
| 5358 | * The first parameter is the target window. The window with the specified hashcode |
| 5359 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5360 | * will be delivered to the target window and as parameters to the command itself. |
| 5361 | * |
| 5362 | * @param client The remote client to sent the result, if any, to. |
| 5363 | * @param command The command to execute. |
| 5364 | * @param parameters The command parameters. |
| 5365 | * |
| 5366 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5367 | * not indicate whether the command itself was successful. |
| 5368 | */ |
| 5369 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5370 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5371 | return false; |
| 5372 | } |
| 5373 | |
| 5374 | boolean success = true; |
| 5375 | Parcel data = null; |
| 5376 | Parcel reply = null; |
| 5377 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5378 | BufferedWriter out = null; |
| 5379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | // Any uncaught exception will crash the system process |
| 5381 | try { |
| 5382 | // Find the hashcode of the window |
| 5383 | int index = parameters.indexOf(' '); |
| 5384 | if (index == -1) { |
| 5385 | index = parameters.length(); |
| 5386 | } |
| 5387 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5388 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5389 | |
| 5390 | // Extract the command's parameter after the window description |
| 5391 | if (index < parameters.length()) { |
| 5392 | parameters = parameters.substring(index + 1); |
| 5393 | } else { |
| 5394 | parameters = ""; |
| 5395 | } |
| 5396 | |
| 5397 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5398 | if (window == null) { |
| 5399 | return false; |
| 5400 | } |
| 5401 | |
| 5402 | data = Parcel.obtain(); |
| 5403 | data.writeInterfaceToken("android.view.IWindow"); |
| 5404 | data.writeString(command); |
| 5405 | data.writeString(parameters); |
| 5406 | data.writeInt(1); |
| 5407 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5408 | |
| 5409 | reply = Parcel.obtain(); |
| 5410 | |
| 5411 | final IBinder binder = window.mClient.asBinder(); |
| 5412 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5413 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5414 | |
| 5415 | reply.readException(); |
| 5416 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5417 | if (!client.isOutputShutdown()) { |
| 5418 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5419 | out.write("DONE\n"); |
| 5420 | out.flush(); |
| 5421 | } |
| 5422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5423 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5424 | 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] | 5425 | success = false; |
| 5426 | } finally { |
| 5427 | if (data != null) { |
| 5428 | data.recycle(); |
| 5429 | } |
| 5430 | if (reply != null) { |
| 5431 | reply.recycle(); |
| 5432 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5433 | if (out != null) { |
| 5434 | try { |
| 5435 | out.close(); |
| 5436 | } catch (IOException e) { |
| 5437 | |
| 5438 | } |
| 5439 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | return success; |
| 5443 | } |
| 5444 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5445 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5446 | synchronized(mWindowMap) { |
| 5447 | mWindowChangeListeners.add(listener); |
| 5448 | } |
| 5449 | } |
| 5450 | |
| 5451 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5452 | synchronized(mWindowMap) { |
| 5453 | mWindowChangeListeners.remove(listener); |
| 5454 | } |
| 5455 | } |
| 5456 | |
| 5457 | private void notifyWindowsChanged() { |
| 5458 | WindowChangeListener[] windowChangeListeners; |
| 5459 | synchronized(mWindowMap) { |
| 5460 | if(mWindowChangeListeners.isEmpty()) { |
| 5461 | return; |
| 5462 | } |
| 5463 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5464 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5465 | } |
| 5466 | int N = windowChangeListeners.length; |
| 5467 | for(int i = 0; i < N; i++) { |
| 5468 | windowChangeListeners[i].windowsChanged(); |
| 5469 | } |
| 5470 | } |
| 5471 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5472 | private void notifyFocusChanged() { |
| 5473 | WindowChangeListener[] windowChangeListeners; |
| 5474 | synchronized(mWindowMap) { |
| 5475 | if(mWindowChangeListeners.isEmpty()) { |
| 5476 | return; |
| 5477 | } |
| 5478 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5479 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5480 | } |
| 5481 | int N = windowChangeListeners.length; |
| 5482 | for(int i = 0; i < N; i++) { |
| 5483 | windowChangeListeners[i].focusChanged(); |
| 5484 | } |
| 5485 | } |
| 5486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5487 | private WindowState findWindow(int hashCode) { |
| 5488 | if (hashCode == -1) { |
| 5489 | return getFocusedWindow(); |
| 5490 | } |
| 5491 | |
| 5492 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5493 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5494 | final int count = windows.size(); |
| 5495 | |
| 5496 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5497 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5498 | if (System.identityHashCode(w) == hashCode) { |
| 5499 | return w; |
| 5500 | } |
| 5501 | } |
| 5502 | } |
| 5503 | |
| 5504 | return null; |
| 5505 | } |
| 5506 | |
| 5507 | /* |
| 5508 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5509 | * that to config-changed listeners if appropriate. |
| 5510 | */ |
| 5511 | void sendNewConfiguration() { |
| 5512 | try { |
| 5513 | mActivityManager.updateConfiguration(null); |
| 5514 | } catch (RemoteException e) { |
| 5515 | } |
| 5516 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5518 | public Configuration computeNewConfiguration() { |
| 5519 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5520 | return computeNewConfigurationLocked(); |
| 5521 | } |
| 5522 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5523 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5524 | Configuration computeNewConfigurationLocked() { |
| 5525 | Configuration config = new Configuration(); |
| 5526 | if (!computeNewConfigurationLocked(config)) { |
| 5527 | return null; |
| 5528 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5529 | return config; |
| 5530 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5531 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5532 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5533 | if (mDisplay == null) { |
| 5534 | return false; |
| 5535 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5536 | |
| 5537 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5538 | |
| 5539 | // Use the effective "visual" dimensions based on current rotation |
| 5540 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5541 | || mRotation == Surface.ROTATION_270); |
| 5542 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5543 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5544 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5545 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5546 | if (dw < dh) { |
| 5547 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5548 | } else if (dw > dh) { |
| 5549 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5550 | } |
| 5551 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5552 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5553 | DisplayMetrics dm = new DisplayMetrics(); |
| 5554 | mDisplay.getMetrics(dm); |
| 5555 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5556 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5557 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5558 | // Note we only do this once because at this point we don't |
| 5559 | // expect the screen to change in this way at runtime, and want |
| 5560 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5561 | int longSize = dw; |
| 5562 | int shortSize = dh; |
| 5563 | if (longSize < shortSize) { |
| 5564 | int tmp = longSize; |
| 5565 | longSize = shortSize; |
| 5566 | shortSize = tmp; |
| 5567 | } |
| 5568 | longSize = (int)(longSize/dm.density); |
| 5569 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5570 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5571 | // These semi-magic numbers define our compatibility modes for |
| 5572 | // applications with different screens. Don't change unless you |
| 5573 | // make sure to test lots and lots of apps! |
| 5574 | if (longSize < 470) { |
| 5575 | // This is shorter than an HVGA normal density screen (which |
| 5576 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5577 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5578 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5579 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5580 | // What size is this screen screen? |
| 5581 | if (longSize >= 800 && shortSize >= 600) { |
| 5582 | // SVGA or larger screens at medium density are the point |
| 5583 | // at which we consider it to be an extra large screen. |
| 5584 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5585 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5586 | // SVGA or larger screens at high density are the point |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5587 | // at which we consider it to be a large screen. |
| 5588 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5589 | } else { |
| 5590 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5591 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5592 | // If this screen is wider than normal HVGA, or taller |
| 5593 | // than FWVGA, then for old apps we want to run in size |
| 5594 | // compatibility mode. |
| 5595 | if (shortSize > 321 || longSize > 570) { |
| 5596 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5597 | } |
| 5598 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5599 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5600 | // Is this a long screen? |
| 5601 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5602 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5603 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5604 | } else { |
| 5605 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5606 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5607 | } |
| 5608 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5609 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5610 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5611 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5612 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5613 | mPolicy.adjustConfigurationLw(config); |
| 5614 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5615 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5616 | |
| 5617 | // ------------------------------------------------------------- |
| 5618 | // Drag and drop |
| 5619 | // ------------------------------------------------------------- |
| 5620 | |
| 5621 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| 5622 | boolean localOnly, int width, int height, Surface outSurface) { |
| 5623 | if (DEBUG_DRAG) { |
| 5624 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| 5625 | + " local=" + localOnly + " win=" + window |
| 5626 | + " asbinder=" + window.asBinder()); |
| 5627 | } |
| 5628 | |
| 5629 | final int callerPid = Binder.getCallingPid(); |
| 5630 | final long origId = Binder.clearCallingIdentity(); |
| 5631 | IBinder token = null; |
| 5632 | |
| 5633 | try { |
| 5634 | synchronized (mWindowMap) { |
| 5635 | try { |
| 5636 | // !!! TODO: fail if the given window does not currently have touch focus? |
| 5637 | |
| 5638 | if (mDragState == null) { |
| 5639 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5640 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5641 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5642 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5643 | token = new Binder(); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5644 | mDragState = new DragState(token, surface, localOnly, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5645 | mDragState.mSurface = surface; |
| 5646 | mDragState.mLocalOnly = localOnly; |
| 5647 | token = mDragState.mToken = new Binder(); |
| 5648 | |
| 5649 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5650 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5651 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5652 | mH.sendMessageDelayed(msg, 5000); |
| 5653 | } else { |
| 5654 | Slog.w(TAG, "Drag already in progress"); |
| 5655 | } |
| 5656 | } catch (Surface.OutOfResourcesException e) { |
| 5657 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5658 | if (mDragState != null) { |
| 5659 | mDragState.reset(); |
| 5660 | mDragState = null; |
| 5661 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5662 | } |
| 5663 | } |
| 5664 | } finally { |
| 5665 | Binder.restoreCallingIdentity(origId); |
| 5666 | } |
| 5667 | |
| 5668 | return token; |
| 5669 | } |
| 5670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5671 | // ------------------------------------------------------------- |
| 5672 | // Input Events and Focus Management |
| 5673 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5674 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5675 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5676 | |
| 5677 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5678 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5679 | * other relevant Window Manager state transitions. */ |
| 5680 | final class InputMonitor { |
| 5681 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5682 | private WindowState mInputFocus; |
| 5683 | |
| 5684 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5685 | private boolean mInputDispatchFrozen; |
| 5686 | |
| 5687 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5688 | private boolean mInputDispatchEnabled = true; |
| 5689 | |
| 5690 | // Temporary list of windows information to provide to the input dispatcher. |
| 5691 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5692 | |
| 5693 | // Temporary input application object to provide to the input dispatcher. |
| 5694 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5695 | |
| 5696 | /* Notifies the window manager about a broken input channel. |
| 5697 | * |
| 5698 | * Called by the InputManager. |
| 5699 | */ |
| 5700 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5701 | synchronized (mWindowMap) { |
| 5702 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5703 | if (windowState == null) { |
| 5704 | return; // irrelevant |
| 5705 | } |
| 5706 | |
| 5707 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5708 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5709 | } |
| 5710 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5711 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5712 | /* Notifies the window manager about an application that is not responding. |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5713 | * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5714 | * |
| 5715 | * Called by the InputManager. |
| 5716 | */ |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5717 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 5718 | AppWindowToken appWindowToken = null; |
| 5719 | if (inputChannel != null) { |
| 5720 | synchronized (mWindowMap) { |
| 5721 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5722 | if (windowState != null) { |
| 5723 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5724 | + windowState.mAttrs.getTitle()); |
| 5725 | appWindowToken = windowState.mAppToken; |
| 5726 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5727 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5728 | } |
| 5729 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5730 | if (appWindowToken == null && token != null) { |
| 5731 | appWindowToken = (AppWindowToken) token; |
| 5732 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5733 | + appWindowToken.stringName); |
| 5734 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5735 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5736 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5737 | try { |
| 5738 | // Notify the activity manager about the timeout and let it decide whether |
| 5739 | // to abort dispatching or keep waiting. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5740 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5741 | if (! abort) { |
| 5742 | // The activity manager declined to abort dispatching. |
| 5743 | // Wait a bit longer and timeout again later. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5744 | return appWindowToken.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5745 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5746 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5747 | } |
| 5748 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5749 | return 0; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5750 | } |
| 5751 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5752 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5753 | synchronized (mWindowMap) { |
| 5754 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5759 | int windowCount = mWindows.size(); |
| 5760 | for (int i = 0; i < windowCount; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5761 | WindowState windowState = mWindows.get(i); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5762 | if (windowState.mInputChannel == inputChannel) { |
| 5763 | return windowState; |
| 5764 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5765 | } |
| 5766 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5767 | return null; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5768 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5769 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5770 | private void addDragInputWindowLw(InputWindowList windowList) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5771 | final InputWindow inputWindow = windowList.add(); |
| 5772 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5773 | inputWindow.name = "drag"; |
| 5774 | inputWindow.layoutParamsFlags = 0; |
| 5775 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5776 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5777 | inputWindow.visible = true; |
| 5778 | inputWindow.canReceiveKeys = false; |
| 5779 | inputWindow.hasFocus = true; |
| 5780 | inputWindow.hasWallpaper = false; |
| 5781 | inputWindow.paused = false; |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5782 | inputWindow.layer = mDragState.getDragLayerLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5783 | inputWindow.ownerPid = Process.myPid(); |
| 5784 | inputWindow.ownerUid = Process.myUid(); |
| 5785 | |
| 5786 | // The drag window covers the entire display |
| 5787 | inputWindow.frameLeft = 0; |
| 5788 | inputWindow.frameTop = 0; |
| 5789 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5790 | inputWindow.frameBottom = mDisplay.getHeight(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5791 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5792 | inputWindow.visibleFrameLeft = inputWindow.frameLeft; |
| 5793 | inputWindow.visibleFrameTop = inputWindow.frameTop; |
| 5794 | inputWindow.visibleFrameRight = inputWindow.frameRight; |
| 5795 | inputWindow.visibleFrameBottom = inputWindow.frameBottom; |
| 5796 | |
| 5797 | inputWindow.touchableAreaLeft = inputWindow.frameLeft; |
| 5798 | inputWindow.touchableAreaTop = inputWindow.frameTop; |
| 5799 | inputWindow.touchableAreaRight = inputWindow.frameRight; |
| 5800 | inputWindow.touchableAreaBottom = inputWindow.frameBottom; |
| 5801 | } |
| 5802 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5803 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5804 | public void updateInputWindowsLw() { |
| 5805 | // Populate the input window list with information about all of the windows that |
| 5806 | // could potentially receive input. |
| 5807 | // As an optimization, we could try to prune the list of windows but this turns |
| 5808 | // out to be difficult because only the native code knows for sure which window |
| 5809 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5810 | final ArrayList<WindowState> windows = mWindows; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5811 | |
| 5812 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5813 | final boolean inDrag = (mDragState != null); |
| 5814 | if (inDrag) { |
| 5815 | if (DEBUG_DRAG) { |
| 5816 | Log.d(TAG, "Inserting drag window"); |
| 5817 | } |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5818 | addDragInputWindowLw(mTempInputWindows); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5819 | } |
| 5820 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5821 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5822 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5823 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5824 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5825 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5826 | continue; |
| 5827 | } |
| 5828 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5829 | final int flags = child.mAttrs.flags; |
| 5830 | final int type = child.mAttrs.type; |
| 5831 | |
| 5832 | final boolean hasFocus = (child == mInputFocus); |
| 5833 | final boolean isVisible = child.isVisibleLw(); |
| 5834 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5835 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5836 | |
| 5837 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5838 | // make sure it's been told about the drag |
| 5839 | if (inDrag && isVisible) { |
| 5840 | mDragState.sendDragStartedIfNeededLw(child); |
| 5841 | } |
| 5842 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5843 | // Add a window to our list of input windows. |
| 5844 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5845 | inputWindow.inputChannel = child.mInputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5846 | inputWindow.name = child.toString(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5847 | inputWindow.layoutParamsFlags = flags; |
| 5848 | inputWindow.layoutParamsType = type; |
| 5849 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5850 | inputWindow.visible = isVisible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5851 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5852 | inputWindow.hasFocus = hasFocus; |
| 5853 | inputWindow.hasWallpaper = hasWallpaper; |
| 5854 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5855 | inputWindow.layer = child.mLayer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5856 | inputWindow.ownerPid = child.mSession.mPid; |
| 5857 | inputWindow.ownerUid = child.mSession.mUid; |
| 5858 | |
| 5859 | final Rect frame = child.mFrame; |
| 5860 | inputWindow.frameLeft = frame.left; |
| 5861 | inputWindow.frameTop = frame.top; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5862 | inputWindow.frameRight = frame.right; |
| 5863 | inputWindow.frameBottom = frame.bottom; |
| 5864 | |
| 5865 | final Rect visibleFrame = child.mVisibleFrame; |
| 5866 | inputWindow.visibleFrameLeft = visibleFrame.left; |
| 5867 | inputWindow.visibleFrameTop = visibleFrame.top; |
| 5868 | inputWindow.visibleFrameRight = visibleFrame.right; |
| 5869 | inputWindow.visibleFrameBottom = visibleFrame.bottom; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5870 | |
| 5871 | switch (child.mTouchableInsets) { |
| 5872 | default: |
| 5873 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5874 | inputWindow.touchableAreaLeft = frame.left; |
| 5875 | inputWindow.touchableAreaTop = frame.top; |
| 5876 | inputWindow.touchableAreaRight = frame.right; |
| 5877 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5878 | break; |
| 5879 | |
| 5880 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5881 | Rect inset = child.mGivenContentInsets; |
| 5882 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5883 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5884 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5885 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5886 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5887 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5888 | |
| 5889 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5890 | Rect inset = child.mGivenVisibleInsets; |
| 5891 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5892 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5893 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5894 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5895 | break; |
| 5896 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5897 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5898 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5899 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5900 | // Send windows to native code. |
| 5901 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5902 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5903 | // Clear the list in preparation for the next round. |
| 5904 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5905 | mTempInputWindows.clear(); |
| 5906 | } |
| 5907 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5908 | /* Notifies that the lid switch changed state. */ |
| 5909 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5910 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5911 | } |
| 5912 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5913 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5914 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5915 | public int interceptKeyBeforeQueueing( |
| 5916 | KeyEvent event, int policyFlags, boolean isScreenOn) { |
| 5917 | return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | /* Provides an opportunity for the window manager policy to process a key before |
| 5921 | * ordinary dispatch. */ |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5922 | public boolean interceptKeyBeforeDispatching( |
| 5923 | InputChannel focus, KeyEvent event, int policyFlags) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5924 | WindowState windowState = getWindowStateForInputChannel(focus); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5925 | return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5926 | } |
| 5927 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5928 | /* Provides an opportunity for the window manager policy to process a key that |
| 5929 | * the application did not handle. */ |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 5930 | public KeyEvent dispatchUnhandledKey( |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5931 | InputChannel focus, KeyEvent event, int policyFlags) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5932 | WindowState windowState = getWindowStateForInputChannel(focus); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5933 | return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5934 | } |
| 5935 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5936 | /* Called when the current input focus changes. |
| 5937 | * Layer assignment is assumed to be complete by the time this is called. |
| 5938 | */ |
| 5939 | public void setInputFocusLw(WindowState newWindow) { |
| 5940 | if (DEBUG_INPUT) { |
| 5941 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5942 | } |
| 5943 | |
| 5944 | if (newWindow != mInputFocus) { |
| 5945 | if (newWindow != null && newWindow.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5946 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5947 | // This is to protect against bugs if someone pauses dispatching but |
| 5948 | // forgets to resume. |
| 5949 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5950 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5951 | |
| 5952 | mInputFocus = newWindow; |
| 5953 | updateInputWindowsLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5954 | } |
| 5955 | } |
| 5956 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5957 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5958 | // Focused app has changed. |
| 5959 | if (newApp == null) { |
| 5960 | mInputManager.setFocusedApplication(null); |
| 5961 | } else { |
| 5962 | mTempInputApplication.name = newApp.toString(); |
| 5963 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5964 | newApp.inputDispatchingTimeoutNanos; |
| 5965 | mTempInputApplication.token = newApp; |
| 5966 | |
| 5967 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5968 | } |
| 5969 | } |
| 5970 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5971 | public void pauseDispatchingLw(WindowToken window) { |
| 5972 | if (! window.paused) { |
| 5973 | if (DEBUG_INPUT) { |
| 5974 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5975 | } |
| 5976 | |
| 5977 | window.paused = true; |
| 5978 | updateInputWindowsLw(); |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | public void resumeDispatchingLw(WindowToken window) { |
| 5983 | if (window.paused) { |
| 5984 | if (DEBUG_INPUT) { |
| 5985 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5986 | } |
| 5987 | |
| 5988 | window.paused = false; |
| 5989 | updateInputWindowsLw(); |
| 5990 | } |
| 5991 | } |
| 5992 | |
| 5993 | public void freezeInputDispatchingLw() { |
| 5994 | if (! mInputDispatchFrozen) { |
| 5995 | if (DEBUG_INPUT) { |
| 5996 | Slog.v(TAG, "Freezing input dispatching"); |
| 5997 | } |
| 5998 | |
| 5999 | mInputDispatchFrozen = true; |
| 6000 | updateInputDispatchModeLw(); |
| 6001 | } |
| 6002 | } |
| 6003 | |
| 6004 | public void thawInputDispatchingLw() { |
| 6005 | if (mInputDispatchFrozen) { |
| 6006 | if (DEBUG_INPUT) { |
| 6007 | Slog.v(TAG, "Thawing input dispatching"); |
| 6008 | } |
| 6009 | |
| 6010 | mInputDispatchFrozen = false; |
| 6011 | updateInputDispatchModeLw(); |
| 6012 | } |
| 6013 | } |
| 6014 | |
| 6015 | public void setEventDispatchingLw(boolean enabled) { |
| 6016 | if (mInputDispatchEnabled != enabled) { |
| 6017 | if (DEBUG_INPUT) { |
| 6018 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 6019 | } |
| 6020 | |
| 6021 | mInputDispatchEnabled = enabled; |
| 6022 | updateInputDispatchModeLw(); |
| 6023 | } |
| 6024 | } |
| 6025 | |
| 6026 | private void updateInputDispatchModeLw() { |
| 6027 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 6028 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6029 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6031 | public void pauseKeyDispatching(IBinder _token) { |
| 6032 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6033 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6034 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | synchronized (mWindowMap) { |
| 6038 | WindowToken token = mTokenMap.get(_token); |
| 6039 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6040 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6041 | } |
| 6042 | } |
| 6043 | } |
| 6044 | |
| 6045 | public void resumeKeyDispatching(IBinder _token) { |
| 6046 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6047 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6048 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | synchronized (mWindowMap) { |
| 6052 | WindowToken token = mTokenMap.get(_token); |
| 6053 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6054 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6055 | } |
| 6056 | } |
| 6057 | } |
| 6058 | |
| 6059 | public void setEventDispatching(boolean enabled) { |
| 6060 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6061 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6062 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6063 | } |
| 6064 | |
| 6065 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6066 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | } |
| 6068 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6070 | /** |
| 6071 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6072 | * Even when sync is false, this method may block while waiting for current |
| 6073 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6074 | * |
| 6075 | * @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] | 6076 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6077 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6078 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6079 | */ |
| 6080 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 6081 | long downTime = ev.getDownTime(); |
| 6082 | long eventTime = ev.getEventTime(); |
| 6083 | |
| 6084 | int action = ev.getAction(); |
| 6085 | int code = ev.getKeyCode(); |
| 6086 | int repeatCount = ev.getRepeatCount(); |
| 6087 | int metaState = ev.getMetaState(); |
| 6088 | int deviceId = ev.getDeviceId(); |
| 6089 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6090 | int source = ev.getSource(); |
Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 6091 | int flags = ev.getFlags(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6092 | |
| 6093 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 6094 | source = InputDevice.SOURCE_KEYBOARD; |
| 6095 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6096 | |
| 6097 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 6098 | if (downTime == 0) downTime = eventTime; |
| 6099 | |
| 6100 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 6101 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6102 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6103 | final int pid = Binder.getCallingPid(); |
| 6104 | final int uid = Binder.getCallingUid(); |
| 6105 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6106 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6107 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6108 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6109 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6110 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6111 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6112 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6113 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6114 | } |
| 6115 | |
| 6116 | /** |
| 6117 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6118 | * Even when sync is false, this method may block while waiting for current |
| 6119 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6120 | * |
| 6121 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 6122 | * {@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] | 6123 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6124 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6125 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6126 | */ |
| 6127 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6128 | final int pid = Binder.getCallingPid(); |
| 6129 | final int uid = Binder.getCallingUid(); |
| 6130 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6131 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6132 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6133 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 6134 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 6135 | } |
| 6136 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6137 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6138 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6139 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6140 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6141 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6142 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6143 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6146 | /** |
| 6147 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6148 | * Even when sync is false, this method may block while waiting for current |
| 6149 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6150 | * |
| 6151 | * @param ev A motion event describing the trackball action. (As noted in |
| 6152 | * {@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] | 6153 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6154 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6155 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6156 | */ |
| 6157 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6158 | final int pid = Binder.getCallingPid(); |
| 6159 | final int uid = Binder.getCallingUid(); |
| 6160 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6161 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6162 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6163 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 6164 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 6165 | } |
| 6166 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6167 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6168 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6169 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6170 | INJECTION_TIMEOUT_MILLIS); |
| 6171 | |
| 6172 | Binder.restoreCallingIdentity(ident); |
| 6173 | return reportInjectionResult(result); |
| 6174 | } |
| 6175 | |
| 6176 | /** |
| 6177 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 6178 | * This variant is useful for fire-and-forget input event injection. It does not |
| 6179 | * block any longer than it takes to enqueue the input event. |
| 6180 | * |
| 6181 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 6182 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6183 | */ |
| 6184 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 6185 | final int pid = Binder.getCallingPid(); |
| 6186 | final int uid = Binder.getCallingUid(); |
| 6187 | final long ident = Binder.clearCallingIdentity(); |
| 6188 | |
| 6189 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 6190 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 6191 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6192 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6193 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6194 | return reportInjectionResult(result); |
| 6195 | } |
| 6196 | |
| 6197 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6198 | switch (result) { |
| 6199 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6200 | Slog.w(TAG, "Input event injection permission denied."); |
| 6201 | throw new SecurityException( |
| 6202 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6203 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 6204 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6205 | return true; |
| 6206 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6207 | Slog.w(TAG, "Input event injection timed out."); |
| 6208 | return false; |
| 6209 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6210 | default: |
| 6211 | Slog.w(TAG, "Input event injection failed."); |
| 6212 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | private WindowState getFocusedWindow() { |
| 6217 | synchronized (mWindowMap) { |
| 6218 | return getFocusedWindowLocked(); |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | private WindowState getFocusedWindowLocked() { |
| 6223 | return mCurrentFocus; |
| 6224 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6226 | public boolean detectSafeMode() { |
| 6227 | mSafeMode = mPolicy.detectSafeMode(); |
| 6228 | return mSafeMode; |
| 6229 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6231 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6232 | synchronized(mWindowMap) { |
| 6233 | if (mDisplay != null) { |
| 6234 | throw new IllegalStateException("Display already initialized"); |
| 6235 | } |
| 6236 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6237 | mDisplay = wm.getDefaultDisplay(); |
| 6238 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6239 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 6240 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 6241 | } |
| 6242 | |
| 6243 | try { |
| 6244 | mActivityManager.updateConfiguration(null); |
| 6245 | } catch (RemoteException e) { |
| 6246 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6247 | |
| 6248 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6249 | } |
| 6250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | // ------------------------------------------------------------- |
| 6252 | // Client Session State |
| 6253 | // ------------------------------------------------------------- |
| 6254 | |
| 6255 | private final class Session extends IWindowSession.Stub |
| 6256 | implements IBinder.DeathRecipient { |
| 6257 | final IInputMethodClient mClient; |
| 6258 | final IInputContext mInputContext; |
| 6259 | final int mUid; |
| 6260 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6261 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6262 | SurfaceSession mSurfaceSession; |
| 6263 | int mNumWindow = 0; |
| 6264 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6266 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6267 | mClient = client; |
| 6268 | mInputContext = inputContext; |
| 6269 | mUid = Binder.getCallingUid(); |
| 6270 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6271 | StringBuilder sb = new StringBuilder(); |
| 6272 | sb.append("Session{"); |
| 6273 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6274 | sb.append(" uid "); |
| 6275 | sb.append(mUid); |
| 6276 | sb.append("}"); |
| 6277 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6279 | synchronized (mWindowMap) { |
| 6280 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6281 | IBinder b = ServiceManager.getService( |
| 6282 | Context.INPUT_METHOD_SERVICE); |
| 6283 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6284 | } |
| 6285 | } |
| 6286 | long ident = Binder.clearCallingIdentity(); |
| 6287 | try { |
| 6288 | // Note: it is safe to call in to the input method manager |
| 6289 | // here because we are not holding our lock. |
| 6290 | if (mInputMethodManager != null) { |
| 6291 | mInputMethodManager.addClient(client, inputContext, |
| 6292 | mUid, mPid); |
| 6293 | } else { |
| 6294 | client.setUsingInputMethod(false); |
| 6295 | } |
| 6296 | client.asBinder().linkToDeath(this, 0); |
| 6297 | } catch (RemoteException e) { |
| 6298 | // The caller has died, so we can just forget about this. |
| 6299 | try { |
| 6300 | if (mInputMethodManager != null) { |
| 6301 | mInputMethodManager.removeClient(client); |
| 6302 | } |
| 6303 | } catch (RemoteException ee) { |
| 6304 | } |
| 6305 | } finally { |
| 6306 | Binder.restoreCallingIdentity(ident); |
| 6307 | } |
| 6308 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6310 | @Override |
| 6311 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6312 | throws RemoteException { |
| 6313 | try { |
| 6314 | return super.onTransact(code, data, reply, flags); |
| 6315 | } catch (RuntimeException e) { |
| 6316 | // Log all 'real' exceptions thrown to the caller |
| 6317 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6318 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6319 | } |
| 6320 | throw e; |
| 6321 | } |
| 6322 | } |
| 6323 | |
| 6324 | public void binderDied() { |
| 6325 | // Note: it is safe to call in to the input method manager |
| 6326 | // here because we are not holding our lock. |
| 6327 | try { |
| 6328 | if (mInputMethodManager != null) { |
| 6329 | mInputMethodManager.removeClient(mClient); |
| 6330 | } |
| 6331 | } catch (RemoteException e) { |
| 6332 | } |
| 6333 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6334 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6335 | mClientDead = true; |
| 6336 | killSessionLocked(); |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6341 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6342 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6343 | outInputChannel); |
| 6344 | } |
| 6345 | |
| 6346 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6347 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6348 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6349 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | public void remove(IWindow window) { |
| 6352 | removeWindow(this, window); |
| 6353 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6356 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6357 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6358 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6359 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6360 | int res = relayoutWindow(this, window, attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6362 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6363 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6364 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6365 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | public void setTransparentRegion(IWindow window, Region region) { |
| 6368 | setTransparentRegionWindow(this, window, region); |
| 6369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6371 | public void setInsets(IWindow window, int touchableInsets, |
| 6372 | Rect contentInsets, Rect visibleInsets) { |
| 6373 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6374 | visibleInsets); |
| 6375 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6377 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6378 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6379 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6381 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6382 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6383 | TAG, "IWindow finishDrawing called for " + window); |
| 6384 | finishDrawingWindow(this, window); |
| 6385 | } |
| 6386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | public void setInTouchMode(boolean mode) { |
| 6388 | synchronized(mWindowMap) { |
| 6389 | mInTouchMode = mode; |
| 6390 | } |
| 6391 | } |
| 6392 | |
| 6393 | public boolean getInTouchMode() { |
| 6394 | synchronized(mWindowMap) { |
| 6395 | return mInTouchMode; |
| 6396 | } |
| 6397 | } |
| 6398 | |
| 6399 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6400 | boolean always) { |
| 6401 | synchronized(mWindowMap) { |
| 6402 | long ident = Binder.clearCallingIdentity(); |
| 6403 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6404 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6405 | windowForClientLocked(this, window, true), |
| 6406 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6407 | } finally { |
| 6408 | Binder.restoreCallingIdentity(ident); |
| 6409 | } |
| 6410 | } |
| 6411 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6412 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6413 | /* Drag/drop */ |
| 6414 | public IBinder prepareDrag(IWindow window, boolean localOnly, |
| 6415 | int width, int height, Surface outSurface) { |
| 6416 | return prepareDragSurface(window, mSurfaceSession, localOnly, |
| 6417 | width, height, outSurface); |
| 6418 | } |
| 6419 | |
| 6420 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6421 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6422 | ClipData data) { |
| 6423 | if (DEBUG_DRAG) { |
| 6424 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6425 | } |
| 6426 | |
| 6427 | synchronized (mWindowMap) { |
| 6428 | if (mDragState == null) { |
| 6429 | Slog.w(TAG, "No drag prepared"); |
| 6430 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6431 | } |
| 6432 | |
| 6433 | if (dragToken != mDragState.mToken) { |
| 6434 | Slog.w(TAG, "Performing mismatched drag"); |
| 6435 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6436 | } |
| 6437 | |
| 6438 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6439 | if (callingWin == null) { |
| 6440 | Slog.w(TAG, "Bad requesting window " + window); |
| 6441 | return false; // !!! TODO: throw here? |
| 6442 | } |
| 6443 | |
| 6444 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6445 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6446 | // called performDrag() |
| 6447 | |
| 6448 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6449 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6450 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6451 | // will let us eliminate the (touchX,touchY) parameters from the API. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6452 | |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6453 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6454 | // the actual drag event dispatch stuff in the dragstate |
| 6455 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6456 | mDragState.register(); |
| 6457 | mInputMonitor.updateInputWindowsLw(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6458 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6459 | mDragState.mServerChannel)) { |
| 6460 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6461 | mDragState.unregister(); |
| 6462 | mDragState = null; |
| 6463 | mInputMonitor.updateInputWindowsLw(); |
| 6464 | return false; |
| 6465 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6466 | |
| 6467 | mDragState.mData = data; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6468 | mDragState.mCurrentX = touchX; |
| 6469 | mDragState.mCurrentY = touchY; |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6470 | mDragState.broadcastDragStartedLw(touchX, touchY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6471 | |
| 6472 | // remember the thumb offsets for later |
| 6473 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6474 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6475 | |
| 6476 | // Make the surface visible at the proper location |
| 6477 | final Surface surface = mDragState.mSurface; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6478 | Surface.openTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6479 | try { |
| 6480 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6481 | (int)(touchY - thumbCenterY)); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6482 | surface.setAlpha(.7071f); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6483 | surface.setLayer(mDragState.getDragLayerLw()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6484 | surface.show(); |
| 6485 | } finally { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6486 | Surface.closeTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6487 | } |
| 6488 | } |
| 6489 | |
| 6490 | return true; // success! |
| 6491 | } |
| 6492 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6493 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6494 | IBinder token = window.asBinder(); |
| 6495 | if (DEBUG_DRAG) { |
| 6496 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6497 | } |
| 6498 | |
| 6499 | synchronized (mWindowMap) { |
| 6500 | if (mDragState.mToken != token) { |
| 6501 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6502 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6503 | } |
| 6504 | |
| 6505 | // The right window has responded, even if it's no longer around, |
| 6506 | // so be sure to halt the timeout even if the later WindowState |
| 6507 | // lookup fails. |
| 6508 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6509 | |
| 6510 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6511 | if (callingWin == null) { |
| 6512 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6513 | return; // !!! TODO: throw here? |
| 6514 | } |
| 6515 | |
| 6516 | mDragState.mDragResult = consumed; |
| 6517 | mDragState.endDragLw(); |
| 6518 | } |
| 6519 | } |
| 6520 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6521 | public void dragRecipientEntered(IWindow window) { |
| 6522 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6523 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6524 | } |
| 6525 | } |
| 6526 | |
| 6527 | public void dragRecipientExited(IWindow window) { |
| 6528 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6529 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6530 | } |
| 6531 | } |
| 6532 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6533 | 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] | 6534 | synchronized(mWindowMap) { |
| 6535 | long ident = Binder.clearCallingIdentity(); |
| 6536 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6537 | setWindowWallpaperPositionLocked( |
| 6538 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6539 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6540 | } finally { |
| 6541 | Binder.restoreCallingIdentity(ident); |
| 6542 | } |
| 6543 | } |
| 6544 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6545 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6546 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6547 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6548 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6549 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6550 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6551 | int z, Bundle extras, boolean sync) { |
| 6552 | synchronized(mWindowMap) { |
| 6553 | long ident = Binder.clearCallingIdentity(); |
| 6554 | try { |
| 6555 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6556 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6557 | action, x, y, z, extras, sync); |
| 6558 | } finally { |
| 6559 | Binder.restoreCallingIdentity(ident); |
| 6560 | } |
| 6561 | } |
| 6562 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6563 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6564 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6565 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6566 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6568 | void windowAddedLocked() { |
| 6569 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6570 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6571 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6572 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6573 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6574 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6575 | mSessions.add(this); |
| 6576 | } |
| 6577 | mNumWindow++; |
| 6578 | } |
| 6579 | |
| 6580 | void windowRemovedLocked() { |
| 6581 | mNumWindow--; |
| 6582 | killSessionLocked(); |
| 6583 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6585 | void killSessionLocked() { |
| 6586 | if (mNumWindow <= 0 && mClientDead) { |
| 6587 | mSessions.remove(this); |
| 6588 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6589 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6590 | TAG, "Last window removed from " + this |
| 6591 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6592 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6593 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6594 | try { |
| 6595 | mSurfaceSession.kill(); |
| 6596 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6597 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6598 | + mSurfaceSession + " in session " + this |
| 6599 | + ": " + e.toString()); |
| 6600 | } |
| 6601 | mSurfaceSession = null; |
| 6602 | } |
| 6603 | } |
| 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 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6607 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6608 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6609 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6610 | } |
| 6611 | |
| 6612 | @Override |
| 6613 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6614 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | } |
| 6616 | } |
| 6617 | |
| 6618 | // ------------------------------------------------------------- |
| 6619 | // Client Window State |
| 6620 | // ------------------------------------------------------------- |
| 6621 | |
| 6622 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6623 | final Session mSession; |
| 6624 | final IWindow mClient; |
| 6625 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6626 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6627 | AppWindowToken mAppToken; |
| 6628 | AppWindowToken mTargetAppToken; |
| 6629 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6630 | final DeathRecipient mDeathRecipient; |
| 6631 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6632 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | final int mBaseLayer; |
| 6634 | final int mSubLayer; |
| 6635 | final boolean mLayoutAttached; |
| 6636 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6637 | final boolean mIsWallpaper; |
| 6638 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6639 | int mViewVisibility; |
| 6640 | boolean mPolicyVisibility = true; |
| 6641 | boolean mPolicyVisibilityAfterAnim = true; |
| 6642 | boolean mAppFreezing; |
| 6643 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6644 | boolean mReportDestroySurface; |
| 6645 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6646 | boolean mAttachedHidden; // is our parent window hidden? |
| 6647 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6648 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6649 | int mRequestedWidth; |
| 6650 | int mRequestedHeight; |
| 6651 | int mLastRequestedWidth; |
| 6652 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6653 | int mLayer; |
| 6654 | int mAnimLayer; |
| 6655 | int mLastLayer; |
| 6656 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6657 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6658 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6659 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6660 | int mLayoutSeq = -1; |
| 6661 | |
| 6662 | Configuration mConfiguration = null; |
| 6663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6664 | // Actual frame shown on-screen (may be modified by animation) |
| 6665 | final Rect mShownFrame = new Rect(); |
| 6666 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6668 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6669 | * Set when we have changed the size of the surface, to know that |
| 6670 | * we must tell them application to resize (and thus redraw itself). |
| 6671 | */ |
| 6672 | boolean mSurfaceResized; |
| 6673 | |
| 6674 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6675 | * Insets that determine the actually visible area |
| 6676 | */ |
| 6677 | final Rect mVisibleInsets = new Rect(); |
| 6678 | final Rect mLastVisibleInsets = new Rect(); |
| 6679 | boolean mVisibleInsetsChanged; |
| 6680 | |
| 6681 | /** |
| 6682 | * Insets that are covered by system windows |
| 6683 | */ |
| 6684 | final Rect mContentInsets = new Rect(); |
| 6685 | final Rect mLastContentInsets = new Rect(); |
| 6686 | boolean mContentInsetsChanged; |
| 6687 | |
| 6688 | /** |
| 6689 | * Set to true if we are waiting for this window to receive its |
| 6690 | * given internal insets before laying out other windows based on it. |
| 6691 | */ |
| 6692 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6694 | /** |
| 6695 | * These are the content insets that were given during layout for |
| 6696 | * this window, to be applied to windows behind it. |
| 6697 | */ |
| 6698 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6700 | /** |
| 6701 | * These are the visible insets that were given during layout for |
| 6702 | * this window, to be applied to windows behind it. |
| 6703 | */ |
| 6704 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6706 | /** |
| 6707 | * Flag indicating whether the touchable region should be adjusted by |
| 6708 | * the visible insets; if false the area outside the visible insets is |
| 6709 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6710 | * tests. |
| 6711 | */ |
| 6712 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6714 | // Current transformation being applied. |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 6715 | boolean mHaveMatrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6716 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6717 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6718 | float mHScale=1, mVScale=1; |
| 6719 | float mLastHScale=1, mLastVScale=1; |
| 6720 | final Matrix mTmpMatrix = new Matrix(); |
| 6721 | |
| 6722 | // "Real" frame that the application sees. |
| 6723 | final Rect mFrame = new Rect(); |
| 6724 | final Rect mLastFrame = new Rect(); |
| 6725 | |
| 6726 | final Rect mContainingFrame = new Rect(); |
| 6727 | final Rect mDisplayFrame = new Rect(); |
| 6728 | final Rect mContentFrame = new Rect(); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6729 | final Rect mParentFrame = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6730 | final Rect mVisibleFrame = new Rect(); |
| 6731 | |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6732 | boolean mContentChanged; |
| 6733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | float mShownAlpha = 1; |
| 6735 | float mAlpha = 1; |
| 6736 | float mLastAlpha = 1; |
| 6737 | |
| 6738 | // Set to true if, when the window gets displayed, it should perform |
| 6739 | // an enter animation. |
| 6740 | boolean mEnterAnimationPending; |
| 6741 | |
| 6742 | // Currently running animation. |
| 6743 | boolean mAnimating; |
| 6744 | boolean mLocalAnimating; |
| 6745 | Animation mAnimation; |
| 6746 | boolean mAnimationIsEntrance; |
| 6747 | boolean mHasTransformation; |
| 6748 | boolean mHasLocalTransformation; |
| 6749 | final Transformation mTransformation = new Transformation(); |
| 6750 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6751 | // If a window showing a wallpaper: the requested offset for the |
| 6752 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6753 | float mWallpaperX = -1; |
| 6754 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6755 | |
| 6756 | // If a window showing a wallpaper: what fraction of the offset |
| 6757 | // range corresponds to a full virtual screen. |
| 6758 | float mWallpaperXStep = -1; |
| 6759 | float mWallpaperYStep = -1; |
| 6760 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6761 | // Wallpaper windows: pixels offset based on above variables. |
| 6762 | int mXOffset; |
| 6763 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6765 | // This is set after IWindowSession.relayout() has been called at |
| 6766 | // least once for the window. It allows us to detect the situation |
| 6767 | // where we don't yet have a surface, but should have one soon, so |
| 6768 | // we can give the window focus before waiting for the relayout. |
| 6769 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6771 | // This is set after the Surface has been created but before the |
| 6772 | // window has been drawn. During this time the surface is hidden. |
| 6773 | boolean mDrawPending; |
| 6774 | |
| 6775 | // This is set after the window has finished drawing for the first |
| 6776 | // time but before its surface is shown. The surface will be |
| 6777 | // displayed when the next layout is run. |
| 6778 | boolean mCommitDrawPending; |
| 6779 | |
| 6780 | // This is set during the time after the window's drawing has been |
| 6781 | // committed, and before its surface is actually shown. It is used |
| 6782 | // to delay showing the surface until all windows in a token are ready |
| 6783 | // to be shown. |
| 6784 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6786 | // Set when the window has been shown in the screen the first time. |
| 6787 | boolean mHasDrawn; |
| 6788 | |
| 6789 | // Currently running an exit animation? |
| 6790 | boolean mExiting; |
| 6791 | |
| 6792 | // Currently on the mDestroySurface list? |
| 6793 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | // Completely remove from window manager after exit animation? |
| 6796 | boolean mRemoveOnExit; |
| 6797 | |
| 6798 | // Set when the orientation is changing and this window has not yet |
| 6799 | // been updated for the new orientation. |
| 6800 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | // Is this window now (or just being) removed? |
| 6803 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6804 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6805 | // For debugging, this is the last information given to the surface flinger. |
| 6806 | boolean mSurfaceShown; |
| 6807 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6808 | int mSurfaceLayer; |
| 6809 | float mSurfaceAlpha; |
| 6810 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6811 | // Input channel |
| 6812 | InputChannel mInputChannel; |
| 6813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6814 | WindowState(Session s, IWindow c, WindowToken token, |
| 6815 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6816 | int viewVisibility) { |
| 6817 | mSession = s; |
| 6818 | mClient = c; |
| 6819 | mToken = token; |
| 6820 | mAttrs.copyFrom(a); |
| 6821 | mViewVisibility = viewVisibility; |
| 6822 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6823 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6824 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6825 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6826 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6827 | try { |
| 6828 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6829 | } catch (RemoteException e) { |
| 6830 | mDeathRecipient = null; |
| 6831 | mAttachedWindow = null; |
| 6832 | mLayoutAttached = false; |
| 6833 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6834 | mIsWallpaper = false; |
| 6835 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | mBaseLayer = 0; |
| 6837 | mSubLayer = 0; |
| 6838 | return; |
| 6839 | } |
| 6840 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6842 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6843 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6844 | // The multiplier here is to reserve space for multiple |
| 6845 | // windows in the same type layer. |
| 6846 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6847 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6848 | + TYPE_LAYER_OFFSET; |
| 6849 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6850 | mAttachedWindow = attachedWindow; |
| 6851 | mAttachedWindow.mChildWindows.add(this); |
| 6852 | mLayoutAttached = mAttrs.type != |
| 6853 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6854 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6855 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6856 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6857 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6858 | } else { |
| 6859 | // The multiplier here is to reserve space for multiple |
| 6860 | // windows in the same type layer. |
| 6861 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6862 | * TYPE_LAYER_MULTIPLIER |
| 6863 | + TYPE_LAYER_OFFSET; |
| 6864 | mSubLayer = 0; |
| 6865 | mAttachedWindow = null; |
| 6866 | mLayoutAttached = false; |
| 6867 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6868 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6869 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6870 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | WindowState appWin = this; |
| 6874 | while (appWin.mAttachedWindow != null) { |
| 6875 | appWin = mAttachedWindow; |
| 6876 | } |
| 6877 | WindowToken appToken = appWin.mToken; |
| 6878 | while (appToken.appWindowToken == null) { |
| 6879 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6880 | if (parent == null || appToken == parent) { |
| 6881 | break; |
| 6882 | } |
| 6883 | appToken = parent; |
| 6884 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6885 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6886 | mAppToken = appToken.appWindowToken; |
| 6887 | |
| 6888 | mSurface = null; |
| 6889 | mRequestedWidth = 0; |
| 6890 | mRequestedHeight = 0; |
| 6891 | mLastRequestedWidth = 0; |
| 6892 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6893 | mXOffset = 0; |
| 6894 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6895 | mLayer = 0; |
| 6896 | mAnimLayer = 0; |
| 6897 | mLastLayer = 0; |
| 6898 | } |
| 6899 | |
| 6900 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6901 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6902 | TAG, "Attaching " + this + " token=" + mToken |
| 6903 | + ", list=" + mToken.windows); |
| 6904 | mSession.windowAddedLocked(); |
| 6905 | } |
| 6906 | |
| 6907 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6908 | mHaveFrame = true; |
| 6909 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6910 | final Rect container = mContainingFrame; |
| 6911 | container.set(pf); |
| 6912 | |
| 6913 | final Rect display = mDisplayFrame; |
| 6914 | display.set(df); |
| 6915 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6916 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6917 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6918 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6919 | display.intersect(mCompatibleScreenFrame); |
| 6920 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | final int pw = container.right - container.left; |
| 6924 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | |
| 6926 | int w,h; |
| 6927 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6928 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6929 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6930 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6931 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6932 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6933 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6934 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6935 | if (!mParentFrame.equals(pf)) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 6936 | //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame |
| 6937 | // + " to " + pf); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6938 | mParentFrame.set(pf); |
| 6939 | mContentChanged = true; |
| 6940 | } |
| 6941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6942 | final Rect content = mContentFrame; |
| 6943 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | final Rect visible = mVisibleFrame; |
| 6946 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6949 | final int fw = frame.width(); |
| 6950 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6953 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6954 | |
| 6955 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6956 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6957 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6958 | |
| 6959 | //System.out.println("Out: " + mFrame); |
| 6960 | |
| 6961 | // Now make sure the window fits in the overall display. |
| 6962 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | // Make sure the content and visible frames are inside of the |
| 6965 | // final window frame. |
| 6966 | if (content.left < frame.left) content.left = frame.left; |
| 6967 | if (content.top < frame.top) content.top = frame.top; |
| 6968 | if (content.right > frame.right) content.right = frame.right; |
| 6969 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6970 | if (visible.left < frame.left) visible.left = frame.left; |
| 6971 | if (visible.top < frame.top) visible.top = frame.top; |
| 6972 | if (visible.right > frame.right) visible.right = frame.right; |
| 6973 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6974 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6975 | final Rect contentInsets = mContentInsets; |
| 6976 | contentInsets.left = content.left-frame.left; |
| 6977 | contentInsets.top = content.top-frame.top; |
| 6978 | contentInsets.right = frame.right-content.right; |
| 6979 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6981 | final Rect visibleInsets = mVisibleInsets; |
| 6982 | visibleInsets.left = visible.left-frame.left; |
| 6983 | visibleInsets.top = visible.top-frame.top; |
| 6984 | visibleInsets.right = frame.right-visible.right; |
| 6985 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6986 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6987 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6988 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6989 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6990 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6991 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6992 | if (localLOGV) { |
| 6993 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6994 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6995 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6996 | + mRequestedWidth + ", mRequestedheight=" |
| 6997 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6998 | + "): frame=" + mFrame.toShortString() |
| 6999 | + " ci=" + contentInsets.toShortString() |
| 7000 | + " vi=" + visibleInsets.toShortString()); |
| 7001 | //} |
| 7002 | } |
| 7003 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | public Rect getFrameLw() { |
| 7006 | return mFrame; |
| 7007 | } |
| 7008 | |
| 7009 | public Rect getShownFrameLw() { |
| 7010 | return mShownFrame; |
| 7011 | } |
| 7012 | |
| 7013 | public Rect getDisplayFrameLw() { |
| 7014 | return mDisplayFrame; |
| 7015 | } |
| 7016 | |
| 7017 | public Rect getContentFrameLw() { |
| 7018 | return mContentFrame; |
| 7019 | } |
| 7020 | |
| 7021 | public Rect getVisibleFrameLw() { |
| 7022 | return mVisibleFrame; |
| 7023 | } |
| 7024 | |
| 7025 | public boolean getGivenInsetsPendingLw() { |
| 7026 | return mGivenInsetsPending; |
| 7027 | } |
| 7028 | |
| 7029 | public Rect getGivenContentInsetsLw() { |
| 7030 | return mGivenContentInsets; |
| 7031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7033 | public Rect getGivenVisibleInsetsLw() { |
| 7034 | return mGivenVisibleInsets; |
| 7035 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7037 | public WindowManager.LayoutParams getAttrs() { |
| 7038 | return mAttrs; |
| 7039 | } |
| 7040 | |
| 7041 | public int getSurfaceLayer() { |
| 7042 | return mLayer; |
| 7043 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7045 | public IApplicationToken getAppToken() { |
| 7046 | return mAppToken != null ? mAppToken.appToken : null; |
| 7047 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7048 | |
| 7049 | public long getInputDispatchingTimeoutNanos() { |
| 7050 | return mAppToken != null |
| 7051 | ? mAppToken.inputDispatchingTimeoutNanos |
| 7052 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 7053 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7054 | |
| 7055 | public boolean hasAppShownWindows() { |
| 7056 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7057 | } |
| 7058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7059 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7060 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7061 | TAG, "Setting animation in " + this + ": " + anim); |
| 7062 | mAnimating = false; |
| 7063 | mLocalAnimating = false; |
| 7064 | mAnimation = anim; |
| 7065 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7066 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7067 | } |
| 7068 | |
| 7069 | public void clearAnimation() { |
| 7070 | if (mAnimation != null) { |
| 7071 | mAnimating = true; |
| 7072 | mLocalAnimating = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7073 | mAnimation.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | mAnimation = null; |
| 7075 | } |
| 7076 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | Surface createSurfaceLocked() { |
| 7079 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7080 | mReportDestroySurface = false; |
| 7081 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | mDrawPending = true; |
| 7083 | mCommitDrawPending = false; |
| 7084 | mReadyToShow = false; |
| 7085 | if (mAppToken != null) { |
| 7086 | mAppToken.allDrawn = false; |
| 7087 | } |
| 7088 | |
| 7089 | int flags = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | |
| 7091 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7092 | flags |= Surface.SECURE; |
| 7093 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7094 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7095 | TAG, "Creating surface in session " |
| 7096 | + mSession.mSurfaceSession + " window " + this |
| 7097 | + " w=" + mFrame.width() |
| 7098 | + " h=" + mFrame.height() + " format=" |
| 7099 | + mAttrs.format + " flags=" + flags); |
| 7100 | |
| 7101 | int w = mFrame.width(); |
| 7102 | int h = mFrame.height(); |
| 7103 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7104 | // for a scaled surface, we always want the requested |
| 7105 | // size. |
| 7106 | w = mRequestedWidth; |
| 7107 | h = mRequestedHeight; |
| 7108 | } |
| 7109 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7110 | // Something is wrong and SurfaceFlinger will not like this, |
| 7111 | // try to revert to sane values |
| 7112 | if (w <= 0) w = 1; |
| 7113 | if (h <= 0) h = 1; |
| 7114 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7115 | mSurfaceShown = false; |
| 7116 | mSurfaceLayer = 0; |
| 7117 | mSurfaceAlpha = 1; |
| 7118 | mSurfaceX = 0; |
| 7119 | mSurfaceY = 0; |
| 7120 | mSurfaceW = w; |
| 7121 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7122 | try { |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7123 | final boolean isHwAccelerated = (mAttrs.flags & |
| 7124 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 7125 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 7126 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 7127 | flags |= Surface.OPAQUE; |
| 7128 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7129 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7130 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7131 | mAttrs.getTitle().toString(), |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7132 | 0, w, h, format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7133 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7134 | + mSurface + " IN SESSION " |
| 7135 | + mSession.mSurfaceSession |
| 7136 | + ": pid=" + mSession.mPid + " format=" |
| 7137 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7138 | + Integer.toHexString(flags) |
| 7139 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7140 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7141 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7142 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7143 | return null; |
| 7144 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7145 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7146 | return null; |
| 7147 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7148 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7149 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7150 | TAG, "Got surface: " + mSurface |
| 7151 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7152 | + ", animLayer=" + mAnimLayer); |
| 7153 | if (SHOW_TRANSACTIONS) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7154 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7155 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 7156 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 7157 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7158 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7159 | } |
| 7160 | Surface.openTransaction(); |
| 7161 | try { |
| 7162 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7163 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7164 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7165 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7166 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7167 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7168 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7169 | mSurface.hide(); |
| 7170 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7171 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7172 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7173 | Surface.SURFACE_DITHER); |
| 7174 | } |
| 7175 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7176 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7177 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7178 | } |
| 7179 | mLastHidden = true; |
| 7180 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7181 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7182 | Surface.closeTransaction(); |
| 7183 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7184 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7185 | TAG, "Created surface " + this); |
| 7186 | } |
| 7187 | return mSurface; |
| 7188 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7190 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7192 | mAppToken.startingDisplayed = false; |
| 7193 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7196 | mDrawPending = false; |
| 7197 | mCommitDrawPending = false; |
| 7198 | mReadyToShow = false; |
| 7199 | |
| 7200 | int i = mChildWindows.size(); |
| 7201 | while (i > 0) { |
| 7202 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7203 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7204 | c.mAttachedHidden = true; |
| 7205 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7206 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7207 | if (mReportDestroySurface) { |
| 7208 | mReportDestroySurface = false; |
| 7209 | mSurfacePendingDestroy = true; |
| 7210 | try { |
| 7211 | mClient.dispatchGetNewSurface(); |
| 7212 | // We'll really destroy on the next time around. |
| 7213 | return; |
| 7214 | } catch (RemoteException e) { |
| 7215 | } |
| 7216 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7218 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7219 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7220 | RuntimeException e = null; |
| 7221 | if (!HIDE_STACK_CRAWLS) { |
| 7222 | e = new RuntimeException(); |
| 7223 | e.fillInStackTrace(); |
| 7224 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7225 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7226 | + mSurface + ", session " + mSession, e); |
| 7227 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7229 | RuntimeException e = null; |
| 7230 | if (!HIDE_STACK_CRAWLS) { |
| 7231 | e = new RuntimeException(); |
| 7232 | e.fillInStackTrace(); |
| 7233 | } |
| 7234 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7235 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7236 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7237 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7238 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | + " surface " + mSurface + " session " + mSession |
| 7240 | + ": " + e.toString()); |
| 7241 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7242 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7243 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7244 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | } |
| 7246 | } |
| 7247 | |
| 7248 | boolean finishDrawingLocked() { |
| 7249 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7250 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7251 | TAG, "finishDrawingLocked: " + mSurface); |
| 7252 | mCommitDrawPending = true; |
| 7253 | mDrawPending = false; |
| 7254 | return true; |
| 7255 | } |
| 7256 | return false; |
| 7257 | } |
| 7258 | |
| 7259 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7260 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7261 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7263 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7264 | } |
| 7265 | mCommitDrawPending = false; |
| 7266 | mReadyToShow = true; |
| 7267 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7268 | final AppWindowToken atoken = mAppToken; |
| 7269 | if (atoken == null || atoken.allDrawn || starting) { |
| 7270 | performShowLocked(); |
| 7271 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7272 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7273 | } |
| 7274 | |
| 7275 | // This must be called while inside a transaction. |
| 7276 | boolean performShowLocked() { |
| 7277 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7278 | RuntimeException e = null; |
| 7279 | if (!HIDE_STACK_CRAWLS) { |
| 7280 | e = new RuntimeException(); |
| 7281 | e.fillInStackTrace(); |
| 7282 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7283 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7284 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7285 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7286 | } |
| 7287 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7288 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7289 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7290 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7291 | + " during animation: policyVis=" + mPolicyVisibility |
| 7292 | + " attHidden=" + mAttachedHidden |
| 7293 | + " tok.hiddenRequested=" |
| 7294 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7295 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7296 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7297 | + " animating=" + mAnimating |
| 7298 | + " tok animating=" |
| 7299 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7300 | if (!showSurfaceRobustlyLocked(this)) { |
| 7301 | return false; |
| 7302 | } |
| 7303 | mLastAlpha = -1; |
| 7304 | mHasDrawn = true; |
| 7305 | mLastHidden = false; |
| 7306 | mReadyToShow = false; |
| 7307 | enableScreenIfNeededLocked(); |
| 7308 | |
| 7309 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7311 | int i = mChildWindows.size(); |
| 7312 | while (i > 0) { |
| 7313 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7314 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7315 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7316 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7317 | if (c.mSurface != null) { |
| 7318 | c.performShowLocked(); |
| 7319 | // It hadn't been shown, which means layout not |
| 7320 | // performed on it, so now we want to make sure to |
| 7321 | // do a layout. If called from within the transaction |
| 7322 | // loop, this will cause it to restart with a new |
| 7323 | // layout. |
| 7324 | mLayoutNeeded = true; |
| 7325 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7326 | } |
| 7327 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7330 | && mAppToken != null) { |
| 7331 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7332 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7333 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7334 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7335 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7336 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7337 | // If this initial window is animating, stop it -- we |
| 7338 | // will do an animation to reveal it from behind the |
| 7339 | // starting window, so there is no need for it to also |
| 7340 | // be doing its own stuff. |
| 7341 | if (mAnimation != null) { |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7342 | mAnimation.cancel(); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7343 | mAnimation = null; |
| 7344 | // Make sure we clean up the animation. |
| 7345 | mAnimating = true; |
| 7346 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7347 | mFinishedStarting.add(mAppToken); |
| 7348 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7349 | } |
| 7350 | mAppToken.updateReportedVisibilityLocked(); |
| 7351 | } |
| 7352 | } |
| 7353 | return true; |
| 7354 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7356 | // This must be called while inside a transaction. Returns true if |
| 7357 | // there is more animation to run. |
| 7358 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7359 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7360 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7362 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7363 | mHasTransformation = true; |
| 7364 | mHasLocalTransformation = true; |
| 7365 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7366 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | TAG, "Starting animation in " + this + |
| 7368 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7369 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7370 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7371 | mAnimation.setStartTime(currentTime); |
| 7372 | mLocalAnimating = true; |
| 7373 | mAnimating = true; |
| 7374 | } |
| 7375 | mTransformation.clear(); |
| 7376 | final boolean more = mAnimation.getTransformation( |
| 7377 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7378 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | TAG, "Stepped animation in " + this + |
| 7380 | ": more=" + more + ", xform=" + mTransformation); |
| 7381 | if (more) { |
| 7382 | // we're not done! |
| 7383 | return true; |
| 7384 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7385 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7386 | TAG, "Finished animation in " + this + |
| 7387 | " @ " + currentTime); |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7388 | |
| 7389 | if (mAnimation != null) { |
| 7390 | mAnimation.cancel(); |
| 7391 | mAnimation = null; |
| 7392 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | //WindowManagerService.this.dump(); |
| 7394 | } |
| 7395 | mHasLocalTransformation = false; |
| 7396 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7397 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7398 | // When our app token is animating, we kind-of pretend like |
| 7399 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7400 | // part of this check means that we will only do this if |
| 7401 | // our window is not currently exiting, or it is not |
| 7402 | // locally animating itself. The idea being that one that |
| 7403 | // is exiting and doing a local animation should be removed |
| 7404 | // once that animation is done. |
| 7405 | mAnimating = true; |
| 7406 | mHasTransformation = true; |
| 7407 | mTransformation.clear(); |
| 7408 | return false; |
| 7409 | } else if (mHasTransformation) { |
| 7410 | // Little trick to get through the path below to act like |
| 7411 | // we have finished an animation. |
| 7412 | mAnimating = true; |
| 7413 | } else if (isAnimating()) { |
| 7414 | mAnimating = true; |
| 7415 | } |
| 7416 | } else if (mAnimation != null) { |
| 7417 | // If the display is frozen, and there is a pending animation, |
| 7418 | // clear it and make sure we run the cleanup code. |
| 7419 | mAnimating = true; |
| 7420 | mLocalAnimating = true; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7421 | mAnimation.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7422 | mAnimation = null; |
| 7423 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7425 | if (!mAnimating && !mLocalAnimating) { |
| 7426 | return false; |
| 7427 | } |
| 7428 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7429 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7430 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7431 | + ", reportedVisible=" |
| 7432 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7434 | mAnimating = false; |
| 7435 | mLocalAnimating = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7436 | if (mAnimation != null) { |
| 7437 | mAnimation.cancel(); |
| 7438 | mAnimation = null; |
| 7439 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7440 | mAnimLayer = mLayer; |
| 7441 | if (mIsImWindow) { |
| 7442 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7443 | } else if (mIsWallpaper) { |
| 7444 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7445 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7446 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7447 | + " anim layer: " + mAnimLayer); |
| 7448 | mHasTransformation = false; |
| 7449 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7450 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7451 | if (DEBUG_VISIBILITY) { |
| 7452 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7453 | + mPolicyVisibilityAfterAnim); |
| 7454 | } |
| 7455 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7456 | if (!mPolicyVisibility) { |
| 7457 | if (mCurrentFocus == this) { |
| 7458 | mFocusMayChange = true; |
| 7459 | } |
| 7460 | // Window is no longer visible -- make sure if we were waiting |
| 7461 | // for it to be displayed before enabling the display, that |
| 7462 | // we allow the display to be enabled now. |
| 7463 | enableScreenIfNeededLocked(); |
| 7464 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7465 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7466 | mTransformation.clear(); |
| 7467 | if (mHasDrawn |
| 7468 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7469 | && mAppToken != null |
| 7470 | && mAppToken.firstWindowDrawn |
| 7471 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7472 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7473 | + mToken + ": first real window done animating"); |
| 7474 | mFinishedStarting.add(mAppToken); |
| 7475 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7476 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7478 | finishExit(); |
| 7479 | |
| 7480 | if (mAppToken != null) { |
| 7481 | mAppToken.updateReportedVisibilityLocked(); |
| 7482 | } |
| 7483 | |
| 7484 | return false; |
| 7485 | } |
| 7486 | |
| 7487 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7488 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7489 | TAG, "finishExit in " + this |
| 7490 | + ": exiting=" + mExiting |
| 7491 | + " remove=" + mRemoveOnExit |
| 7492 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7494 | final int N = mChildWindows.size(); |
| 7495 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7496 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 (!mExiting) { |
| 7500 | return; |
| 7501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | if (isWindowAnimating()) { |
| 7504 | return; |
| 7505 | } |
| 7506 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7507 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7508 | TAG, "Exit animation finished in " + this |
| 7509 | + ": remove=" + mRemoveOnExit); |
| 7510 | if (mSurface != null) { |
| 7511 | mDestroySurface.add(this); |
| 7512 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7513 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7514 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7515 | try { |
| 7516 | mSurface.hide(); |
| 7517 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7518 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7519 | } |
| 7520 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7521 | } |
| 7522 | mExiting = false; |
| 7523 | if (mRemoveOnExit) { |
| 7524 | mPendingRemove.add(this); |
| 7525 | mRemoveOnExit = false; |
| 7526 | } |
| 7527 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7529 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7530 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7531 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7532 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7533 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7534 | return true; |
| 7535 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | void computeShownFrameLocked() { |
| 7538 | final boolean selfTransformation = mHasLocalTransformation; |
| 7539 | Transformation attachedTransformation = |
| 7540 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7541 | ? mAttachedWindow.mTransformation : null; |
| 7542 | Transformation appTransformation = |
| 7543 | (mAppToken != null && mAppToken.hasTransformation) |
| 7544 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7545 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7546 | // Wallpapers are animated based on the "real" window they |
| 7547 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7548 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7549 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7550 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7551 | mWallpaperTarget.mAnimation != null && |
| 7552 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7553 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7554 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7555 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7556 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7557 | } |
| 7558 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7559 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7560 | mWallpaperTarget.mAppToken.animation != null && |
| 7561 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7562 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7563 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7564 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7565 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7566 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7567 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7568 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7569 | final boolean screenAnimation = mScreenRotationAnimation != null |
| 7570 | && mScreenRotationAnimation.isAnimating(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7571 | if (selfTransformation || attachedTransformation != null |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7572 | || appTransformation != null || screenAnimation) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7573 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7574 | final Rect frame = mFrame; |
| 7575 | final float tmpFloats[] = mTmpFloats; |
| 7576 | final Matrix tmpMatrix = mTmpMatrix; |
| 7577 | |
| 7578 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7579 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7580 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7581 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7583 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7584 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7585 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7586 | } |
| 7587 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7588 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7589 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7590 | if (screenAnimation) { |
| 7591 | tmpMatrix.postConcat( |
| 7592 | mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 7593 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7594 | |
| 7595 | // "convert" it into SurfaceFlinger's format |
| 7596 | // (a 2x2 matrix + an offset) |
| 7597 | // Here we must not transform the position of the surface |
| 7598 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7599 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7600 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7601 | mHaveMatrix = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7602 | tmpMatrix.getValues(tmpFloats); |
| 7603 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7604 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 7605 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7606 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7607 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7608 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | int w = frame.width(); |
| 7610 | int h = frame.height(); |
| 7611 | mShownFrame.set(x, y, x+w, y+h); |
| 7612 | |
| 7613 | // Now set the alpha... but because our current hardware |
| 7614 | // can't do alpha transformation on a non-opaque surface, |
| 7615 | // turn it off if we are running an animation that is also |
| 7616 | // transforming since it is more important to have that |
| 7617 | // animation be smooth. |
| 7618 | mShownAlpha = mAlpha; |
| 7619 | if (!mLimitedAlphaCompositing |
| 7620 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7621 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7622 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7623 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7624 | if (selfTransformation) { |
| 7625 | mShownAlpha *= mTransformation.getAlpha(); |
| 7626 | } |
| 7627 | if (attachedTransformation != null) { |
| 7628 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7629 | } |
| 7630 | if (appTransformation != null) { |
| 7631 | mShownAlpha *= appTransformation.getAlpha(); |
| 7632 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7633 | if (screenAnimation) { |
| 7634 | mShownAlpha *= |
| 7635 | mScreenRotationAnimation.getEnterTransformation().getAlpha(); |
| 7636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7637 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7638 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7639 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7640 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7641 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7642 | TAG, "Continuing animation in " + this + |
| 7643 | ": " + mShownFrame + |
| 7644 | ", alpha=" + mTransformation.getAlpha()); |
| 7645 | return; |
| 7646 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7649 | if (mXOffset != 0 || mYOffset != 0) { |
| 7650 | mShownFrame.offset(mXOffset, mYOffset); |
| 7651 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7652 | mShownAlpha = mAlpha; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7653 | mHaveMatrix = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7654 | mDsDx = 1; |
| 7655 | mDtDx = 0; |
| 7656 | mDsDy = 0; |
| 7657 | mDtDy = 1; |
| 7658 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7660 | /** |
| 7661 | * Is this window visible? It is not visible if there is no |
| 7662 | * surface, or we are in the process of running an exit animation |
| 7663 | * that will remove the surface, or its app token has been hidden. |
| 7664 | */ |
| 7665 | public boolean isVisibleLw() { |
| 7666 | final AppWindowToken atoken = mAppToken; |
| 7667 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7668 | && (atoken == null || !atoken.hiddenRequested) |
| 7669 | && !mExiting && !mDestroying; |
| 7670 | } |
| 7671 | |
| 7672 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7673 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7674 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7675 | * things like window flags that impact the keyguard. |
| 7676 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7677 | * for this "hidden behind keyguard" state rather than overloading |
| 7678 | * mPolicyVisibility. Ungh. |
| 7679 | */ |
| 7680 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7681 | final AppWindowToken atoken = mAppToken; |
| 7682 | return mSurface != null && !mAttachedHidden |
| 7683 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7684 | && !mDrawPending && !mCommitDrawPending |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7685 | && !mExiting && !mDestroying; |
| 7686 | } |
| 7687 | |
| 7688 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7689 | * Is this window visible, ignoring its app token? It is not visible |
| 7690 | * if there is no surface, or we are in the process of running an exit animation |
| 7691 | * that will remove the surface. |
| 7692 | */ |
| 7693 | public boolean isWinVisibleLw() { |
| 7694 | final AppWindowToken atoken = mAppToken; |
| 7695 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7696 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7697 | && !mExiting && !mDestroying; |
| 7698 | } |
| 7699 | |
| 7700 | /** |
| 7701 | * The same as isVisible(), but follows the current hidden state of |
| 7702 | * the associated app token, not the pending requested hidden state. |
| 7703 | */ |
| 7704 | boolean isVisibleNow() { |
| 7705 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7706 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7707 | } |
| 7708 | |
| 7709 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7710 | * Can this window possibly be a drag/drop target? The test here is |
| 7711 | * a combination of the above "visible now" with the check that the |
| 7712 | * Input Manager uses when discarding windows from input consideration. |
| 7713 | */ |
| 7714 | boolean isPotentialDragTarget() { |
| 7715 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7716 | } |
| 7717 | |
| 7718 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | * Same as isVisible(), but we also count it as visible between the |
| 7720 | * call to IWindowSession.add() and the first relayout(). |
| 7721 | */ |
| 7722 | boolean isVisibleOrAdding() { |
| 7723 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7724 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7725 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7726 | && mPolicyVisibility && !mAttachedHidden |
| 7727 | && (atoken == null || !atoken.hiddenRequested) |
| 7728 | && !mExiting && !mDestroying; |
| 7729 | } |
| 7730 | |
| 7731 | /** |
| 7732 | * Is this window currently on-screen? It is on-screen either if it |
| 7733 | * is visible or it is currently running an animation before no longer |
| 7734 | * being visible. |
| 7735 | */ |
| 7736 | boolean isOnScreen() { |
| 7737 | final AppWindowToken atoken = mAppToken; |
| 7738 | if (atoken != null) { |
| 7739 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7740 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7741 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7742 | } else { |
| 7743 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7744 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7745 | } |
| 7746 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7748 | /** |
| 7749 | * Like isOnScreen(), but we don't return true if the window is part |
| 7750 | * of a transition that has not yet been started. |
| 7751 | */ |
| 7752 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7753 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7754 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7755 | return false; |
| 7756 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7757 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7758 | final boolean animating = atoken != null |
| 7759 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7760 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7761 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7762 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7763 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | /** Is the window or its container currently animating? */ |
| 7767 | boolean isAnimating() { |
| 7768 | final WindowState attached = mAttachedWindow; |
| 7769 | final AppWindowToken atoken = mAppToken; |
| 7770 | return mAnimation != null |
| 7771 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7772 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | (atoken.animation != null |
| 7774 | || atoken.inPendingTransaction)); |
| 7775 | } |
| 7776 | |
| 7777 | /** Is this window currently animating? */ |
| 7778 | boolean isWindowAnimating() { |
| 7779 | return mAnimation != null; |
| 7780 | } |
| 7781 | |
| 7782 | /** |
| 7783 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7784 | * been drawn. |
| 7785 | */ |
| 7786 | public boolean isDisplayedLw() { |
| 7787 | final AppWindowToken atoken = mAppToken; |
| 7788 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7789 | && !mDrawPending && !mCommitDrawPending |
| 7790 | && ((!mAttachedHidden && |
| 7791 | (atoken == null || !atoken.hiddenRequested)) |
| 7792 | || mAnimating); |
| 7793 | } |
| 7794 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7795 | /** |
| 7796 | * Returns true if the window has a surface that it has drawn a |
| 7797 | * complete UI in to. |
| 7798 | */ |
| 7799 | public boolean isDrawnLw() { |
| 7800 | final AppWindowToken atoken = mAppToken; |
| 7801 | return mSurface != null && !mDestroying |
| 7802 | && !mDrawPending && !mCommitDrawPending; |
| 7803 | } |
| 7804 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7805 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7806 | * Return true if the window is opaque and fully drawn. This indicates |
| 7807 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7808 | */ |
| 7809 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7810 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7811 | || mAttrs.type == TYPE_WALLPAPER) |
| 7812 | && mSurface != null && mAnimation == null |
| 7813 | && (mAppToken == null || mAppToken.animation == null) |
| 7814 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7815 | } |
| 7816 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7817 | /** |
| 7818 | * Return whether this window is wanting to have a translation |
| 7819 | * animation applied to it for an in-progress move. (Only makes |
| 7820 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 7821 | */ |
| 7822 | boolean shouldAnimateMove() { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7823 | return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7824 | && (mFrame.top != mLastFrame.top |
| 7825 | || mFrame.left != mLastFrame.left) |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7826 | && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove()) |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7827 | && mPolicy.isScreenOn(); |
| 7828 | } |
| 7829 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7830 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7831 | return |
| 7832 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7833 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7834 | // only if it's visible |
| 7835 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7836 | // and only if the application fills the compatible screen |
| 7837 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7838 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7839 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7840 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7841 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7842 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7843 | } |
| 7844 | |
| 7845 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7846 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7847 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7848 | } |
| 7849 | |
| 7850 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7851 | disposeInputChannel(); |
| 7852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7853 | if (mAttachedWindow != null) { |
| 7854 | mAttachedWindow.mChildWindows.remove(this); |
| 7855 | } |
| 7856 | destroySurfaceLocked(); |
| 7857 | mSession.windowRemovedLocked(); |
| 7858 | try { |
| 7859 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7860 | } catch (RuntimeException e) { |
| 7861 | // Ignore if it has already been removed (usually because |
| 7862 | // we are doing this as part of processing a death note.) |
| 7863 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7864 | } |
| 7865 | |
| 7866 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7867 | if (mInputChannel != null) { |
| 7868 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7869 | |
| 7870 | mInputChannel.dispose(); |
| 7871 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7872 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7876 | public void binderDied() { |
| 7877 | try { |
| 7878 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7879 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7880 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7881 | if (win != null) { |
| 7882 | removeWindowLocked(mSession, win); |
| 7883 | } |
| 7884 | } |
| 7885 | } catch (IllegalArgumentException ex) { |
| 7886 | // This will happen if the window has already been |
| 7887 | // removed. |
| 7888 | } |
| 7889 | } |
| 7890 | } |
| 7891 | |
| 7892 | /** Returns true if this window desires key events. */ |
| 7893 | public final boolean canReceiveKeys() { |
| 7894 | return isVisibleOrAdding() |
| 7895 | && (mViewVisibility == View.VISIBLE) |
| 7896 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7897 | } |
| 7898 | |
| 7899 | public boolean hasDrawnLw() { |
| 7900 | return mHasDrawn; |
| 7901 | } |
| 7902 | |
| 7903 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7904 | return showLw(doAnimation, true); |
| 7905 | } |
| 7906 | |
| 7907 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7908 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7909 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7910 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7911 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7912 | if (doAnimation) { |
| 7913 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7914 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7915 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7916 | doAnimation = false; |
| 7917 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7918 | // Check for the case where we are currently visible and |
| 7919 | // not animating; we do not want to do animation at such a |
| 7920 | // point to become visible when we already are. |
| 7921 | doAnimation = false; |
| 7922 | } |
| 7923 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7924 | mPolicyVisibility = true; |
| 7925 | mPolicyVisibilityAfterAnim = true; |
| 7926 | if (doAnimation) { |
| 7927 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7928 | } |
| 7929 | if (requestAnim) { |
| 7930 | requestAnimationLocked(0); |
| 7931 | } |
| 7932 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7933 | } |
| 7934 | |
| 7935 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7936 | return hideLw(doAnimation, true); |
| 7937 | } |
| 7938 | |
| 7939 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7940 | if (doAnimation) { |
| 7941 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7942 | doAnimation = false; |
| 7943 | } |
| 7944 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7945 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7946 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7947 | if (!current) { |
| 7948 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7949 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7950 | if (doAnimation) { |
| 7951 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7952 | if (mAnimation == null) { |
| 7953 | doAnimation = false; |
| 7954 | } |
| 7955 | } |
| 7956 | if (doAnimation) { |
| 7957 | mPolicyVisibilityAfterAnim = false; |
| 7958 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7959 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7960 | mPolicyVisibilityAfterAnim = false; |
| 7961 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7962 | // Window is no longer visible -- make sure if we were waiting |
| 7963 | // for it to be displayed before enabling the display, that |
| 7964 | // we allow the display to be enabled now. |
| 7965 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7966 | if (mCurrentFocus == this) { |
| 7967 | mFocusMayChange = true; |
| 7968 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7969 | } |
| 7970 | if (requestAnim) { |
| 7971 | requestAnimationLocked(0); |
| 7972 | } |
| 7973 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | } |
| 7975 | |
| 7976 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7977 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7978 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7979 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7980 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7981 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7982 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7983 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7984 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7985 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7986 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7987 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7988 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7989 | } |
| 7990 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7991 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7992 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7993 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7994 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7995 | pw.print("="); pw.print(mAnimLayer); |
| 7996 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7997 | if (mSurface != null) { |
| 7998 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7999 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8000 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8001 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8002 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8003 | pw.print(","); pw.print(mSurfaceY); |
| 8004 | pw.print(") "); pw.print(mSurfaceW); |
| 8005 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8006 | } |
| 8007 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8008 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8009 | if (mAppToken != null) { |
| 8010 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8011 | } |
| 8012 | if (mTargetAppToken != null) { |
| 8013 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8014 | } |
| 8015 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8016 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8017 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8018 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8019 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8020 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8021 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8022 | pw.print(mPolicyVisibility); |
| 8023 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8024 | pw.print(mPolicyVisibilityAfterAnim); |
| 8025 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8026 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8027 | if (!mRelayoutCalled) { |
| 8028 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8029 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8030 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8031 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8032 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8033 | if (mXOffset != 0 || mYOffset != 0) { |
| 8034 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8035 | pw.print(" y="); pw.println(mYOffset); |
| 8036 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8037 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8038 | mGivenContentInsets.printShortString(pw); |
| 8039 | pw.print(" mGivenVisibleInsets="); |
| 8040 | mGivenVisibleInsets.printShortString(pw); |
| 8041 | pw.println(); |
| 8042 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8043 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8044 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8045 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8046 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8047 | pw.print(prefix); pw.print("mShownFrame="); |
| 8048 | mShownFrame.printShortString(pw); |
| 8049 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8050 | pw.println(); |
| 8051 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8052 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8053 | pw.println(); |
| 8054 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8055 | mContainingFrame.printShortString(pw); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8056 | pw.print(" mParentFrame="); |
| 8057 | mParentFrame.printShortString(pw); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8058 | pw.print(" mDisplayFrame="); |
| 8059 | mDisplayFrame.printShortString(pw); |
| 8060 | pw.println(); |
| 8061 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8062 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8063 | pw.println(); |
| 8064 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8065 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8066 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8067 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8068 | pw.println(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8069 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8070 | || mAnimation != null) { |
| 8071 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8072 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8073 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8074 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8075 | } |
| 8076 | if (mHasTransformation || mHasLocalTransformation) { |
| 8077 | pw.print(prefix); pw.print("XForm: has="); |
| 8078 | pw.print(mHasTransformation); |
| 8079 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8080 | pw.print(" "); mTransformation.printShortString(pw); |
| 8081 | pw.println(); |
| 8082 | } |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8083 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8084 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8085 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8086 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8087 | } |
| 8088 | if (mHaveMatrix) { |
| 8089 | pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx); |
| 8090 | pw.print(" mDtDx="); pw.print(mDtDx); |
| 8091 | pw.print(" mDsDy="); pw.print(mDsDy); |
| 8092 | pw.print(" mDtDy="); pw.println(mDtDy); |
| 8093 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8094 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8095 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8096 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8097 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8098 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8099 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8100 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8101 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8102 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8103 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8104 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8105 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8106 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8107 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8108 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8109 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8110 | if (mHScale != 1 || mVScale != 1) { |
| 8111 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8112 | pw.print(" mVScale="); pw.println(mVScale); |
| 8113 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8114 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8115 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8116 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8117 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8118 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8119 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8120 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8121 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8122 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8123 | |
| 8124 | String makeInputChannelName() { |
| 8125 | return Integer.toHexString(System.identityHashCode(this)) |
| 8126 | + " " + mAttrs.getTitle(); |
| 8127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | |
| 8129 | @Override |
| 8130 | public String toString() { |
| 8131 | return "Window{" |
| 8132 | + Integer.toHexString(System.identityHashCode(this)) |
| 8133 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 8134 | } |
| 8135 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | // ------------------------------------------------------------- |
| 8138 | // Window Token State |
| 8139 | // ------------------------------------------------------------- |
| 8140 | |
| 8141 | class WindowToken { |
| 8142 | // The actual token. |
| 8143 | final IBinder token; |
| 8144 | |
| 8145 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8146 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8148 | // Set if this token was explicitly added by a client, so should |
| 8149 | // not be removed when all windows are removed. |
| 8150 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8151 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8152 | // For printing. |
| 8153 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8155 | // If this is an AppWindowToken, this is non-null. |
| 8156 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8158 | // All of the windows associated with this token. |
| 8159 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8160 | |
| 8161 | // Is key dispatching paused for this token? |
| 8162 | boolean paused = false; |
| 8163 | |
| 8164 | // Should this token's windows be hidden? |
| 8165 | boolean hidden; |
| 8166 | |
| 8167 | // Temporary for finding which tokens no longer have visible windows. |
| 8168 | boolean hasVisible; |
| 8169 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8170 | // Set to true when this token is in a pending transaction where it |
| 8171 | // will be shown. |
| 8172 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8173 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8174 | // Set to true when this token is in a pending transaction where it |
| 8175 | // will be hidden. |
| 8176 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8177 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8178 | // Set to true when this token is in a pending transaction where its |
| 8179 | // windows will be put to the bottom of the list. |
| 8180 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8181 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8182 | // Set to true when this token is in a pending transaction where its |
| 8183 | // windows will be put to the top of the list. |
| 8184 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8186 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8187 | token = _token; |
| 8188 | windowType = type; |
| 8189 | explicit = _explicit; |
| 8190 | } |
| 8191 | |
| 8192 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8193 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8194 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8195 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8196 | pw.print(" hidden="); pw.print(hidden); |
| 8197 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8198 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8199 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8200 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8201 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8202 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8203 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8204 | } |
| 8205 | |
| 8206 | @Override |
| 8207 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8208 | if (stringName == null) { |
| 8209 | StringBuilder sb = new StringBuilder(); |
| 8210 | sb.append("WindowToken{"); |
| 8211 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8212 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8213 | stringName = sb.toString(); |
| 8214 | } |
| 8215 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8216 | } |
| 8217 | }; |
| 8218 | |
| 8219 | class AppWindowToken extends WindowToken { |
| 8220 | // Non-null only for application tokens. |
| 8221 | final IApplicationToken appToken; |
| 8222 | |
| 8223 | // All of the windows and child windows that are included in this |
| 8224 | // application token. Note this list is NOT sorted! |
| 8225 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8226 | |
| 8227 | int groupId = -1; |
| 8228 | boolean appFullscreen; |
| 8229 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8230 | |
| 8231 | // The input dispatching timeout for this application token in nanoseconds. |
| 8232 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8234 | // These are used for determining when all windows associated with |
| 8235 | // an activity have been drawn, so they can be made visible together |
| 8236 | // at the same time. |
| 8237 | int lastTransactionSequence = mTransactionSequence-1; |
| 8238 | int numInterestingWindows; |
| 8239 | int numDrawnWindows; |
| 8240 | boolean inPendingTransaction; |
| 8241 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8243 | // Is this token going to be hidden in a little while? If so, it |
| 8244 | // won't be taken into account for setting the screen orientation. |
| 8245 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8247 | // Is this window's surface needed? This is almost like hidden, except |
| 8248 | // it will sometimes be true a little earlier: when the token has |
| 8249 | // been shown, but is still waiting for its app transition to execute |
| 8250 | // before making its windows shown. |
| 8251 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8253 | // Have we told the window clients to hide themselves? |
| 8254 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8256 | // Last visibility state we reported to the app token. |
| 8257 | boolean reportedVisible; |
| 8258 | |
| 8259 | // Set to true when the token has been removed from the window mgr. |
| 8260 | boolean removed; |
| 8261 | |
| 8262 | // Have we been asked to have this token keep the screen frozen? |
| 8263 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8265 | boolean animating; |
| 8266 | Animation animation; |
| 8267 | boolean hasTransformation; |
| 8268 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8270 | // Offset to the window of all layers in the token, for use by |
| 8271 | // AppWindowToken animations. |
| 8272 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8274 | // Information about an application starting window if displayed. |
| 8275 | StartingData startingData; |
| 8276 | WindowState startingWindow; |
| 8277 | View startingView; |
| 8278 | boolean startingDisplayed; |
| 8279 | boolean startingMoved; |
| 8280 | boolean firstWindowDrawn; |
| 8281 | |
| 8282 | AppWindowToken(IApplicationToken _token) { |
| 8283 | super(_token.asBinder(), |
| 8284 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8285 | appWindowToken = this; |
| 8286 | appToken = _token; |
| 8287 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8289 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8290 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8291 | TAG, "Setting animation in " + this + ": " + anim); |
| 8292 | animation = anim; |
| 8293 | animating = false; |
| 8294 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8295 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8296 | int zorder = anim.getZAdjustment(); |
| 8297 | int adj = 0; |
| 8298 | if (zorder == Animation.ZORDER_TOP) { |
| 8299 | adj = TYPE_LAYER_OFFSET; |
| 8300 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8301 | adj = -TYPE_LAYER_OFFSET; |
| 8302 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8304 | if (animLayerAdjustment != adj) { |
| 8305 | animLayerAdjustment = adj; |
| 8306 | updateLayers(); |
| 8307 | } |
| 8308 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8310 | public void setDummyAnimation() { |
| 8311 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8312 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8313 | TAG, "Setting dummy animation in " + this); |
| 8314 | animation = sDummyAnimation; |
| 8315 | } |
| 8316 | } |
| 8317 | |
| 8318 | public void clearAnimation() { |
| 8319 | if (animation != null) { |
| 8320 | animation = null; |
| 8321 | animating = true; |
| 8322 | } |
| 8323 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8325 | void updateLayers() { |
| 8326 | final int N = allAppWindows.size(); |
| 8327 | final int adj = animLayerAdjustment; |
| 8328 | for (int i=0; i<N; i++) { |
| 8329 | WindowState w = allAppWindows.get(i); |
| 8330 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8331 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | + w.mAnimLayer); |
| 8333 | if (w == mInputMethodTarget) { |
| 8334 | setInputMethodAnimLayerAdjustment(adj); |
| 8335 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8336 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8337 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8338 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8339 | } |
| 8340 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8342 | void sendAppVisibilityToClients() { |
| 8343 | final int N = allAppWindows.size(); |
| 8344 | for (int i=0; i<N; i++) { |
| 8345 | WindowState win = allAppWindows.get(i); |
| 8346 | if (win == startingWindow && clientHidden) { |
| 8347 | // Don't hide the starting window. |
| 8348 | continue; |
| 8349 | } |
| 8350 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8351 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8352 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8353 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8354 | } catch (RemoteException e) { |
| 8355 | } |
| 8356 | } |
| 8357 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8359 | void showAllWindowsLocked() { |
| 8360 | final int NW = allAppWindows.size(); |
| 8361 | for (int i=0; i<NW; i++) { |
| 8362 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8363 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8364 | "performing show on: " + w); |
| 8365 | w.performShowLocked(); |
| 8366 | } |
| 8367 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8369 | // This must be called while inside a transaction. |
| 8370 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8371 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8372 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8374 | if (animation == sDummyAnimation) { |
| 8375 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8376 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8377 | // when it is really time to animate, this will be set to |
| 8378 | // a real animation and the next call will execute normally. |
| 8379 | return false; |
| 8380 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8382 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8383 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8384 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8385 | TAG, "Starting animation in " + this + |
| 8386 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8387 | + " scale=" + mTransitionAnimationScale |
| 8388 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8389 | animation.initialize(dw, dh, dw, dh); |
| 8390 | animation.setStartTime(currentTime); |
| 8391 | animating = true; |
| 8392 | } |
| 8393 | transformation.clear(); |
| 8394 | final boolean more = animation.getTransformation( |
| 8395 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8396 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8397 | TAG, "Stepped animation in " + this + |
| 8398 | ": more=" + more + ", xform=" + transformation); |
| 8399 | if (more) { |
| 8400 | // we're done! |
| 8401 | hasTransformation = true; |
| 8402 | return true; |
| 8403 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8404 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8405 | TAG, "Finished animation in " + this + |
| 8406 | " @ " + currentTime); |
| 8407 | animation = null; |
| 8408 | } |
| 8409 | } else if (animation != null) { |
| 8410 | // If the display is frozen, and there is a pending animation, |
| 8411 | // clear it and make sure we run the cleanup code. |
| 8412 | animating = true; |
| 8413 | animation = null; |
| 8414 | } |
| 8415 | |
| 8416 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8418 | if (!animating) { |
| 8419 | return false; |
| 8420 | } |
| 8421 | |
| 8422 | clearAnimation(); |
| 8423 | animating = false; |
| 8424 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8425 | moveInputMethodWindowsIfNeededLocked(true); |
| 8426 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8427 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8428 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8429 | TAG, "Animation done in " + this |
| 8430 | + ": reportedVisible=" + reportedVisible); |
| 8431 | |
| 8432 | transformation.clear(); |
| 8433 | if (animLayerAdjustment != 0) { |
| 8434 | animLayerAdjustment = 0; |
| 8435 | updateLayers(); |
| 8436 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8438 | final int N = windows.size(); |
| 8439 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8440 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8441 | } |
| 8442 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8444 | return false; |
| 8445 | } |
| 8446 | |
| 8447 | void updateReportedVisibilityLocked() { |
| 8448 | if (appToken == null) { |
| 8449 | return; |
| 8450 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8452 | int numInteresting = 0; |
| 8453 | int numVisible = 0; |
| 8454 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8455 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8456 | 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] | 8457 | final int N = allAppWindows.size(); |
| 8458 | for (int i=0; i<N; i++) { |
| 8459 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8460 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8461 | || win.mViewVisibility != View.VISIBLE |
Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8462 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8463 | || win.mDestroying) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8464 | continue; |
| 8465 | } |
| 8466 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8467 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8468 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8469 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8470 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8471 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8472 | + " pv=" + win.mPolicyVisibility |
| 8473 | + " dp=" + win.mDrawPending |
| 8474 | + " cdp=" + win.mCommitDrawPending |
| 8475 | + " ah=" + win.mAttachedHidden |
| 8476 | + " th=" |
| 8477 | + (win.mAppToken != null |
| 8478 | ? win.mAppToken.hiddenRequested : false) |
| 8479 | + " a=" + win.mAnimating); |
| 8480 | } |
| 8481 | } |
| 8482 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8483 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8484 | if (!win.isAnimating()) { |
| 8485 | numVisible++; |
| 8486 | } |
| 8487 | nowGone = false; |
| 8488 | } else if (win.isAnimating()) { |
| 8489 | nowGone = false; |
| 8490 | } |
| 8491 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8494 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8495 | + numInteresting + " visible=" + numVisible); |
| 8496 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8497 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8498 | TAG, "Visibility changed in " + this |
| 8499 | + ": vis=" + nowVisible); |
| 8500 | reportedVisible = nowVisible; |
| 8501 | Message m = mH.obtainMessage( |
| 8502 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8503 | nowVisible ? 1 : 0, |
| 8504 | nowGone ? 1 : 0, |
| 8505 | this); |
| 8506 | mH.sendMessage(m); |
| 8507 | } |
| 8508 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8509 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8510 | WindowState findMainWindow() { |
| 8511 | int j = windows.size(); |
| 8512 | while (j > 0) { |
| 8513 | j--; |
| 8514 | WindowState win = windows.get(j); |
| 8515 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8516 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8517 | return win; |
| 8518 | } |
| 8519 | } |
| 8520 | return null; |
| 8521 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8522 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8523 | void dump(PrintWriter pw, String prefix) { |
| 8524 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8525 | if (appToken != null) { |
| 8526 | pw.print(prefix); pw.println("app=true"); |
| 8527 | } |
| 8528 | if (allAppWindows.size() > 0) { |
| 8529 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8530 | } |
| 8531 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8532 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8533 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8534 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8535 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8536 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8537 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8538 | if (paused || freezingScreen) { |
| 8539 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8540 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8541 | } |
| 8542 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8543 | || inPendingTransaction || allDrawn) { |
| 8544 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8545 | pw.print(numInterestingWindows); |
| 8546 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8547 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8548 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8549 | } |
| 8550 | if (animating || animation != null) { |
| 8551 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8552 | pw.print(" animation="); pw.println(animation); |
| 8553 | } |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8554 | if (hasTransformation) { |
| 8555 | pw.print(prefix); pw.print("XForm: "); |
| 8556 | transformation.printShortString(pw); |
| 8557 | pw.println(); |
| 8558 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8559 | if (animLayerAdjustment != 0) { |
| 8560 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8561 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8562 | if (startingData != null || removed || firstWindowDrawn) { |
| 8563 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8564 | pw.print(" removed="); pw.print(removed); |
| 8565 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8566 | } |
| 8567 | if (startingWindow != null || startingView != null |
| 8568 | || startingDisplayed || startingMoved) { |
| 8569 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8570 | pw.print(" startingView="); pw.print(startingView); |
| 8571 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8572 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8573 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8574 | } |
| 8575 | |
| 8576 | @Override |
| 8577 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8578 | if (stringName == null) { |
| 8579 | StringBuilder sb = new StringBuilder(); |
| 8580 | sb.append("AppWindowToken{"); |
| 8581 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8582 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8583 | stringName = sb.toString(); |
| 8584 | } |
| 8585 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8586 | } |
| 8587 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8589 | // ------------------------------------------------------------- |
| 8590 | // DummyAnimation |
| 8591 | // ------------------------------------------------------------- |
| 8592 | |
| 8593 | // This is an animation that does nothing: it just immediately finishes |
| 8594 | // itself every time it is called. It is used as a stub animation in cases |
| 8595 | // where we want to synchronize multiple things that may be animating. |
| 8596 | static final class DummyAnimation extends Animation { |
| 8597 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8598 | return false; |
| 8599 | } |
| 8600 | } |
| 8601 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8603 | // ------------------------------------------------------------- |
| 8604 | // Async Handler |
| 8605 | // ------------------------------------------------------------- |
| 8606 | |
| 8607 | static final class StartingData { |
| 8608 | final String pkg; |
| 8609 | final int theme; |
| 8610 | final CharSequence nonLocalizedLabel; |
| 8611 | final int labelRes; |
| 8612 | final int icon; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8613 | final int windowFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8615 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8616 | int _labelRes, int _icon, int _windowFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8617 | pkg = _pkg; |
| 8618 | theme = _theme; |
| 8619 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8620 | labelRes = _labelRes; |
| 8621 | icon = _icon; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8622 | windowFlags = _windowFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8623 | } |
| 8624 | } |
| 8625 | |
| 8626 | private final class H extends Handler { |
| 8627 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8628 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8629 | public static final int ANIMATE = 4; |
| 8630 | public static final int ADD_STARTING = 5; |
| 8631 | public static final int REMOVE_STARTING = 6; |
| 8632 | public static final int FINISHED_STARTING = 7; |
| 8633 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8634 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8635 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8636 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8637 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8638 | public static final int FORCE_GC = 15; |
| 8639 | public static final int ENABLE_SCREEN = 16; |
| 8640 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8641 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8642 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8643 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8644 | public static final int DRAG_END_TIMEOUT = 21; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8646 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8648 | public H() { |
| 8649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8651 | @Override |
| 8652 | public void handleMessage(Message msg) { |
| 8653 | switch (msg.what) { |
| 8654 | case REPORT_FOCUS_CHANGE: { |
| 8655 | WindowState lastFocus; |
| 8656 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8658 | synchronized(mWindowMap) { |
| 8659 | lastFocus = mLastFocus; |
| 8660 | newFocus = mCurrentFocus; |
| 8661 | if (lastFocus == newFocus) { |
| 8662 | // Focus is not changing, so nothing to do. |
| 8663 | return; |
| 8664 | } |
| 8665 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8666 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8667 | // + " to " + newFocus); |
| 8668 | if (newFocus != null && lastFocus != null |
| 8669 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8670 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8671 | mLosingFocus.add(lastFocus); |
| 8672 | lastFocus = null; |
| 8673 | } |
| 8674 | } |
| 8675 | |
| 8676 | if (lastFocus != newFocus) { |
| 8677 | //System.out.println("Changing focus from " + lastFocus |
| 8678 | // + " to " + newFocus); |
| 8679 | if (newFocus != null) { |
| 8680 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8681 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8682 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8683 | } catch (RemoteException e) { |
| 8684 | // Ignore if process has died. |
| 8685 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8686 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8687 | } |
| 8688 | |
| 8689 | if (lastFocus != null) { |
| 8690 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8691 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8692 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8693 | } catch (RemoteException e) { |
| 8694 | // Ignore if process has died. |
| 8695 | } |
| 8696 | } |
| 8697 | } |
| 8698 | } break; |
| 8699 | |
| 8700 | case REPORT_LOSING_FOCUS: { |
| 8701 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8703 | synchronized(mWindowMap) { |
| 8704 | losers = mLosingFocus; |
| 8705 | mLosingFocus = new ArrayList<WindowState>(); |
| 8706 | } |
| 8707 | |
| 8708 | final int N = losers.size(); |
| 8709 | for (int i=0; i<N; i++) { |
| 8710 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8711 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8712 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8713 | } catch (RemoteException e) { |
| 8714 | // Ignore if process has died. |
| 8715 | } |
| 8716 | } |
| 8717 | } break; |
| 8718 | |
| 8719 | case ANIMATE: { |
| 8720 | synchronized(mWindowMap) { |
| 8721 | mAnimationPending = false; |
| 8722 | performLayoutAndPlaceSurfacesLocked(); |
| 8723 | } |
| 8724 | } break; |
| 8725 | |
| 8726 | case ADD_STARTING: { |
| 8727 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8728 | final StartingData sd = wtoken.startingData; |
| 8729 | |
| 8730 | if (sd == null) { |
| 8731 | // Animation has been canceled... do nothing. |
| 8732 | return; |
| 8733 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8734 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8735 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8736 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8738 | View view = null; |
| 8739 | try { |
| 8740 | view = mPolicy.addStartingWindow( |
| 8741 | wtoken.token, sd.pkg, |
| 8742 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8743 | sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8744 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8745 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8746 | } |
| 8747 | |
| 8748 | if (view != null) { |
| 8749 | boolean abort = false; |
| 8750 | |
| 8751 | synchronized(mWindowMap) { |
| 8752 | if (wtoken.removed || wtoken.startingData == null) { |
| 8753 | // If the window was successfully added, then |
| 8754 | // we need to remove it. |
| 8755 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8756 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8757 | "Aborted starting " + wtoken |
| 8758 | + ": removed=" + wtoken.removed |
| 8759 | + " startingData=" + wtoken.startingData); |
| 8760 | wtoken.startingWindow = null; |
| 8761 | wtoken.startingData = null; |
| 8762 | abort = true; |
| 8763 | } |
| 8764 | } else { |
| 8765 | wtoken.startingView = view; |
| 8766 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8767 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8768 | "Added starting " + wtoken |
| 8769 | + ": startingWindow=" |
| 8770 | + wtoken.startingWindow + " startingView=" |
| 8771 | + wtoken.startingView); |
| 8772 | } |
| 8773 | |
| 8774 | if (abort) { |
| 8775 | try { |
| 8776 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8777 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8778 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8779 | } |
| 8780 | } |
| 8781 | } |
| 8782 | } break; |
| 8783 | |
| 8784 | case REMOVE_STARTING: { |
| 8785 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8786 | IBinder token = null; |
| 8787 | View view = null; |
| 8788 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8789 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8790 | + wtoken + ": startingWindow=" |
| 8791 | + wtoken.startingWindow + " startingView=" |
| 8792 | + wtoken.startingView); |
| 8793 | if (wtoken.startingWindow != null) { |
| 8794 | view = wtoken.startingView; |
| 8795 | token = wtoken.token; |
| 8796 | wtoken.startingData = null; |
| 8797 | wtoken.startingView = null; |
| 8798 | wtoken.startingWindow = null; |
| 8799 | } |
| 8800 | } |
| 8801 | if (view != null) { |
| 8802 | try { |
| 8803 | mPolicy.removeStartingWindow(token, view); |
| 8804 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8805 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8806 | } |
| 8807 | } |
| 8808 | } break; |
| 8809 | |
| 8810 | case FINISHED_STARTING: { |
| 8811 | IBinder token = null; |
| 8812 | View view = null; |
| 8813 | while (true) { |
| 8814 | synchronized (mWindowMap) { |
| 8815 | final int N = mFinishedStarting.size(); |
| 8816 | if (N <= 0) { |
| 8817 | break; |
| 8818 | } |
| 8819 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8820 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8821 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8822 | "Finished starting " + wtoken |
| 8823 | + ": startingWindow=" + wtoken.startingWindow |
| 8824 | + " startingView=" + wtoken.startingView); |
| 8825 | |
| 8826 | if (wtoken.startingWindow == null) { |
| 8827 | continue; |
| 8828 | } |
| 8829 | |
| 8830 | view = wtoken.startingView; |
| 8831 | token = wtoken.token; |
| 8832 | wtoken.startingData = null; |
| 8833 | wtoken.startingView = null; |
| 8834 | wtoken.startingWindow = null; |
| 8835 | } |
| 8836 | |
| 8837 | try { |
| 8838 | mPolicy.removeStartingWindow(token, view); |
| 8839 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8840 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8841 | } |
| 8842 | } |
| 8843 | } break; |
| 8844 | |
| 8845 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8846 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8847 | |
| 8848 | boolean nowVisible = msg.arg1 != 0; |
| 8849 | boolean nowGone = msg.arg2 != 0; |
| 8850 | |
| 8851 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8852 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8853 | TAG, "Reporting visible in " + wtoken |
| 8854 | + " visible=" + nowVisible |
| 8855 | + " gone=" + nowGone); |
| 8856 | if (nowVisible) { |
| 8857 | wtoken.appToken.windowsVisible(); |
| 8858 | } else { |
| 8859 | wtoken.appToken.windowsGone(); |
| 8860 | } |
| 8861 | } catch (RemoteException ex) { |
| 8862 | } |
| 8863 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8865 | case WINDOW_FREEZE_TIMEOUT: { |
| 8866 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8867 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8868 | int i = mWindows.size(); |
| 8869 | while (i > 0) { |
| 8870 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8871 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8872 | if (w.mOrientationChanging) { |
| 8873 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8874 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8875 | } |
| 8876 | } |
| 8877 | performLayoutAndPlaceSurfacesLocked(); |
| 8878 | } |
| 8879 | break; |
| 8880 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8882 | case HOLD_SCREEN_CHANGED: { |
| 8883 | Session oldHold; |
| 8884 | Session newHold; |
| 8885 | synchronized (mWindowMap) { |
| 8886 | oldHold = mLastReportedHold; |
| 8887 | newHold = (Session)msg.obj; |
| 8888 | mLastReportedHold = newHold; |
| 8889 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8890 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8891 | if (oldHold != newHold) { |
| 8892 | try { |
| 8893 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8894 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8895 | "window", |
| 8896 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8897 | } |
| 8898 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8899 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8900 | "window", |
| 8901 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8902 | } |
| 8903 | } catch (RemoteException e) { |
| 8904 | } |
| 8905 | } |
| 8906 | break; |
| 8907 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8909 | case APP_TRANSITION_TIMEOUT: { |
| 8910 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8911 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8912 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8913 | "*** APP TRANSITION TIMEOUT"); |
| 8914 | mAppTransitionReady = true; |
| 8915 | mAppTransitionTimeout = true; |
| 8916 | performLayoutAndPlaceSurfacesLocked(); |
| 8917 | } |
| 8918 | } |
| 8919 | break; |
| 8920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8922 | case PERSIST_ANIMATION_SCALE: { |
| 8923 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8924 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8925 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8926 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8927 | break; |
| 8928 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8930 | case FORCE_GC: { |
| 8931 | synchronized(mWindowMap) { |
| 8932 | if (mAnimationPending) { |
| 8933 | // If we are animating, don't do the gc now but |
| 8934 | // delay a bit so we don't interrupt the animation. |
| 8935 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8936 | 2000); |
| 8937 | return; |
| 8938 | } |
| 8939 | // If we are currently rotating the display, it will |
| 8940 | // schedule a new message when done. |
| 8941 | if (mDisplayFrozen) { |
| 8942 | return; |
| 8943 | } |
| 8944 | mFreezeGcPending = 0; |
| 8945 | } |
| 8946 | Runtime.getRuntime().gc(); |
| 8947 | break; |
| 8948 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8950 | case ENABLE_SCREEN: { |
| 8951 | performEnableScreen(); |
| 8952 | break; |
| 8953 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8954 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8955 | case APP_FREEZE_TIMEOUT: { |
| 8956 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8957 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8958 | int i = mAppTokens.size(); |
| 8959 | while (i > 0) { |
| 8960 | i--; |
| 8961 | AppWindowToken tok = mAppTokens.get(i); |
| 8962 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8963 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8964 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8965 | } |
| 8966 | } |
| 8967 | } |
| 8968 | break; |
| 8969 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8970 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8971 | case SEND_NEW_CONFIGURATION: { |
| 8972 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8973 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8974 | break; |
| 8975 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8976 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8977 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8978 | if (mWindowsChanged) { |
| 8979 | synchronized (mWindowMap) { |
| 8980 | mWindowsChanged = false; |
| 8981 | } |
| 8982 | notifyWindowsChanged(); |
| 8983 | } |
| 8984 | break; |
| 8985 | } |
| 8986 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8987 | case DRAG_START_TIMEOUT: { |
| 8988 | IBinder win = (IBinder)msg.obj; |
| 8989 | if (DEBUG_DRAG) { |
| 8990 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 8991 | } |
| 8992 | synchronized (mWindowMap) { |
| 8993 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 8994 | if (mDragState != null) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8995 | mDragState.unregister(); |
| 8996 | mInputMonitor.updateInputWindowsLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8997 | mDragState.reset(); |
| 8998 | mDragState = null; |
| 8999 | } |
| 9000 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9001 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9002 | } |
| 9003 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9004 | case DRAG_END_TIMEOUT: { |
| 9005 | IBinder win = (IBinder)msg.obj; |
| 9006 | if (DEBUG_DRAG) { |
| 9007 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 9008 | } |
| 9009 | synchronized (mWindowMap) { |
| 9010 | // !!! TODO: ANR the drag-receiving app |
| 9011 | mDragState.mDragResult = false; |
| 9012 | mDragState.endDragLw(); |
| 9013 | } |
| 9014 | break; |
| 9015 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9016 | } |
| 9017 | } |
| 9018 | } |
| 9019 | |
| 9020 | // ------------------------------------------------------------- |
| 9021 | // IWindowManager API |
| 9022 | // ------------------------------------------------------------- |
| 9023 | |
| 9024 | public IWindowSession openSession(IInputMethodClient client, |
| 9025 | IInputContext inputContext) { |
| 9026 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9027 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9028 | Session session = new Session(client, inputContext); |
| 9029 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9030 | } |
| 9031 | |
| 9032 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9033 | synchronized (mWindowMap) { |
| 9034 | // The focus for the client is the window immediately below |
| 9035 | // where we would place the input method window. |
| 9036 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9037 | WindowState imFocus; |
| 9038 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9039 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9040 | if (imFocus != null) { |
| 9041 | if (imFocus.mSession.mClient != null && |
| 9042 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9043 | return true; |
| 9044 | } |
| 9045 | } |
| 9046 | } |
| 9047 | } |
| 9048 | return false; |
| 9049 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9051 | // ------------------------------------------------------------- |
| 9052 | // Internals |
| 9053 | // ------------------------------------------------------------- |
| 9054 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9055 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9056 | boolean throwOnError) { |
| 9057 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9058 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9059 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9060 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9061 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9062 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9063 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9064 | TAG, "Looking up client " + client + ": " + win); |
| 9065 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9066 | RuntimeException ex = new IllegalArgumentException( |
| 9067 | "Requested window " + client + " does not exist"); |
| 9068 | if (throwOnError) { |
| 9069 | throw ex; |
| 9070 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9071 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9072 | return null; |
| 9073 | } |
| 9074 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9075 | RuntimeException ex = new IllegalArgumentException( |
| 9076 | "Requested window " + client + " is in session " + |
| 9077 | win.mSession + ", not " + session); |
| 9078 | if (throwOnError) { |
| 9079 | throw ex; |
| 9080 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9081 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9082 | return null; |
| 9083 | } |
| 9084 | |
| 9085 | return win; |
| 9086 | } |
| 9087 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9088 | final void rebuildAppWindowListLocked() { |
| 9089 | int NW = mWindows.size(); |
| 9090 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9091 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9092 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9093 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9094 | // First remove all existing app windows. |
| 9095 | i=0; |
| 9096 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9097 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9098 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9099 | WindowState win = mWindows.remove(i); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9100 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9101 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9102 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9103 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9104 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9105 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9106 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9107 | && lastWallpaper == i-1) { |
| 9108 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9109 | } |
| 9110 | i++; |
| 9111 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9112 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9113 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9114 | // so skip them before adding app tokens. |
| 9115 | lastWallpaper++; |
| 9116 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9117 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9118 | // First add all of the exiting app tokens... these are no longer |
| 9119 | // in the main app list, but still have windows shown. We put them |
| 9120 | // in the back because now that the animation is over we no longer |
| 9121 | // will care about them. |
| 9122 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9123 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9124 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9125 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9126 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9127 | // And add in the still active app tokens in Z order. |
| 9128 | NT = mAppTokens.size(); |
| 9129 | for (int j=0; j<NT; j++) { |
| 9130 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9131 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9132 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9133 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9134 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9135 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9136 | + " windows but added " + i); |
| 9137 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9138 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9140 | private final void assignLayersLocked() { |
| 9141 | int N = mWindows.size(); |
| 9142 | int curBaseLayer = 0; |
| 9143 | int curLayer = 0; |
| 9144 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9145 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9146 | if (DEBUG_LAYERS) { |
| 9147 | RuntimeException here = new RuntimeException("here"); |
| 9148 | here.fillInStackTrace(); |
| 9149 | Log.v(TAG, "Assigning layers", here); |
| 9150 | } |
| 9151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9153 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9154 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9155 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9156 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9157 | w.mLayer = curLayer; |
| 9158 | } else { |
| 9159 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9160 | w.mLayer = curLayer; |
| 9161 | } |
| 9162 | if (w.mTargetAppToken != null) { |
| 9163 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9164 | } else if (w.mAppToken != null) { |
| 9165 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9166 | } else { |
| 9167 | w.mAnimLayer = w.mLayer; |
| 9168 | } |
| 9169 | if (w.mIsImWindow) { |
| 9170 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9171 | } else if (w.mIsWallpaper) { |
| 9172 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9173 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9174 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9175 | + w.mAnimLayer); |
| 9176 | //System.out.println( |
| 9177 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9178 | } |
| 9179 | } |
| 9180 | |
| 9181 | private boolean mInLayout = false; |
| 9182 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9183 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9184 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9185 | throw new RuntimeException("Recursive call!"); |
| 9186 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9187 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9188 | return; |
| 9189 | } |
| 9190 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9191 | if (mWaitingForConfig) { |
| 9192 | // Our configuration has changed (most likely rotation), but we |
| 9193 | // don't yet have the complete configuration to report to |
| 9194 | // applications. Don't do any window layout until we have it. |
| 9195 | return; |
| 9196 | } |
| 9197 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9198 | if (mDisplay == null) { |
| 9199 | // Not yet initialized, nothing to do. |
| 9200 | return; |
| 9201 | } |
| 9202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9203 | boolean recoveringMemory = false; |
| 9204 | if (mForceRemoves != null) { |
| 9205 | recoveringMemory = true; |
| 9206 | // Wait a little it for things to settle down, and off we go. |
| 9207 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9208 | WindowState ws = mForceRemoves.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9209 | Slog.i(TAG, "Force removing: " + ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9210 | removeWindowInnerLocked(ws.mSession, ws); |
| 9211 | } |
| 9212 | mForceRemoves = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9213 | 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] | 9214 | Object tmp = new Object(); |
| 9215 | synchronized (tmp) { |
| 9216 | try { |
| 9217 | tmp.wait(250); |
| 9218 | } catch (InterruptedException e) { |
| 9219 | } |
| 9220 | } |
| 9221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9223 | mInLayout = true; |
| 9224 | try { |
| 9225 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9227 | int i = mPendingRemove.size()-1; |
| 9228 | if (i >= 0) { |
| 9229 | while (i >= 0) { |
| 9230 | WindowState w = mPendingRemove.get(i); |
| 9231 | removeWindowInnerLocked(w.mSession, w); |
| 9232 | i--; |
| 9233 | } |
| 9234 | mPendingRemove.clear(); |
| 9235 | |
| 9236 | mInLayout = false; |
| 9237 | assignLayersLocked(); |
| 9238 | mLayoutNeeded = true; |
| 9239 | performLayoutAndPlaceSurfacesLocked(); |
| 9240 | |
| 9241 | } else { |
| 9242 | mInLayout = false; |
| 9243 | if (mLayoutNeeded) { |
| 9244 | requestAnimationLocked(0); |
| 9245 | } |
| 9246 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9247 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9248 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 9249 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9250 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9251 | } catch (RuntimeException e) { |
| 9252 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9253 | 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] | 9254 | } |
| 9255 | } |
| 9256 | |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9257 | private final int performLayoutLockedInner(boolean initial) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9258 | if (!mLayoutNeeded) { |
| 9259 | return 0; |
| 9260 | } |
| 9261 | |
| 9262 | mLayoutNeeded = false; |
| 9263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9264 | final int dw = mDisplay.getWidth(); |
| 9265 | final int dh = mDisplay.getHeight(); |
| 9266 | |
| 9267 | final int N = mWindows.size(); |
| 9268 | int i; |
| 9269 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9270 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9271 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9272 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9273 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9274 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9275 | int seq = mLayoutSeq+1; |
| 9276 | if (seq < 0) seq = 0; |
| 9277 | mLayoutSeq = seq; |
| 9278 | |
| 9279 | // First perform layout of any root windows (not attached |
| 9280 | // to another window). |
| 9281 | int topAttached = -1; |
| 9282 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9283 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9284 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9285 | // Don't do layout of a window if it is not visible, or |
| 9286 | // soon won't be visible, to avoid wasting time and funky |
| 9287 | // changes while a window is animating away. |
| 9288 | final AppWindowToken atoken = win.mAppToken; |
| 9289 | final boolean gone = win.mViewVisibility == View.GONE |
| 9290 | || !win.mRelayoutCalled |
| 9291 | || win.mRootToken.hidden |
| 9292 | || (atoken != null && atoken.hiddenRequested) |
| 9293 | || win.mAttachedHidden |
| 9294 | || win.mExiting || win.mDestroying; |
| 9295 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9296 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 9297 | Slog.v(TAG, "First pass " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9298 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9299 | + " mLayoutAttached=" + win.mLayoutAttached); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9300 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9301 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9302 | + win.mRelayoutCalled + " hidden=" |
| 9303 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9304 | + (atoken != null && atoken.hiddenRequested) |
| 9305 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9306 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9307 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9308 | // If this view is GONE, then skip it -- keep the current |
| 9309 | // frame, and let the caller know so they can ignore it |
| 9310 | // if they want. (We do the normal layout for INVISIBLE |
| 9311 | // windows, since that means "perform layout as normal, |
| 9312 | // just don't display"). |
| 9313 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9314 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9315 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9316 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9317 | win.mContentChanged = false; |
| 9318 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9319 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9320 | win.mLayoutSeq = seq; |
| 9321 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9322 | + win.mFrame + " mContainingFrame=" |
| 9323 | + win.mContainingFrame + " mDisplayFrame=" |
| 9324 | + win.mDisplayFrame); |
| 9325 | } else { |
| 9326 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9327 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9328 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9329 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9330 | |
| 9331 | // Now perform layout of attached windows, which usually |
| 9332 | // depend on the position of the window they are attached to. |
| 9333 | // XXX does not deal with windows that are attached to windows |
| 9334 | // that are themselves attached. |
| 9335 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9336 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9337 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9338 | if (win.mLayoutAttached) { |
| 9339 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9340 | + " mHaveFrame=" + win.mHaveFrame |
| 9341 | + " mViewVisibility=" + win.mViewVisibility |
| 9342 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9343 | // If this view is GONE, then skip it -- keep the current |
| 9344 | // frame, and let the caller know so they can ignore it |
| 9345 | // if they want. (We do the normal layout for INVISIBLE |
| 9346 | // windows, since that means "perform layout as normal, |
| 9347 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9348 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9349 | || !win.mHaveFrame) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9350 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9351 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9352 | win.mContentChanged = false; |
| 9353 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9354 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9355 | win.mLayoutSeq = seq; |
| 9356 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9357 | + win.mFrame + " mContainingFrame=" |
| 9358 | + win.mContainingFrame + " mDisplayFrame=" |
| 9359 | + win.mDisplayFrame); |
| 9360 | } |
| 9361 | } |
| 9362 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9363 | |
| 9364 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9365 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9366 | |
| 9367 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9368 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9369 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9370 | // "Something has changed! Let's make it correct now." |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9371 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9372 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9373 | if (mDisplay == null) { |
| 9374 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9375 | return; |
| 9376 | } |
| 9377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9378 | final long currentTime = SystemClock.uptimeMillis(); |
| 9379 | final int dw = mDisplay.getWidth(); |
| 9380 | final int dh = mDisplay.getHeight(); |
| 9381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9382 | int i; |
| 9383 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9384 | if (mFocusMayChange) { |
| 9385 | mFocusMayChange = false; |
| 9386 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9387 | } |
| 9388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9389 | // Initialize state of exiting tokens. |
| 9390 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9391 | mExitingTokens.get(i).hasVisible = false; |
| 9392 | } |
| 9393 | |
| 9394 | // Initialize state of exiting applications. |
| 9395 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9396 | mExitingAppTokens.get(i).hasVisible = false; |
| 9397 | } |
| 9398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9399 | boolean orientationChangeComplete = true; |
| 9400 | Session holdScreen = null; |
| 9401 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9402 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9403 | boolean focusDisplayed = false; |
| 9404 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9405 | boolean createWatermark = false; |
| 9406 | |
| 9407 | if (mFxSession == null) { |
| 9408 | mFxSession = new SurfaceSession(); |
| 9409 | createWatermark = true; |
| 9410 | } |
| 9411 | |
| 9412 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9413 | |
| 9414 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9415 | |
| 9416 | if (createWatermark) { |
| 9417 | createWatermark(); |
| 9418 | } |
| 9419 | if (mWatermark != null) { |
| 9420 | mWatermark.positionSurface(dw, dh); |
| 9421 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9422 | if (mStrictModeFlash != null) { |
| 9423 | mStrictModeFlash.positionSurface(dw, dh); |
| 9424 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9426 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9427 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9428 | int repeats = 0; |
| 9429 | int changes = 0; |
| 9430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9431 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9432 | repeats++; |
| 9433 | if (repeats > 6) { |
| 9434 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9435 | mLayoutNeeded = false; |
| 9436 | break; |
| 9437 | } |
| 9438 | |
| 9439 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9440 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9441 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9442 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9443 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9444 | assignLayersLocked(); |
| 9445 | mLayoutNeeded = true; |
| 9446 | } |
| 9447 | } |
| 9448 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9449 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9450 | if (updateOrientationFromAppTokensLocked()) { |
| 9451 | mLayoutNeeded = true; |
| 9452 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9453 | } |
| 9454 | } |
| 9455 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9456 | mLayoutNeeded = true; |
| 9457 | } |
| 9458 | } |
| 9459 | |
| 9460 | // FIRST LOOP: Perform a layout, if needed. |
| 9461 | if (repeats < 4) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9462 | changes = performLayoutLockedInner(repeats == 0); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9463 | if (changes != 0) { |
| 9464 | continue; |
| 9465 | } |
| 9466 | } else { |
| 9467 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9468 | changes = 0; |
| 9469 | } |
| 9470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9471 | final int transactionSequence = ++mTransactionSequence; |
| 9472 | |
| 9473 | // Update animations of all applications, including those |
| 9474 | // associated with exiting/removed apps |
| 9475 | boolean tokensAnimating = false; |
| 9476 | final int NAT = mAppTokens.size(); |
| 9477 | for (i=0; i<NAT; i++) { |
| 9478 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9479 | tokensAnimating = true; |
| 9480 | } |
| 9481 | } |
| 9482 | final int NEAT = mExitingAppTokens.size(); |
| 9483 | for (i=0; i<NEAT; i++) { |
| 9484 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9485 | tokensAnimating = true; |
| 9486 | } |
| 9487 | } |
| 9488 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9489 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9490 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9491 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9492 | + transactionSequence + " tokensAnimating=" |
| 9493 | + tokensAnimating); |
| 9494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9495 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9496 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9497 | if (mScreenRotationAnimation != null) { |
| 9498 | if (mScreenRotationAnimation.isAnimating()) { |
| 9499 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 9500 | animating = true; |
| 9501 | } else { |
| 9502 | mScreenRotationAnimation = null; |
| 9503 | } |
| 9504 | } |
| 9505 | } |
| 9506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9507 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9508 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9509 | boolean forceHiding = false; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9510 | WindowState windowDetachedWallpaper = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9511 | |
| 9512 | mPolicy.beginAnimationLw(dw, dh); |
| 9513 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9514 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9516 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9517 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9518 | |
| 9519 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9520 | |
| 9521 | if (w.mSurface != null) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9522 | // Take care of the window being ready to display. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9523 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9524 | if ((w.mAttrs.flags |
| 9525 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9526 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9527 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9528 | wallpaperMayChange = true; |
| 9529 | } |
| 9530 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9531 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9532 | final boolean wasAnimating = w.mAnimating; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9533 | |
| 9534 | int animDw = dw; |
| 9535 | int animDh = dh; |
| 9536 | |
| 9537 | // If the window has moved due to its containing |
| 9538 | // content frame changing, then we'd like to animate |
| 9539 | // it. The checks here are ordered by what is least |
Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 9540 | // likely to be true first. |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9541 | if (w.shouldAnimateMove()) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9542 | // Frame has moved, containing content frame |
| 9543 | // has also moved, and we're not currently animating... |
| 9544 | // let's do something. |
| 9545 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 9546 | com.android.internal.R.anim.window_move_from_decor); |
| 9547 | w.setAnimation(a); |
| 9548 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 9549 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 9550 | } |
| 9551 | |
| 9552 | // Execute animation. |
| 9553 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 9554 | animDw, animDh); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9555 | |
| 9556 | // If this window is animating, make a note that we have |
| 9557 | // an animating window and take care of a request to run |
| 9558 | // a detached wallpaper animation. |
| 9559 | if (nowAnimating) { |
| 9560 | if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) { |
| 9561 | windowDetachedWallpaper = w; |
| 9562 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9563 | animating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9564 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9565 | |
| 9566 | // If this window's app token is running a detached wallpaper |
| 9567 | // animation, make a note so we can ensure the wallpaper is |
| 9568 | // displayed behind it. |
| 9569 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 9570 | && w.mAppToken.animation.getDetachWallpaper()) { |
| 9571 | windowDetachedWallpaper = w; |
| 9572 | } |
| 9573 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9574 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9575 | wallpaperMayChange = true; |
| 9576 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9577 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9578 | if (mPolicy.doesForceHide(w, attrs)) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9579 | if (!wasAnimating && nowAnimating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9580 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9581 | "Animation started that could impact force hide: " |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9582 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9583 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9584 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9585 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9586 | forceHiding = true; |
| 9587 | } |
| 9588 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9589 | boolean changed; |
| 9590 | if (forceHiding) { |
| 9591 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9592 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9593 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9594 | } else { |
| 9595 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9596 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9597 | "Now policy shown: " + w); |
| 9598 | if (changed) { |
| 9599 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9600 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9601 | // Assume we will need to animate. If |
| 9602 | // we don't (because the wallpaper will |
| 9603 | // stay with the lock screen), then we will |
| 9604 | // clean up later. |
| 9605 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9606 | if (a != null) { |
| 9607 | w.setAnimation(a); |
| 9608 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9609 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9610 | if (mCurrentFocus == null || |
| 9611 | mCurrentFocus.mLayer < w.mLayer) { |
| 9612 | // We are showing on to of the current |
| 9613 | // focus, so re-evaluate focus to make |
| 9614 | // sure it is correct. |
| 9615 | mFocusMayChange = true; |
| 9616 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9617 | } |
| 9618 | } |
| 9619 | if (changed && (attrs.flags |
| 9620 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9621 | wallpaperMayChange = true; |
| 9622 | } |
| 9623 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9625 | mPolicy.animatingWindowLw(w, attrs); |
| 9626 | } |
| 9627 | |
| 9628 | final AppWindowToken atoken = w.mAppToken; |
| 9629 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9630 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9631 | atoken.lastTransactionSequence = transactionSequence; |
| 9632 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9633 | atoken.startingDisplayed = false; |
| 9634 | } |
| 9635 | if ((w.isOnScreen() || w.mAttrs.type |
| 9636 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9637 | && !w.mExiting && !w.mDestroying) { |
| 9638 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9639 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9640 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9641 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9642 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9643 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9644 | + " pv=" + w.mPolicyVisibility |
| 9645 | + " dp=" + w.mDrawPending |
| 9646 | + " cdp=" + w.mCommitDrawPending |
| 9647 | + " ah=" + w.mAttachedHidden |
| 9648 | + " th=" + atoken.hiddenRequested |
| 9649 | + " a=" + w.mAnimating); |
| 9650 | } |
| 9651 | } |
| 9652 | if (w != atoken.startingWindow) { |
| 9653 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9654 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9655 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9656 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9657 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9658 | "tokenMayBeDrawn: " + atoken |
| 9659 | + " freezingScreen=" + atoken.freezingScreen |
| 9660 | + " mAppFreezing=" + w.mAppFreezing); |
| 9661 | tokenMayBeDrawn = true; |
| 9662 | } |
| 9663 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9664 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9665 | atoken.startingDisplayed = true; |
| 9666 | } |
| 9667 | } |
| 9668 | } else if (w.mReadyToShow) { |
| 9669 | w.performShowLocked(); |
| 9670 | } |
| 9671 | } |
| 9672 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9673 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9674 | |
| 9675 | if (tokenMayBeDrawn) { |
| 9676 | // See if any windows have been drawn, so they (and others |
| 9677 | // associated with them) can now be shown. |
| 9678 | final int NT = mTokenList.size(); |
| 9679 | for (i=0; i<NT; i++) { |
| 9680 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9681 | if (wtoken == null) { |
| 9682 | continue; |
| 9683 | } |
| 9684 | if (wtoken.freezingScreen) { |
| 9685 | int numInteresting = wtoken.numInterestingWindows; |
| 9686 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9687 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9688 | "allDrawn: " + wtoken |
| 9689 | + " interesting=" + numInteresting |
| 9690 | + " drawn=" + wtoken.numDrawnWindows); |
| 9691 | wtoken.showAllWindowsLocked(); |
| 9692 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9693 | orientationChangeComplete = true; |
| 9694 | } |
| 9695 | } else if (!wtoken.allDrawn) { |
| 9696 | int numInteresting = wtoken.numInterestingWindows; |
| 9697 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9698 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9699 | "allDrawn: " + wtoken |
| 9700 | + " interesting=" + numInteresting |
| 9701 | + " drawn=" + wtoken.numDrawnWindows); |
| 9702 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9703 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9704 | |
| 9705 | // We can now show all of the drawn windows! |
| 9706 | if (!mOpeningApps.contains(wtoken)) { |
| 9707 | wtoken.showAllWindowsLocked(); |
| 9708 | } |
| 9709 | } |
| 9710 | } |
| 9711 | } |
| 9712 | } |
| 9713 | |
| 9714 | // If we are ready to perform an app transition, check through |
| 9715 | // all of the app tokens to be shown and see if they are ready |
| 9716 | // to go. |
| 9717 | if (mAppTransitionReady) { |
| 9718 | int NN = mOpeningApps.size(); |
| 9719 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9720 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9721 | "Checking " + NN + " opening apps (frozen=" |
| 9722 | + mDisplayFrozen + " timeout=" |
| 9723 | + mAppTransitionTimeout + ")..."); |
| 9724 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9725 | // If the display isn't frozen, wait to do anything until |
| 9726 | // all of the apps are ready. Otherwise just go because |
| 9727 | // we'll unfreeze the display when everyone is ready. |
| 9728 | for (i=0; i<NN && goodToGo; i++) { |
| 9729 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9730 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9731 | "Check opening app" + wtoken + ": allDrawn=" |
| 9732 | + wtoken.allDrawn + " startingDisplayed=" |
| 9733 | + wtoken.startingDisplayed); |
| 9734 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9735 | && !wtoken.startingMoved) { |
| 9736 | goodToGo = false; |
| 9737 | } |
| 9738 | } |
| 9739 | } |
| 9740 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9741 | 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] | 9742 | int transit = mNextAppTransition; |
| 9743 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9744 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9745 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9746 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9747 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9748 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9749 | mAppTransitionTimeout = false; |
| 9750 | mStartingIconInTransition = false; |
| 9751 | mSkipAppTransitionAnimation = false; |
| 9752 | |
| 9753 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9754 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9755 | // If there are applications waiting to come to the |
| 9756 | // top of the stack, now is the time to move their windows. |
| 9757 | // (Note that we don't do apps going to the bottom |
| 9758 | // here -- we want to keep their windows in the old |
| 9759 | // Z-order until the animation completes.) |
| 9760 | if (mToTopApps.size() > 0) { |
| 9761 | NN = mAppTokens.size(); |
| 9762 | for (i=0; i<NN; i++) { |
| 9763 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9764 | if (wtoken.sendingToTop) { |
| 9765 | wtoken.sendingToTop = false; |
| 9766 | moveAppWindowsLocked(wtoken, NN, false); |
| 9767 | } |
| 9768 | } |
| 9769 | mToTopApps.clear(); |
| 9770 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9771 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9772 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9773 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9774 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9775 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9776 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9777 | // The top-most window will supply the layout params, |
| 9778 | // and we will determine it below. |
| 9779 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9780 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9781 | int bestAnimLayer = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9782 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9783 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9784 | "New wallpaper target=" + mWallpaperTarget |
| 9785 | + ", lower target=" + mLowerWallpaperTarget |
| 9786 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9787 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9788 | // Do a first pass through the tokens for two |
| 9789 | // things: |
| 9790 | // (1) Determine if both the closing and opening |
| 9791 | // app token sets are wallpaper targets, in which |
| 9792 | // case special animations are needed |
| 9793 | // (since the wallpaper needs to stay static |
| 9794 | // behind them). |
| 9795 | // (2) Find the layout params of the top-most |
| 9796 | // application window in the tokens, which is |
| 9797 | // what will control the animation theme. |
| 9798 | final int NC = mClosingApps.size(); |
| 9799 | NN = NC + mOpeningApps.size(); |
| 9800 | for (i=0; i<NN; i++) { |
| 9801 | AppWindowToken wtoken; |
| 9802 | int mode; |
| 9803 | if (i < NC) { |
| 9804 | wtoken = mClosingApps.get(i); |
| 9805 | mode = 1; |
| 9806 | } else { |
| 9807 | wtoken = mOpeningApps.get(i-NC); |
| 9808 | mode = 2; |
| 9809 | } |
| 9810 | if (mLowerWallpaperTarget != null) { |
| 9811 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9812 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9813 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9814 | } |
| 9815 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9816 | if (wtoken.appFullscreen) { |
| 9817 | WindowState ws = wtoken.findMainWindow(); |
| 9818 | if (ws != null) { |
| 9819 | // If this is a compatibility mode |
| 9820 | // window, we will always use its anim. |
| 9821 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9822 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9823 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9824 | bestAnimLayer = Integer.MAX_VALUE; |
| 9825 | } else if (ws.mLayer > bestAnimLayer) { |
| 9826 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9827 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9828 | bestAnimLayer = ws.mLayer; |
| 9829 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9830 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9831 | } |
| 9832 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9833 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9834 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9835 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9836 | "Wallpaper animation!"); |
| 9837 | switch (transit) { |
| 9838 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9839 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9840 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9841 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9842 | break; |
| 9843 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9844 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9845 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9846 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9847 | break; |
| 9848 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9849 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9850 | "New transit: " + transit); |
| 9851 | } else if (oldWallpaper != null) { |
| 9852 | // We are transitioning from an activity with |
| 9853 | // a wallpaper to one without. |
| 9854 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9855 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9856 | "New transit away from wallpaper: " + transit); |
| 9857 | } else if (mWallpaperTarget != null) { |
| 9858 | // We are transitioning from an activity without |
| 9859 | // a wallpaper to now showing the wallpaper |
| 9860 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9861 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9862 | "New transit into wallpaper: " + transit); |
| 9863 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9864 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9865 | // If all closing windows are obscured, then there is |
| 9866 | // no need to do an animation. This is the case, for |
| 9867 | // example, when this transition is being done behind |
| 9868 | // the lock screen. |
| 9869 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9870 | animLp = null; |
| 9871 | } |
| 9872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9873 | NN = mOpeningApps.size(); |
| 9874 | for (i=0; i<NN; i++) { |
| 9875 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9876 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9877 | "Now opening app" + wtoken); |
| 9878 | wtoken.reportedVisible = false; |
| 9879 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9880 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9881 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9882 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9883 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9884 | wtoken.showAllWindowsLocked(); |
| 9885 | } |
| 9886 | NN = mClosingApps.size(); |
| 9887 | for (i=0; i<NN; i++) { |
| 9888 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9889 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9890 | "Now closing app" + wtoken); |
| 9891 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9892 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9893 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9894 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9895 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9896 | // Force the allDrawn flag, because we want to start |
| 9897 | // this guy's animations regardless of whether it's |
| 9898 | // gotten drawn. |
| 9899 | wtoken.allDrawn = true; |
| 9900 | } |
| 9901 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9902 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9904 | mOpeningApps.clear(); |
| 9905 | mClosingApps.clear(); |
| 9906 | |
| 9907 | // This has changed the visibility of windows, so perform |
| 9908 | // a new layout to get them all up-to-date. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9909 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9910 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9911 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9912 | assignLayersLocked(); |
| 9913 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9914 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9915 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9916 | } |
| 9917 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9918 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9919 | int adjResult = 0; |
| 9920 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9921 | if (!animating && mAppTransitionRunning) { |
| 9922 | // We have finished the animation of an app transition. To do |
| 9923 | // this, we have delayed a lot of operations like showing and |
| 9924 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9925 | // reflects the correct Z-order, but the window list may now |
| 9926 | // be out of sync with it. So here we will just rebuild the |
| 9927 | // entire app window list. Fun! |
| 9928 | mAppTransitionRunning = false; |
| 9929 | // Clear information about apps that were moving. |
| 9930 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9931 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9932 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9933 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9934 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9935 | moveInputMethodWindowsIfNeededLocked(false); |
| 9936 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9937 | // Since the window list has been rebuilt, focus might |
| 9938 | // have to be recomputed since the actual order of windows |
| 9939 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9940 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9941 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9942 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9943 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9944 | // At this point, there was a window with a wallpaper that |
| 9945 | // was force hiding other windows behind it, but now it |
| 9946 | // is going away. This may be simple -- just animate |
| 9947 | // away the wallpaper and its window -- or it may be |
| 9948 | // hard -- the wallpaper now needs to be shown behind |
| 9949 | // something that was hidden. |
| 9950 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9951 | if (mLowerWallpaperTarget != null |
| 9952 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9953 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9954 | "wallpaperForceHiding changed with lower=" |
| 9955 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9956 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9957 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9958 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9959 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9960 | // The lower target has become hidden before we |
| 9961 | // actually started the animation... let's completely |
| 9962 | // re-evaluate everything. |
| 9963 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9964 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9965 | } |
| 9966 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9967 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9968 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9969 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9970 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9971 | + " NEW: " + mWallpaperTarget |
| 9972 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9973 | if (mLowerWallpaperTarget == null) { |
| 9974 | // Whoops, we don't need a special wallpaper animation. |
| 9975 | // Clear them out. |
| 9976 | forceHiding = false; |
| 9977 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9978 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9979 | if (w.mSurface != null) { |
| 9980 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9981 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9982 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9983 | forceHiding = true; |
| 9984 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9985 | if (!w.mAnimating) { |
| 9986 | // We set the animation above so it |
| 9987 | // is not yet running. |
| 9988 | w.clearAnimation(); |
| 9989 | } |
| 9990 | } |
| 9991 | } |
| 9992 | } |
| 9993 | } |
| 9994 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9995 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9996 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 9997 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 9998 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 9999 | + windowDetachedWallpaper); |
| 10000 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 10001 | wallpaperMayChange = true; |
| 10002 | } |
| 10003 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10004 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10005 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10006 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10007 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10008 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10009 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10010 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10011 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10012 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10013 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10014 | assignLayersLocked(); |
| 10015 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10016 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10017 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10018 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10019 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10020 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10021 | if (mFocusMayChange) { |
| 10022 | mFocusMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10023 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10024 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10025 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10026 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10027 | } |
| 10028 | |
| 10029 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10030 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10031 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10032 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10033 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10034 | + Integer.toHexString(changes)); |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10035 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10036 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10037 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10038 | |
| 10039 | // THIRD LOOP: Update the surfaces of all windows. |
| 10040 | |
| 10041 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10042 | |
| 10043 | boolean obscured = false; |
| 10044 | boolean blurring = false; |
| 10045 | boolean dimming = false; |
| 10046 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10047 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10048 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10049 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10050 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10052 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10053 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10054 | |
| 10055 | boolean displayed = false; |
| 10056 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10057 | final int attrFlags = attrs.flags; |
| 10058 | |
| 10059 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10060 | // XXX NOTE: The logic here could be improved. We have |
| 10061 | // the decision about whether to resize a window separated |
| 10062 | // from whether to hide the surface. This can cause us to |
| 10063 | // resize a surface even if we are going to hide it. You |
| 10064 | // can see this by (1) holding device in landscape mode on |
| 10065 | // home screen; (2) tapping browser icon (device will rotate |
| 10066 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10067 | // in step 2 but then immediately hidden, causing us to |
| 10068 | // have to resize and then redraw it again in step 3. It |
| 10069 | // would be nice to figure out how to avoid this, but it is |
| 10070 | // difficult because we do need to resize surfaces in some |
| 10071 | // cases while they are hidden such as when first showing a |
| 10072 | // window. |
| 10073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10074 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10075 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10076 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10077 | + ": new=" + w.mShownFrame + ", old=" |
| 10078 | + w.mLastShownFrame); |
| 10079 | |
| 10080 | boolean resize; |
| 10081 | int width, height; |
| 10082 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 10083 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 10084 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 10085 | // for a scaled surface, we just want to use |
| 10086 | // the requested size. |
| 10087 | width = w.mRequestedWidth; |
| 10088 | height = w.mRequestedHeight; |
| 10089 | w.mLastRequestedWidth = width; |
| 10090 | w.mLastRequestedHeight = height; |
| 10091 | w.mLastShownFrame.set(w.mShownFrame); |
| 10092 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10093 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10094 | "POS " + w.mShownFrame.left |
| 10095 | + ", " + w.mShownFrame.top, null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10096 | w.mSurfaceX = w.mShownFrame.left; |
| 10097 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10098 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10099 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10100 | Slog.w(TAG, "Error positioning surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10101 | if (!recoveringMemory) { |
| 10102 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10103 | } |
| 10104 | } |
| 10105 | } else { |
| 10106 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 10107 | width = w.mShownFrame.width(); |
| 10108 | height = w.mShownFrame.height(); |
| 10109 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10110 | } |
| 10111 | |
| 10112 | if (resize) { |
| 10113 | if (width < 1) width = 1; |
| 10114 | if (height < 1) height = 1; |
| 10115 | if (w.mSurface != null) { |
| 10116 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10117 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10118 | "POS " + w.mShownFrame.left + "," |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10119 | + w.mShownFrame.top + " SIZE " |
| 10120 | + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10121 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10122 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10123 | w.mSurfaceW = width; |
| 10124 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10125 | w.mSurface.setSize(width, height); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10126 | w.mSurfaceX = w.mShownFrame.left; |
| 10127 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10128 | w.mSurface.setPosition(w.mShownFrame.left, |
| 10129 | w.mShownFrame.top); |
| 10130 | } catch (RuntimeException e) { |
| 10131 | // If something goes wrong with the surface (such |
| 10132 | // as running out of memory), don't take down the |
| 10133 | // entire system. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10134 | Slog.e(TAG, "Failure updating surface of " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10135 | + "size=(" + width + "x" + height |
| 10136 | + "), pos=(" + w.mShownFrame.left |
| 10137 | + "," + w.mShownFrame.top + ")", e); |
| 10138 | if (!recoveringMemory) { |
| 10139 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10140 | } |
| 10141 | } |
| 10142 | } |
| 10143 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10144 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10145 | w.mContentInsetsChanged = |
| 10146 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10147 | w.mVisibleInsetsChanged = |
| 10148 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10149 | boolean configChanged = |
| 10150 | w.mConfiguration != mCurConfiguration |
| 10151 | && (w.mConfiguration == null |
| 10152 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10153 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10154 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10155 | + mCurConfiguration); |
| 10156 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10157 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10158 | + ": configChanged=" + configChanged |
| 10159 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10160 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10161 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10162 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10163 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10164 | || configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10165 | w.mLastFrame.set(w.mFrame); |
| 10166 | w.mLastContentInsets.set(w.mContentInsets); |
| 10167 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10168 | // If the screen is currently frozen, then keep |
| 10169 | // it frozen until this window draws at its new |
| 10170 | // orientation. |
| 10171 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10172 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10173 | "Resizing while display frozen: " + w); |
| 10174 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10175 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10176 | mWindowsFreezingScreen = true; |
| 10177 | // XXX should probably keep timeout from |
| 10178 | // when we first froze the display. |
| 10179 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10180 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10181 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10182 | } |
| 10183 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10184 | // If the orientation is changing, then we need to |
| 10185 | // hold off on unfreezing the display until this |
| 10186 | // window has been redrawn; to do that, we need |
| 10187 | // to go through the process of getting informed |
| 10188 | // by the application when it has finished drawing. |
| 10189 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10190 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10191 | "Orientation start waiting for draw in " |
| 10192 | + w + ", surface " + w.mSurface); |
| 10193 | w.mDrawPending = true; |
| 10194 | w.mCommitDrawPending = false; |
| 10195 | w.mReadyToShow = false; |
| 10196 | if (w.mAppToken != null) { |
| 10197 | w.mAppToken.allDrawn = false; |
| 10198 | } |
| 10199 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10200 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10201 | "Resizing window " + w + " to " + w.mFrame); |
| 10202 | mResizingWindows.add(w); |
| 10203 | } else if (w.mOrientationChanging) { |
| 10204 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10205 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10206 | "Orientation not waiting for draw in " |
| 10207 | + w + ", surface " + w.mSurface); |
| 10208 | w.mOrientationChanging = false; |
| 10209 | } |
| 10210 | } |
| 10211 | } |
| 10212 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10213 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10214 | if (!w.mLastHidden) { |
| 10215 | //dump(); |
| 10216 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10217 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10218 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10219 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10220 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10221 | try { |
| 10222 | w.mSurface.hide(); |
| 10223 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10224 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10225 | } |
| 10226 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10227 | } |
| 10228 | // If we are waiting for this window to handle an |
| 10229 | // orientation change, well, it is hidden, so |
| 10230 | // doesn't really matter. Note that this does |
| 10231 | // introduce a potential glitch if the window |
| 10232 | // becomes unhidden before it has drawn for the |
| 10233 | // new orientation. |
| 10234 | if (w.mOrientationChanging) { |
| 10235 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10236 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10237 | "Orientation change skips hidden " + w); |
| 10238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10239 | } else if (w.mLastLayer != w.mAnimLayer |
| 10240 | || w.mLastAlpha != w.mShownAlpha |
| 10241 | || w.mLastDsDx != w.mDsDx |
| 10242 | || w.mLastDtDx != w.mDtDx |
| 10243 | || w.mLastDsDy != w.mDsDy |
| 10244 | || w.mLastDtDy != w.mDtDy |
| 10245 | || w.mLastHScale != w.mHScale |
| 10246 | || w.mLastVScale != w.mVScale |
| 10247 | || w.mLastHidden) { |
| 10248 | displayed = true; |
| 10249 | w.mLastAlpha = w.mShownAlpha; |
| 10250 | w.mLastLayer = w.mAnimLayer; |
| 10251 | w.mLastDsDx = w.mDsDx; |
| 10252 | w.mLastDtDx = w.mDtDx; |
| 10253 | w.mLastDsDy = w.mDsDy; |
| 10254 | w.mLastDtDy = w.mDtDy; |
| 10255 | w.mLastHScale = w.mHScale; |
| 10256 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10257 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10258 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10259 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10260 | + "," + (w.mDtDx*w.mVScale) |
| 10261 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10262 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10263 | if (w.mSurface != null) { |
| 10264 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10265 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10266 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10267 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10268 | w.mSurface.setLayer(w.mAnimLayer); |
| 10269 | w.mSurface.setMatrix( |
| 10270 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10271 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10272 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10273 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10274 | if (!recoveringMemory) { |
| 10275 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10276 | } |
| 10277 | } |
| 10278 | } |
| 10279 | |
| 10280 | if (w.mLastHidden && !w.mDrawPending |
| 10281 | && !w.mCommitDrawPending |
| 10282 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10283 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10284 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10285 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10286 | + " during relayout"); |
| 10287 | if (showSurfaceRobustlyLocked(w)) { |
| 10288 | w.mHasDrawn = true; |
| 10289 | w.mLastHidden = false; |
| 10290 | } else { |
| 10291 | w.mOrientationChanging = false; |
| 10292 | } |
| 10293 | } |
| 10294 | if (w.mSurface != null) { |
| 10295 | w.mToken.hasVisible = true; |
| 10296 | } |
| 10297 | } else { |
| 10298 | displayed = true; |
| 10299 | } |
| 10300 | |
| 10301 | if (displayed) { |
| 10302 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10303 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10304 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10305 | covered = true; |
| 10306 | } |
| 10307 | } |
| 10308 | if (w.mOrientationChanging) { |
| 10309 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10310 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10311 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10312 | "Orientation continue waiting for draw in " + w); |
| 10313 | } else { |
| 10314 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10315 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10316 | "Orientation change complete in " + w); |
| 10317 | } |
| 10318 | } |
| 10319 | w.mToken.hasVisible = true; |
| 10320 | } |
| 10321 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10322 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10323 | "Orientation change skips hidden " + w); |
| 10324 | w.mOrientationChanging = false; |
| 10325 | } |
| 10326 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 10327 | if (w.mContentChanged) { |
| 10328 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 10329 | w.mContentChanged = false; |
| 10330 | } |
| 10331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10332 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10333 | |
| 10334 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10335 | focusDisplayed = true; |
| 10336 | } |
| 10337 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10338 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10340 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10341 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10342 | if (w.mSurface != null) { |
| 10343 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10344 | holdScreen = w.mSession; |
| 10345 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10346 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10347 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10348 | screenBrightness = w.mAttrs.screenBrightness; |
| 10349 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10350 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10351 | && buttonBrightness < 0) { |
| 10352 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10353 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10354 | if (canBeSeen |
| 10355 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10356 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10357 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10358 | syswin = true; |
| 10359 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10360 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10361 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10362 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10363 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10364 | // This window completely covers everything behind it, |
| 10365 | // so we want to leave all of them as unblurred (for |
| 10366 | // performance reasons). |
| 10367 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10368 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10369 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10370 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10371 | obscured = true; |
| 10372 | if (mBackgroundFillerSurface == null) { |
| 10373 | try { |
| 10374 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10375 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10376 | 0, dw, dh, |
| 10377 | PixelFormat.OPAQUE, |
| 10378 | Surface.FX_SURFACE_NORMAL); |
| 10379 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10380 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10381 | } |
| 10382 | } |
| 10383 | try { |
| 10384 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10385 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10386 | // Using the same layer as Dim because they will never be shown at the |
| 10387 | // same time. |
| 10388 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10389 | mBackgroundFillerSurface.show(); |
| 10390 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10391 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10392 | } |
| 10393 | backgroundFillerShown = true; |
| 10394 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10395 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10396 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10397 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10398 | + ": blurring=" + blurring |
| 10399 | + " obscured=" + obscured |
| 10400 | + " displayed=" + displayed); |
| 10401 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10402 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10403 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10404 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10405 | if (mDimAnimator == null) { |
| 10406 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10407 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10408 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 10409 | mDimAnimator.updateParameters(mContext.getResources(), |
| 10410 | w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10411 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10412 | } |
| 10413 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10414 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10415 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10416 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10417 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10418 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10419 | + mBlurSurface + ": CREATE"); |
| 10420 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10421 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10422 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10423 | -1, 16, 16, |
| 10424 | PixelFormat.OPAQUE, |
| 10425 | Surface.FX_SURFACE_BLUR); |
| 10426 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10427 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10428 | } |
| 10429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10430 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10431 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10432 | + mBlurSurface + ": pos=(0,0) (" + |
| 10433 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10434 | mBlurSurface.setPosition(0, 0); |
| 10435 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10436 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10437 | if (!mBlurShown) { |
| 10438 | try { |
| 10439 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10440 | + mBlurSurface + ": SHOW"); |
| 10441 | mBlurSurface.show(); |
| 10442 | } catch (RuntimeException e) { |
| 10443 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10444 | } |
| 10445 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10446 | } |
| 10447 | } |
| 10448 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10449 | } |
| 10450 | } |
| 10451 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10452 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10453 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10454 | // This is the wallpaper target and its obscured state |
| 10455 | // changed... make sure the current wallaper's visibility |
| 10456 | // has been updated accordingly. |
| 10457 | updateWallpaperVisibilityLocked(); |
| 10458 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10459 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10460 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10461 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10462 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10463 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10464 | try { |
| 10465 | mBackgroundFillerSurface.hide(); |
| 10466 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10467 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10468 | } |
| 10469 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10470 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10471 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10472 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10473 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10474 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10476 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10477 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10478 | + ": HIDE"); |
| 10479 | try { |
| 10480 | mBlurSurface.hide(); |
| 10481 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10482 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10483 | } |
| 10484 | mBlurShown = false; |
| 10485 | } |
| 10486 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10487 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10488 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10489 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10490 | } |
| 10491 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10492 | mInputMonitor.updateInputWindowsLw(); |
| 10493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10494 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10495 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10496 | if (mWatermark != null) { |
| 10497 | mWatermark.drawIfNeeded(); |
| 10498 | } |
| 10499 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10500 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10501 | "With display frozen, orientationChangeComplete=" |
| 10502 | + orientationChangeComplete); |
| 10503 | if (orientationChangeComplete) { |
| 10504 | if (mWindowsFreezingScreen) { |
| 10505 | mWindowsFreezingScreen = false; |
| 10506 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10507 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10508 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10509 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10511 | i = mResizingWindows.size(); |
| 10512 | if (i > 0) { |
| 10513 | do { |
| 10514 | i--; |
| 10515 | WindowState win = mResizingWindows.get(i); |
| 10516 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10517 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10518 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10519 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10520 | boolean configChanged = |
| 10521 | win.mConfiguration != mCurConfiguration |
| 10522 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10523 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10524 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10525 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10526 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10527 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10528 | + " / " + mCurConfiguration + " / 0x" |
| 10529 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10530 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10531 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10532 | win.mClient.resized(win.mFrame.width(), |
| 10533 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10534 | win.mLastVisibleInsets, win.mDrawPending, |
| 10535 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10536 | win.mContentInsetsChanged = false; |
| 10537 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10538 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10539 | } catch (RemoteException e) { |
| 10540 | win.mOrientationChanging = false; |
| 10541 | } |
| 10542 | } while (i > 0); |
| 10543 | mResizingWindows.clear(); |
| 10544 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10546 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10547 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10548 | i = mDestroySurface.size(); |
| 10549 | if (i > 0) { |
| 10550 | do { |
| 10551 | i--; |
| 10552 | WindowState win = mDestroySurface.get(i); |
| 10553 | win.mDestroying = false; |
| 10554 | if (mInputMethodWindow == win) { |
| 10555 | mInputMethodWindow = null; |
| 10556 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10557 | if (win == mWallpaperTarget) { |
| 10558 | wallpaperDestroyed = true; |
| 10559 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10560 | win.destroySurfaceLocked(); |
| 10561 | } while (i > 0); |
| 10562 | mDestroySurface.clear(); |
| 10563 | } |
| 10564 | |
| 10565 | // Time to remove any exiting tokens? |
| 10566 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10567 | WindowToken token = mExitingTokens.get(i); |
| 10568 | if (!token.hasVisible) { |
| 10569 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10570 | if (token.windowType == TYPE_WALLPAPER) { |
| 10571 | mWallpaperTokens.remove(token); |
| 10572 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10573 | } |
| 10574 | } |
| 10575 | |
| 10576 | // Time to remove any exiting applications? |
| 10577 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10578 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10579 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10580 | // Make sure there is no animation running on this token, |
| 10581 | // so any windows associated with it will be removed as |
| 10582 | // soon as their animations are complete |
| 10583 | token.animation = null; |
| 10584 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10585 | mAppTokens.remove(token); |
| 10586 | mExitingAppTokens.remove(i); |
| 10587 | } |
| 10588 | } |
| 10589 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10590 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10591 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10592 | if (!animating && mAppTransitionRunning) { |
| 10593 | // We have finished the animation of an app transition. To do |
| 10594 | // this, we have delayed a lot of operations like showing and |
| 10595 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10596 | // reflects the correct Z-order, but the window list may now |
| 10597 | // be out of sync with it. So here we will just rebuild the |
| 10598 | // entire app window list. Fun! |
| 10599 | mAppTransitionRunning = false; |
| 10600 | needRelayout = true; |
| 10601 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10602 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10603 | // Clear information about apps that were moving. |
| 10604 | mToBottomApps.clear(); |
| 10605 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10607 | if (focusDisplayed) { |
| 10608 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10609 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10610 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10611 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10612 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10613 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10614 | requestAnimationLocked(0); |
| 10615 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10616 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10617 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10618 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10619 | mInputMonitor.updateInputWindowsLw(); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10620 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10621 | setHoldScreenLocked(holdScreen != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10622 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10623 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10624 | } else { |
| 10625 | mPowerManager.setScreenBrightnessOverride((int) |
| 10626 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10627 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10628 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10629 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10630 | } else { |
| 10631 | mPowerManager.setButtonBrightnessOverride((int) |
| 10632 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10634 | if (holdScreen != mHoldingScreenOn) { |
| 10635 | mHoldingScreenOn = holdScreen; |
| 10636 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10637 | mH.sendMessage(m); |
| 10638 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10639 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10640 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10641 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10642 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10643 | LocalPowerManager.BUTTON_EVENT, true); |
| 10644 | mTurnOnScreen = false; |
| 10645 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10646 | |
| 10647 | // Check to see if we are now in a state where the screen should |
| 10648 | // be enabled, because the window obscured flags have changed. |
| 10649 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10650 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10651 | |
| 10652 | /** |
| 10653 | * Must be called with the main window manager lock held. |
| 10654 | */ |
| 10655 | void setHoldScreenLocked(boolean holding) { |
| 10656 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10657 | if (holding != state) { |
| 10658 | if (holding) { |
| 10659 | mHoldingScreenWakeLock.acquire(); |
| 10660 | } else { |
| 10661 | mPolicy.screenOnStoppedLw(); |
| 10662 | mHoldingScreenWakeLock.release(); |
| 10663 | } |
| 10664 | } |
| 10665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10666 | |
| 10667 | void requestAnimationLocked(long delay) { |
| 10668 | if (!mAnimationPending) { |
| 10669 | mAnimationPending = true; |
| 10670 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10671 | } |
| 10672 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10674 | /** |
| 10675 | * Have the surface flinger show a surface, robustly dealing with |
| 10676 | * error conditions. In particular, if there is not enough memory |
| 10677 | * to show the surface, then we will try to get rid of other surfaces |
| 10678 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10679 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10680 | * @return Returns true if the surface was successfully shown. |
| 10681 | */ |
| 10682 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10683 | try { |
| 10684 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10685 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10686 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10687 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10688 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10689 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10690 | win.mTurnOnScreen = false; |
| 10691 | mTurnOnScreen = true; |
| 10692 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10693 | } |
| 10694 | return true; |
| 10695 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10696 | 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] | 10697 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10699 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10701 | return false; |
| 10702 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10704 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10705 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10706 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10707 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10708 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10710 | if (mForceRemoves == null) { |
| 10711 | mForceRemoves = new ArrayList<WindowState>(); |
| 10712 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10714 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10715 | try { |
| 10716 | // There was some problem... first, do a sanity check of the |
| 10717 | // window list to make sure we haven't left any dangling surfaces |
| 10718 | // around. |
| 10719 | int N = mWindows.size(); |
| 10720 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10721 | 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] | 10722 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10723 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10724 | if (ws.mSurface != null) { |
| 10725 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10726 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10727 | + ws + " surface=" + ws.mSurface |
| 10728 | + " token=" + win.mToken |
| 10729 | + " pid=" + ws.mSession.mPid |
| 10730 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10731 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10732 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10733 | ws.mSurface = null; |
| 10734 | mForceRemoves.add(ws); |
| 10735 | i--; |
| 10736 | N--; |
| 10737 | leakedSurface = true; |
| 10738 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10739 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10740 | + ws + " surface=" + ws.mSurface |
| 10741 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10742 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10743 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10744 | ws.mSurface = null; |
| 10745 | leakedSurface = true; |
| 10746 | } |
| 10747 | } |
| 10748 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10750 | boolean killedApps = false; |
| 10751 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10752 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10753 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10754 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10755 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10756 | if (ws.mSurface != null) { |
| 10757 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10758 | } |
| 10759 | } |
| 10760 | if (pidCandidates.size() > 0) { |
| 10761 | int[] pids = new int[pidCandidates.size()]; |
| 10762 | for (int i=0; i<pids.length; i++) { |
| 10763 | pids[i] = pidCandidates.keyAt(i); |
| 10764 | } |
| 10765 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10766 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10767 | killedApps = true; |
| 10768 | } |
| 10769 | } catch (RemoteException e) { |
| 10770 | } |
| 10771 | } |
| 10772 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10773 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10774 | if (leakedSurface || killedApps) { |
| 10775 | // We managed to reclaim some memory, so get rid of the trouble |
| 10776 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10777 | 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] | 10778 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10779 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10780 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10781 | win.mSurface = null; |
| 10782 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10784 | try { |
| 10785 | win.mClient.dispatchGetNewSurface(); |
| 10786 | } catch (RemoteException e) { |
| 10787 | } |
| 10788 | } |
| 10789 | } finally { |
| 10790 | Binder.restoreCallingIdentity(callingIdentity); |
| 10791 | } |
| 10792 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10794 | private boolean updateFocusedWindowLocked(int mode) { |
| 10795 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10796 | if (mCurrentFocus != newFocus) { |
| 10797 | // This check makes sure that we don't already have the focus |
| 10798 | // change message pending. |
| 10799 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10800 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10801 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10802 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10803 | final WindowState oldFocus = mCurrentFocus; |
| 10804 | mCurrentFocus = newFocus; |
| 10805 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10807 | final WindowState imWindow = mInputMethodWindow; |
| 10808 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10809 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10810 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10811 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10812 | mLayoutNeeded = true; |
| 10813 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10814 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 10815 | performLayoutLockedInner(true); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10816 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10817 | // Client will do the layout, but we need to assign layers |
| 10818 | // for handleNewWindowLocked() below. |
| 10819 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10820 | } |
| 10821 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10822 | |
| 10823 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10824 | // If we defer assigning layers, then the caller is responsible for |
| 10825 | // doing this part. |
| 10826 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10827 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10828 | return true; |
| 10829 | } |
| 10830 | return false; |
| 10831 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10832 | |
| 10833 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10834 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10835 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10836 | |
| 10837 | private WindowState computeFocusedWindowLocked() { |
| 10838 | WindowState result = null; |
| 10839 | WindowState win; |
| 10840 | |
| 10841 | int i = mWindows.size() - 1; |
| 10842 | int nextAppIndex = mAppTokens.size()-1; |
| 10843 | WindowToken nextApp = nextAppIndex >= 0 |
| 10844 | ? mAppTokens.get(nextAppIndex) : null; |
| 10845 | |
| 10846 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10847 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10848 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10849 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10850 | TAG, "Looking for focus: " + i |
| 10851 | + " = " + win |
| 10852 | + ", flags=" + win.mAttrs.flags |
| 10853 | + ", canReceive=" + win.canReceiveKeys()); |
| 10854 | |
| 10855 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10857 | // If this window's application has been removed, just skip it. |
| 10858 | if (thisApp != null && thisApp.removed) { |
| 10859 | i--; |
| 10860 | continue; |
| 10861 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10863 | // If there is a focused app, don't allow focus to go to any |
| 10864 | // windows below it. If this is an application window, step |
| 10865 | // through the app tokens until we find its app. |
| 10866 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10867 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10868 | int origAppIndex = nextAppIndex; |
| 10869 | while (nextAppIndex > 0) { |
| 10870 | if (nextApp == mFocusedApp) { |
| 10871 | // Whoops, we are below the focused app... no focus |
| 10872 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10873 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10874 | TAG, "Reached focused app: " + mFocusedApp); |
| 10875 | return null; |
| 10876 | } |
| 10877 | nextAppIndex--; |
| 10878 | nextApp = mAppTokens.get(nextAppIndex); |
| 10879 | if (nextApp == thisApp) { |
| 10880 | break; |
| 10881 | } |
| 10882 | } |
| 10883 | if (thisApp != nextApp) { |
| 10884 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10885 | // happen, but if it does we can get totally hosed... |
| 10886 | // so restart at the original app. |
| 10887 | nextAppIndex = origAppIndex; |
| 10888 | nextApp = mAppTokens.get(nextAppIndex); |
| 10889 | } |
| 10890 | } |
| 10891 | |
| 10892 | // Dispatch to this window if it is wants key events. |
| 10893 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10894 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10895 | TAG, "Found focus @ " + i + " = " + win); |
| 10896 | result = win; |
| 10897 | break; |
| 10898 | } |
| 10899 | |
| 10900 | i--; |
| 10901 | } |
| 10902 | |
| 10903 | return result; |
| 10904 | } |
| 10905 | |
| 10906 | private void startFreezingDisplayLocked() { |
| 10907 | if (mDisplayFrozen) { |
| 10908 | return; |
| 10909 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10911 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10913 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10914 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10915 | if (mFreezeGcPending != 0) { |
| 10916 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10917 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10918 | mH.removeMessages(H.FORCE_GC); |
| 10919 | Runtime.getRuntime().gc(); |
| 10920 | mFreezeGcPending = now; |
| 10921 | } |
| 10922 | } else { |
| 10923 | mFreezeGcPending = now; |
| 10924 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10926 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10927 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10928 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10929 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10930 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10931 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10932 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10933 | mAppTransitionReady = true; |
| 10934 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10936 | if (PROFILE_ORIENTATION) { |
| 10937 | File file = new File("/data/system/frozen"); |
| 10938 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10939 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 10940 | |
| 10941 | if (CUSTOM_SCREEN_ROTATION) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 10942 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 10943 | mScreenRotationAnimation.kill(); |
| 10944 | mScreenRotationAnimation = null; |
| 10945 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 10946 | if (mScreenRotationAnimation == null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 10947 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
| 10948 | mDisplay, mFxSession); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 10949 | } |
| 10950 | } else { |
| 10951 | Surface.freezeDisplay(0); |
| 10952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10953 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10954 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10955 | private void stopFreezingDisplayLocked() { |
| 10956 | if (!mDisplayFrozen) { |
| 10957 | return; |
| 10958 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10959 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10960 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10961 | return; |
| 10962 | } |
| 10963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10964 | mDisplayFrozen = false; |
| 10965 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10966 | if (PROFILE_ORIENTATION) { |
| 10967 | Debug.stopMethodTracing(); |
| 10968 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 10969 | |
| 10970 | if (CUSTOM_SCREEN_ROTATION) { |
| 10971 | if (mScreenRotationAnimation != null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 10972 | if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION, |
| 10973 | mTransitionAnimationScale)) { |
| 10974 | requestAnimationLocked(0); |
| 10975 | } else { |
| 10976 | mScreenRotationAnimation = null; |
| 10977 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 10978 | } |
| 10979 | } else { |
| 10980 | Surface.unfreezeDisplay(0); |
| 10981 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10982 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10983 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10984 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10985 | // While the display is frozen we don't re-compute the orientation |
| 10986 | // to avoid inconsistent states. However, something interesting |
| 10987 | // could have actually changed during that time so re-evaluate it |
| 10988 | // now to catch that. |
| 10989 | if (updateOrientationFromAppTokensLocked()) { |
| 10990 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10991 | } |
| 10992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10993 | // A little kludge: a lot could have happened while the |
| 10994 | // display was frozen, so now that we are coming back we |
| 10995 | // do a gc so that any remote references the system |
| 10996 | // processes holds on others can be released if they are |
| 10997 | // no longer needed. |
| 10998 | mH.removeMessages(H.FORCE_GC); |
| 10999 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11000 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11002 | mScreenFrozenLock.release(); |
| 11003 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11004 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11005 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 11006 | DisplayMetrics dm) { |
| 11007 | if (index < tokens.length) { |
| 11008 | String str = tokens[index]; |
| 11009 | if (str != null && str.length() > 0) { |
| 11010 | try { |
| 11011 | int val = Integer.parseInt(str); |
| 11012 | return val; |
| 11013 | } catch (Exception e) { |
| 11014 | } |
| 11015 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11016 | } |
| 11017 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 11018 | return defDps; |
| 11019 | } |
| 11020 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 11021 | return val; |
| 11022 | } |
| 11023 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11024 | static class Watermark { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11025 | final String[] mTokens; |
| 11026 | final String mText; |
| 11027 | final Paint mTextPaint; |
| 11028 | final int mTextWidth; |
| 11029 | final int mTextHeight; |
| 11030 | final int mTextAscent; |
| 11031 | final int mTextDescent; |
| 11032 | final int mDeltaX; |
| 11033 | final int mDeltaY; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11034 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11035 | Surface mSurface; |
| 11036 | int mLastDW; |
| 11037 | int mLastDH; |
| 11038 | boolean mDrawNeeded; |
| 11039 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11040 | Watermark(Display display, SurfaceSession session, String[] tokens) { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11041 | final DisplayMetrics dm = new DisplayMetrics(); |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11042 | display.getMetrics(dm); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11043 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11044 | if (false) { |
| 11045 | Log.i(TAG, "*********************** WATERMARK"); |
| 11046 | for (int i=0; i<tokens.length; i++) { |
| 11047 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 11048 | } |
| 11049 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11050 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11051 | mTokens = tokens; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11052 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11053 | StringBuilder builder = new StringBuilder(32); |
| 11054 | int len = mTokens[0].length(); |
| 11055 | len = len & ~1; |
| 11056 | for (int i=0; i<len; i+=2) { |
| 11057 | int c1 = mTokens[0].charAt(i); |
| 11058 | int c2 = mTokens[0].charAt(i+1); |
| 11059 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 11060 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 11061 | else c1 -= '0'; |
| 11062 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 11063 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 11064 | else c2 -= '0'; |
| 11065 | builder.append((char)(255-((c1*16)+c2))); |
| 11066 | } |
| 11067 | mText = builder.toString(); |
| 11068 | if (false) { |
| 11069 | Log.i(TAG, "Final text: " + mText); |
| 11070 | } |
| 11071 | |
| 11072 | int fontSize = getPropertyInt(tokens, 1, |
| 11073 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 11074 | |
| 11075 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 11076 | mTextPaint.setTextSize(fontSize); |
| 11077 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 11078 | |
| 11079 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 11080 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 11081 | mTextAscent = fm.ascent; |
| 11082 | mTextDescent = fm.descent; |
| 11083 | mTextHeight = fm.descent - fm.ascent; |
| 11084 | |
| 11085 | mDeltaX = getPropertyInt(tokens, 2, |
| 11086 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 11087 | mDeltaY = getPropertyInt(tokens, 3, |
| 11088 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 11089 | int shadowColor = getPropertyInt(tokens, 4, |
| 11090 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 11091 | int color = getPropertyInt(tokens, 5, |
| 11092 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 11093 | int shadowRadius = getPropertyInt(tokens, 6, |
| 11094 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 11095 | int shadowDx = getPropertyInt(tokens, 8, |
| 11096 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11097 | int shadowDy = getPropertyInt(tokens, 9, |
| 11098 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11099 | |
| 11100 | mTextPaint.setColor(color); |
| 11101 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11102 | |
| 11103 | try { |
| 11104 | mSurface = new Surface(session, 0, |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11105 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11106 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11107 | mSurface.setPosition(0, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11108 | mSurface.show(); |
| 11109 | } catch (OutOfResourcesException e) { |
| 11110 | } |
| 11111 | } |
| 11112 | |
| 11113 | void positionSurface(int dw, int dh) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11114 | if (mLastDW != dw || mLastDH != dh) { |
| 11115 | mLastDW = dw; |
| 11116 | mLastDH = dh; |
| 11117 | mSurface.setSize(dw, dh); |
| 11118 | mDrawNeeded = true; |
| 11119 | } |
| 11120 | } |
| 11121 | |
| 11122 | void drawIfNeeded() { |
| 11123 | if (mDrawNeeded) { |
| 11124 | final int dw = mLastDW; |
| 11125 | final int dh = mLastDH; |
| 11126 | |
| 11127 | mDrawNeeded = false; |
| 11128 | Rect dirty = new Rect(0, 0, dw, dh); |
| 11129 | Canvas c = null; |
| 11130 | try { |
| 11131 | c = mSurface.lockCanvas(dirty); |
| 11132 | } catch (IllegalArgumentException e) { |
| 11133 | } catch (OutOfResourcesException e) { |
| 11134 | } |
| 11135 | if (c != null) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11136 | c.drawColor(0, PorterDuff.Mode.CLEAR); |
| 11137 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11138 | int deltaX = mDeltaX; |
| 11139 | int deltaY = mDeltaY; |
| 11140 | |
| 11141 | // deltaX shouldn't be close to a round fraction of our |
| 11142 | // x step, or else things will line up too much. |
| 11143 | int div = (dw+mTextWidth)/deltaX; |
| 11144 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 11145 | int qdelta = deltaX/4; |
| 11146 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 11147 | deltaX += deltaX/3; |
| 11148 | } |
| 11149 | |
| 11150 | int y = -mTextHeight; |
| 11151 | int x = -mTextWidth; |
| 11152 | while (y < (dh+mTextHeight)) { |
| 11153 | c.drawText(mText, x, y, mTextPaint); |
| 11154 | x += deltaX; |
| 11155 | if (x >= dw) { |
| 11156 | x -= (dw+mTextWidth); |
| 11157 | y += deltaY; |
| 11158 | } |
| 11159 | } |
| 11160 | mSurface.unlockCanvasAndPost(c); |
| 11161 | } |
| 11162 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11163 | } |
| 11164 | } |
| 11165 | |
| 11166 | void createWatermark() { |
| 11167 | if (mWatermark != null) { |
| 11168 | return; |
| 11169 | } |
| 11170 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11171 | File file = new File("/system/etc/setup.conf"); |
| 11172 | FileInputStream in = null; |
| 11173 | try { |
| 11174 | in = new FileInputStream(file); |
| 11175 | DataInputStream ind = new DataInputStream(in); |
| 11176 | String line = ind.readLine(); |
| 11177 | if (line != null) { |
| 11178 | String[] toks = line.split("%"); |
| 11179 | if (toks != null && toks.length > 0) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11180 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11181 | } |
| 11182 | } |
| 11183 | } catch (FileNotFoundException e) { |
| 11184 | } catch (IOException e) { |
| 11185 | } finally { |
| 11186 | if (in != null) { |
| 11187 | try { |
| 11188 | in.close(); |
| 11189 | } catch (IOException e) { |
| 11190 | } |
| 11191 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11192 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11193 | } |
| 11194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11195 | @Override |
| 11196 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11197 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11198 | != PackageManager.PERMISSION_GRANTED) { |
| 11199 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11200 | + Binder.getCallingPid() |
| 11201 | + ", uid=" + Binder.getCallingUid()); |
| 11202 | return; |
| 11203 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11204 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11205 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11206 | pw.println(" "); |
| 11207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11208 | synchronized(mWindowMap) { |
| 11209 | pw.println("Current Window Manager state:"); |
| 11210 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11211 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11212 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11213 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11214 | w.dump(pw, " "); |
| 11215 | } |
| 11216 | if (mInputMethodDialogs.size() > 0) { |
| 11217 | pw.println(" "); |
| 11218 | pw.println(" Input method dialogs:"); |
| 11219 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11220 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11221 | 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] | 11222 | } |
| 11223 | } |
| 11224 | if (mPendingRemove.size() > 0) { |
| 11225 | pw.println(" "); |
| 11226 | pw.println(" Remove pending for:"); |
| 11227 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11228 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11229 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11230 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11231 | w.dump(pw, " "); |
| 11232 | } |
| 11233 | } |
| 11234 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11235 | pw.println(" "); |
| 11236 | pw.println(" Windows force removing:"); |
| 11237 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11238 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11239 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11240 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11241 | w.dump(pw, " "); |
| 11242 | } |
| 11243 | } |
| 11244 | if (mDestroySurface.size() > 0) { |
| 11245 | pw.println(" "); |
| 11246 | pw.println(" Windows waiting to destroy their surface:"); |
| 11247 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11248 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11249 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11250 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11251 | w.dump(pw, " "); |
| 11252 | } |
| 11253 | } |
| 11254 | if (mLosingFocus.size() > 0) { |
| 11255 | pw.println(" "); |
| 11256 | pw.println(" Windows losing focus:"); |
| 11257 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11258 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11259 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11260 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11261 | w.dump(pw, " "); |
| 11262 | } |
| 11263 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11264 | if (mResizingWindows.size() > 0) { |
| 11265 | pw.println(" "); |
| 11266 | pw.println(" Windows waiting to resize:"); |
| 11267 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11268 | WindowState w = mResizingWindows.get(i); |
| 11269 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11270 | pw.print(w); pw.println(":"); |
| 11271 | w.dump(pw, " "); |
| 11272 | } |
| 11273 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11274 | if (mSessions.size() > 0) { |
| 11275 | pw.println(" "); |
| 11276 | pw.println(" All active sessions:"); |
| 11277 | Iterator<Session> it = mSessions.iterator(); |
| 11278 | while (it.hasNext()) { |
| 11279 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11280 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11281 | s.dump(pw, " "); |
| 11282 | } |
| 11283 | } |
| 11284 | if (mTokenMap.size() > 0) { |
| 11285 | pw.println(" "); |
| 11286 | pw.println(" All tokens:"); |
| 11287 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11288 | while (it.hasNext()) { |
| 11289 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11290 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11291 | token.dump(pw, " "); |
| 11292 | } |
| 11293 | } |
| 11294 | if (mTokenList.size() > 0) { |
| 11295 | pw.println(" "); |
| 11296 | pw.println(" Window token list:"); |
| 11297 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11298 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 11299 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11300 | } |
| 11301 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11302 | if (mWallpaperTokens.size() > 0) { |
| 11303 | pw.println(" "); |
| 11304 | pw.println(" Wallpaper tokens:"); |
| 11305 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11306 | WindowToken token = mWallpaperTokens.get(i); |
| 11307 | pw.print(" Wallpaper #"); pw.print(i); |
| 11308 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11309 | token.dump(pw, " "); |
| 11310 | } |
| 11311 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11312 | if (mAppTokens.size() > 0) { |
| 11313 | pw.println(" "); |
| 11314 | pw.println(" Application tokens in Z order:"); |
| 11315 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11316 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11317 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11318 | } |
| 11319 | } |
| 11320 | if (mFinishedStarting.size() > 0) { |
| 11321 | pw.println(" "); |
| 11322 | pw.println(" Finishing start of application tokens:"); |
| 11323 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11324 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11325 | pw.print(" Finished Starting #"); pw.print(i); |
| 11326 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11327 | token.dump(pw, " "); |
| 11328 | } |
| 11329 | } |
| 11330 | if (mExitingTokens.size() > 0) { |
| 11331 | pw.println(" "); |
| 11332 | pw.println(" Exiting tokens:"); |
| 11333 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11334 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11335 | pw.print(" Exiting #"); pw.print(i); |
| 11336 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11337 | token.dump(pw, " "); |
| 11338 | } |
| 11339 | } |
| 11340 | if (mExitingAppTokens.size() > 0) { |
| 11341 | pw.println(" "); |
| 11342 | pw.println(" Exiting application tokens:"); |
| 11343 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11344 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11345 | pw.print(" Exiting App #"); pw.print(i); |
| 11346 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11347 | token.dump(pw, " "); |
| 11348 | } |
| 11349 | } |
| 11350 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11351 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11352 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11353 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11354 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11355 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11356 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11357 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11358 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11359 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11360 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 11361 | if (mWindowDetachedWallpaper != null) { |
| 11362 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 11363 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11364 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11365 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11366 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11367 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11368 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11369 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11370 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11371 | if (mDimAnimator != null) { |
| 11372 | mDimAnimator.printTo(pw); |
| 11373 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11374 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11375 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11376 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11377 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11378 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11379 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11380 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11381 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11382 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11383 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11384 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11385 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11386 | pw.print(" mRotation="); pw.print(mRotation); |
| 11387 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11388 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11389 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11390 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11391 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11392 | pw.print(" mNextAppTransition=0x"); |
| 11393 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11394 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11395 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11396 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11397 | if (mNextAppTransitionPackage != null) { |
| 11398 | pw.print(" mNextAppTransitionPackage="); |
| 11399 | pw.print(mNextAppTransitionPackage); |
| 11400 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11401 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11402 | pw.print(", mNextAppTransitionExit=0x"); |
| 11403 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11404 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11405 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11406 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 11407 | if (mOpeningApps.size() > 0) { |
| 11408 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11409 | } |
| 11410 | if (mClosingApps.size() > 0) { |
| 11411 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11412 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11413 | if (mToTopApps.size() > 0) { |
| 11414 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11415 | } |
| 11416 | if (mToBottomApps.size() > 0) { |
| 11417 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11418 | } |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 11419 | if (mDisplay != null) { |
| 11420 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11421 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| 11422 | } else { |
| 11423 | pw.println(" NO DISPLAY"); |
| 11424 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11425 | } |
| 11426 | } |
| 11427 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11428 | // 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] | 11429 | public void monitor() { |
| 11430 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11431 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11432 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11433 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11434 | /** |
| 11435 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11436 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11437 | */ |
| 11438 | private static class DimAnimator { |
| 11439 | Surface mDimSurface; |
| 11440 | boolean mDimShown = false; |
| 11441 | float mDimCurrentAlpha; |
| 11442 | float mDimTargetAlpha; |
| 11443 | float mDimDeltaPerMs; |
| 11444 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11445 | |
| 11446 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11447 | |
| 11448 | DimAnimator (SurfaceSession session) { |
| 11449 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11450 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11451 | + mDimSurface + ": CREATE"); |
| 11452 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11453 | mDimSurface = new Surface(session, 0, |
| 11454 | "DimSurface", |
| 11455 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11456 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11457 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11458 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11459 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11460 | } |
| 11461 | } |
| 11462 | } |
| 11463 | |
| 11464 | /** |
| 11465 | * Show the dim surface. |
| 11466 | */ |
| 11467 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11468 | if (!mDimShown) { |
| 11469 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11470 | dw + "x" + dh + ")"); |
| 11471 | mDimShown = true; |
| 11472 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11473 | mLastDimWidth = dw; |
| 11474 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11475 | mDimSurface.setPosition(0, 0); |
| 11476 | mDimSurface.setSize(dw, dh); |
| 11477 | mDimSurface.show(); |
| 11478 | } catch (RuntimeException e) { |
| 11479 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11480 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11481 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11482 | mLastDimWidth = dw; |
| 11483 | mLastDimHeight = dh; |
| 11484 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11485 | } |
| 11486 | } |
| 11487 | |
| 11488 | /** |
| 11489 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11490 | * {@link updateSurface} after all windows are examined. |
| 11491 | */ |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11492 | void updateParameters(Resources res, WindowState w, long currentTime) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11493 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11494 | |
| 11495 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11496 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11497 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11498 | if (mDimTargetAlpha != target) { |
| 11499 | // If the desired dim level has changed, then |
| 11500 | // start an animation to it. |
| 11501 | mLastDimAnimTime = currentTime; |
| 11502 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11503 | ? w.mAnimation.computeDurationHint() |
| 11504 | : DEFAULT_DIM_DURATION; |
| 11505 | if (target > mDimTargetAlpha) { |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11506 | TypedValue tv = new TypedValue(); |
| 11507 | res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration, |
| 11508 | tv, true); |
| 11509 | if (tv.type == TypedValue.TYPE_FRACTION) { |
| 11510 | duration = (long)tv.getFraction((float)duration, (float)duration); |
| 11511 | } else if (tv.type >= TypedValue.TYPE_FIRST_INT |
| 11512 | && tv.type <= TypedValue.TYPE_LAST_INT) { |
| 11513 | duration = tv.data; |
| 11514 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11515 | } |
| 11516 | if (duration < 1) { |
| 11517 | // Don't divide by zero |
| 11518 | duration = 1; |
| 11519 | } |
| 11520 | mDimTargetAlpha = target; |
| 11521 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11522 | } |
| 11523 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11524 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11525 | /** |
| 11526 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11527 | * false when the animation is finished and the dim surface is hidden. |
| 11528 | */ |
| 11529 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11530 | if (!dimming) { |
| 11531 | if (mDimTargetAlpha != 0) { |
| 11532 | mLastDimAnimTime = currentTime; |
| 11533 | mDimTargetAlpha = 0; |
| 11534 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11535 | } |
| 11536 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11537 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11538 | boolean animating = false; |
| 11539 | if (mLastDimAnimTime != 0) { |
| 11540 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11541 | * (currentTime-mLastDimAnimTime); |
| 11542 | boolean more = true; |
| 11543 | if (displayFrozen) { |
| 11544 | // If the display is frozen, there is no reason to animate. |
| 11545 | more = false; |
| 11546 | } else if (mDimDeltaPerMs > 0) { |
| 11547 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11548 | more = false; |
| 11549 | } |
| 11550 | } else if (mDimDeltaPerMs < 0) { |
| 11551 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11552 | more = false; |
| 11553 | } |
| 11554 | } else { |
| 11555 | more = false; |
| 11556 | } |
| 11557 | |
| 11558 | // Do we need to continue animating? |
| 11559 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11560 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11561 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11562 | mLastDimAnimTime = currentTime; |
| 11563 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11564 | animating = true; |
| 11565 | } else { |
| 11566 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11567 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11568 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11569 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11570 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11571 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11572 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11573 | + ": HIDE"); |
| 11574 | try { |
| 11575 | mDimSurface.hide(); |
| 11576 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11577 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11578 | } |
| 11579 | mDimShown = false; |
| 11580 | } |
| 11581 | } |
| 11582 | } |
| 11583 | return animating; |
| 11584 | } |
| 11585 | |
| 11586 | public void printTo(PrintWriter pw) { |
| 11587 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11588 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11589 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11590 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11591 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11592 | } |
| 11593 | } |
| 11594 | |
| 11595 | /** |
| 11596 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11597 | * This is used for opening/closing transition for apps in compatible mode. |
| 11598 | */ |
| 11599 | private static class FadeInOutAnimation extends Animation { |
| 11600 | int mWidth; |
| 11601 | boolean mFadeIn; |
| 11602 | |
| 11603 | public FadeInOutAnimation(boolean fadeIn) { |
| 11604 | setInterpolator(new AccelerateInterpolator()); |
| 11605 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11606 | mFadeIn = fadeIn; |
| 11607 | } |
| 11608 | |
| 11609 | @Override |
| 11610 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11611 | float x = interpolatedTime; |
| 11612 | if (!mFadeIn) { |
| 11613 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11614 | } |
| 11615 | if (x < 0.5) { |
| 11616 | // move the window out of the screen. |
| 11617 | t.getMatrix().setTranslate(mWidth, 0); |
| 11618 | } else { |
| 11619 | t.getMatrix().setTranslate(0, 0);// show |
| 11620 | t.setAlpha((x - 0.5f) * 2); |
| 11621 | } |
| 11622 | } |
| 11623 | |
| 11624 | @Override |
| 11625 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11626 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11627 | mWidth = width; |
| 11628 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11629 | |
| 11630 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11631 | public int getZAdjustment() { |
| 11632 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11633 | } |
| 11634 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11635 | } |