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; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 28 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 32 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 35 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 36 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 37 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 38 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
| 40 | import com.android.internal.app.IBatteryStats; |
| 41 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 42 | import com.android.internal.policy.impl.PhoneWindowManager; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 43 | import com.android.internal.view.BaseInputHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import com.android.internal.view.IInputContext; |
| 45 | import com.android.internal.view.IInputMethodClient; |
| 46 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 47 | import com.android.internal.view.WindowManagerPolicyThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import com.android.server.am.BatteryStatsService; |
| 49 | |
| 50 | import android.Manifest; |
| 51 | import android.app.ActivityManagerNative; |
| 52 | import android.app.IActivityManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 53 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 54 | import android.content.BroadcastReceiver; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 55 | import android.content.ClipData; |
| 56 | import android.content.ClipDescription; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 58 | import android.content.Intent; |
| 59 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.content.pm.ActivityInfo; |
| 61 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 62 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.content.res.Configuration; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 64 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.graphics.Matrix; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 66 | import android.graphics.Paint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.graphics.PixelFormat; |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame^] | 68 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.graphics.Rect; |
| 70 | import android.graphics.Region; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 71 | import android.graphics.Typeface; |
| 72 | import android.graphics.Paint.FontMetricsInt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.os.BatteryStats; |
| 74 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 75 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.os.Debug; |
| 77 | import android.os.Handler; |
| 78 | import android.os.IBinder; |
| 79 | import android.os.LocalPowerManager; |
| 80 | import android.os.Looper; |
| 81 | import android.os.Message; |
| 82 | import android.os.Parcel; |
| 83 | import android.os.ParcelFileDescriptor; |
| 84 | import android.os.Power; |
| 85 | import android.os.PowerManager; |
| 86 | import android.os.Process; |
| 87 | import android.os.RemoteException; |
| 88 | import android.os.ServiceManager; |
| 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; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 102 | import android.view.HapticFeedbackConstants; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | import android.view.IApplicationToken; |
| 104 | import android.view.IOnKeyguardExitResult; |
| 105 | import android.view.IRotationWatcher; |
| 106 | import android.view.IWindow; |
| 107 | import android.view.IWindowManager; |
| 108 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 109 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 110 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 111 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 112 | import android.view.InputHandler; |
| 113 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import android.view.KeyEvent; |
| 115 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.view.Surface; |
| 117 | import android.view.SurfaceSession; |
| 118 | import android.view.View; |
| 119 | import android.view.ViewTreeObserver; |
| 120 | import android.view.WindowManager; |
| 121 | import android.view.WindowManagerImpl; |
| 122 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 123 | import android.view.Surface.OutOfResourcesException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 125 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | import android.view.animation.Animation; |
| 127 | import android.view.animation.AnimationUtils; |
| 128 | import android.view.animation.Transformation; |
| 129 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 130 | import java.io.BufferedReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 132 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | import java.io.File; |
| 134 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 135 | import java.io.FileInputStream; |
| 136 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | import java.io.IOException; |
| 138 | import java.io.OutputStream; |
| 139 | import java.io.OutputStreamWriter; |
| 140 | import java.io.PrintWriter; |
| 141 | import java.io.StringWriter; |
| 142 | import java.net.Socket; |
| 143 | import java.util.ArrayList; |
| 144 | import java.util.HashMap; |
| 145 | import java.util.HashSet; |
| 146 | import java.util.Iterator; |
| 147 | import java.util.List; |
| 148 | |
| 149 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 150 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 151 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | static final String TAG = "WindowManager"; |
| 153 | static final boolean DEBUG = false; |
| 154 | static final boolean DEBUG_FOCUS = false; |
| 155 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | static final boolean DEBUG_LAYERS = false; |
| 159 | static final boolean DEBUG_INPUT = false; |
| 160 | static final boolean DEBUG_INPUT_METHOD = false; |
| 161 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 162 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 164 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 166 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 167 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 168 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 169 | static final boolean DEBUG_DRAG = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 171 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | static final boolean PROFILE_ORIENTATION = false; |
| 174 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 175 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** How much to multiply the policy's type layer, to reserve room |
| 178 | * for multiple windows of the same type and Z-ordering adjustment |
| 179 | * with TYPE_LAYER_OFFSET. */ |
| 180 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 183 | * or below others in the same layer. */ |
| 184 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | /** How much to increment the layer for each window, to reserve room |
| 187 | * for effect surfaces between them. |
| 188 | */ |
| 189 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | /** The maximum length we will accept for a loaded animation duration: |
| 192 | * this is 10 seconds. |
| 193 | */ |
| 194 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 195 | |
| 196 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 197 | * value to another, when no window animation is driving it. |
| 198 | */ |
| 199 | static final int DEFAULT_DIM_DURATION = 200; |
| 200 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 201 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 202 | * compatible windows. |
| 203 | */ |
| 204 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 207 | */ |
| 208 | static final int DIM_DURATION_MULTIPLIER = 6; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 209 | |
| 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 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 330 | * This was the app token that was used to retrieve the last enter |
| 331 | * animation. It will be used for the next exit animation. |
| 332 | */ |
| 333 | AppWindowToken mLastEnterAnimToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 334 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 335 | /** |
| 336 | * These were the layout params used to retrieve the last enter animation. |
| 337 | * They will be used for the next exit animation. |
| 338 | */ |
| 339 | LayoutParams mLastEnterAnimParams; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 340 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 341 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | * Z-ordered (bottom-most first) list of all Window objects. |
| 343 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 344 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | |
| 346 | /** |
| 347 | * Windows that are being resized. Used so we can tell the client about |
| 348 | * the resize after closing the transaction in which we resized the |
| 349 | * underlying surface. |
| 350 | */ |
| 351 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 352 | |
| 353 | /** |
| 354 | * Windows whose animations have ended and now must be removed. |
| 355 | */ |
| 356 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 357 | |
| 358 | /** |
| 359 | * Windows whose surface should be destroyed. |
| 360 | */ |
| 361 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 362 | |
| 363 | /** |
| 364 | * Windows that have lost input focus and are waiting for the new |
| 365 | * focus window to be displayed before they are told about this. |
| 366 | */ |
| 367 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 368 | |
| 369 | /** |
| 370 | * This is set when we have run out of memory, and will either be an empty |
| 371 | * list or contain windows that need to be force removed. |
| 372 | */ |
| 373 | ArrayList<WindowState> mForceRemoves; |
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 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 378 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | Surface mBlurSurface; |
| 380 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 381 | Watermark mWatermark; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | final float[] mTmpFloats = new float[9]; |
| 386 | |
| 387 | boolean mSafeMode; |
| 388 | boolean mDisplayEnabled = false; |
| 389 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 390 | int mInitialDisplayWidth = 0; |
| 391 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | int mRotation = 0; |
| 393 | int mRequestedRotation = 0; |
| 394 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 395 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | ArrayList<IRotationWatcher> mRotationWatchers |
| 397 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | boolean mLayoutNeeded = true; |
| 400 | boolean mAnimationPending = false; |
| 401 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 402 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | boolean mWindowsFreezingScreen = false; |
| 404 | long mFreezeGcPending = 0; |
| 405 | int mAppsFreezingScreen = 0; |
| 406 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 407 | int mLayoutSeq = 0; |
| 408 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 409 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 410 | boolean mFocusMayChange; |
| 411 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 412 | Configuration mCurConfiguration = new Configuration(); |
| 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | // This is held as long as we have the screen frozen, to give us time to |
| 415 | // perform a rotation animation when turning off shows the lock screen which |
| 416 | // changes the orientation. |
| 417 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | // State management of app transitions. When we are preparing for a |
| 420 | // transition, mNextAppTransition will be the kind of transition to |
| 421 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 422 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 423 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 424 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 425 | String mNextAppTransitionPackage; |
| 426 | int mNextAppTransitionEnter; |
| 427 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 429 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | boolean mAppTransitionTimeout = false; |
| 431 | boolean mStartingIconInTransition = false; |
| 432 | boolean mSkipAppTransitionAnimation = false; |
| 433 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 434 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 435 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 436 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | H mH = new H(); |
| 441 | |
| 442 | WindowState mCurrentFocus = null; |
| 443 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | // This just indicates the window the input method is on top of, not |
| 446 | // necessarily the window its input is going to. |
| 447 | WindowState mInputMethodTarget = null; |
| 448 | WindowState mUpcomingInputMethodTarget = null; |
| 449 | boolean mInputMethodTargetWaitingAnim; |
| 450 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | WindowState mInputMethodWindow = null; |
| 453 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 454 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 455 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 456 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 457 | // If non-null, this is the currently visible window that is associated |
| 458 | // with the wallpaper. |
| 459 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 460 | // If non-null, we are in the middle of animating from one wallpaper target |
| 461 | // to another, and this is the lower one in Z-order. |
| 462 | WindowState mLowerWallpaperTarget = null; |
| 463 | // If non-null, we are in the middle of animating from one wallpaper target |
| 464 | // to another, and this is the higher one in Z-order. |
| 465 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 466 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 467 | float mLastWallpaperX = -1; |
| 468 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 469 | float mLastWallpaperXStep = -1; |
| 470 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 471 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 472 | // changing its scroll position. |
| 473 | WindowState mWaitingOnWallpaper; |
| 474 | // The last time we had a timeout when waiting for a wallpaper. |
| 475 | long mLastWallpaperTimeoutTime; |
| 476 | // We give a wallpaper up to 150ms to finish scrolling. |
| 477 | static final long WALLPAPER_TIMEOUT = 150; |
| 478 | // Time we wait after a timeout before trying to wait again. |
| 479 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | AppWindowToken mFocusedApp = null; |
| 482 | |
| 483 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | float mWindowAnimationScale = 1.0f; |
| 486 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 487 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 488 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | |
| 490 | // Who is holding the screen on. |
| 491 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 492 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 493 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 494 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 497 | * Drag/drop state |
| 498 | */ |
| 499 | class DragState { |
| 500 | IBinder mToken; |
| 501 | Surface mSurface; |
| 502 | boolean mLocalOnly; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 503 | IBinder mLocalWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 504 | ClipData mData; |
| 505 | ClipDescription mDataDescription; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 506 | boolean mDragResult; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 507 | float mCurrentX, mCurrentY; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 508 | float mThumbOffsetX, mThumbOffsetY; |
| 509 | InputChannel mServerChannel, mClientChannel; |
| 510 | WindowState mTargetWindow; |
| 511 | ArrayList<WindowState> mNotifiedWindows; |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 512 | boolean mDragInProgress; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 513 | |
| 514 | private final Rect tmpRect = new Rect(); |
| 515 | |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 516 | DragState(IBinder token, Surface surface, boolean localOnly, IBinder localWin) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 517 | mToken = token; |
| 518 | mSurface = surface; |
| 519 | mLocalOnly = localOnly; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 520 | mLocalWin = localWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 521 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 522 | } |
| 523 | |
| 524 | void reset() { |
| 525 | if (mSurface != null) { |
| 526 | mSurface.destroy(); |
| 527 | } |
| 528 | mSurface = null; |
| 529 | mLocalOnly = false; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 530 | mLocalWin = null; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 531 | mToken = null; |
| 532 | mData = null; |
| 533 | mThumbOffsetX = mThumbOffsetY = 0; |
| 534 | mNotifiedWindows = null; |
| 535 | } |
| 536 | |
| 537 | void register() { |
| 538 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 539 | if (mClientChannel != null) { |
| 540 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 541 | } else { |
| 542 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 543 | mServerChannel = channels[0]; |
| 544 | mClientChannel = channels[1]; |
| 545 | mInputManager.registerInputChannel(mServerChannel); |
| 546 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 547 | mH.getLooper().getQueue()); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | void unregister() { |
| 552 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 553 | if (mClientChannel == null) { |
| 554 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 555 | } else { |
| 556 | mInputManager.unregisterInputChannel(mServerChannel); |
| 557 | InputQueue.unregisterInputChannel(mClientChannel); |
| 558 | mClientChannel.dispose(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 559 | mServerChannel.dispose(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 560 | mClientChannel = null; |
| 561 | mServerChannel = null; |
| 562 | } |
| 563 | } |
| 564 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 565 | int getDragLayerLw() { |
| 566 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 567 | * TYPE_LAYER_MULTIPLIER |
| 568 | + TYPE_LAYER_OFFSET; |
| 569 | } |
| 570 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 571 | /* call out to each visible window/session informing it about the drag |
| 572 | */ |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 573 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 574 | // Cache a base-class instance of the clip metadata so that parceling |
| 575 | // works correctly in calling out to the apps. |
Dianne Hackborn | f834dfa | 2010-10-26 12:43:57 -0700 | [diff] [blame] | 576 | mDataDescription = mData.getDescription(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 577 | mNotifiedWindows.clear(); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 578 | mDragInProgress = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 579 | |
| 580 | if (DEBUG_DRAG) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 581 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 584 | final int N = mWindows.size(); |
| 585 | for (int i = 0; i < N; i++) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 586 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 587 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 591 | * designated window is potentially a drop recipient. There are race situations |
| 592 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 593 | * 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] | 594 | * |
| 595 | * This method clones the 'event' parameter if it's being delivered to the same |
| 596 | * 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] | 597 | */ |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 598 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 599 | ClipDescription desc) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 600 | // Don't actually send the event if the drag is supposed to be pinned |
| 601 | // to the originating window but 'newWin' is not that window. |
| 602 | if (mLocalOnly) { |
| 603 | final IBinder winBinder = newWin.mClient.asBinder(); |
| 604 | if (winBinder != mLocalWin) { |
| 605 | if (DEBUG_DRAG) { |
| 606 | Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin); |
| 607 | } |
| 608 | return; |
| 609 | } |
| 610 | } |
| 611 | |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 612 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 613 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 614 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 615 | desc, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 616 | try { |
| 617 | newWin.mClient.dispatchDragEvent(event); |
| 618 | // track each window that we've notified that the drag is starting |
| 619 | mNotifiedWindows.add(newWin); |
| 620 | } catch (RemoteException e) { |
| 621 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 622 | } finally { |
| 623 | // if the callee was local, the dispatch has already recycled the event |
| 624 | if (Process.myPid() != newWin.mSession.mPid) { |
| 625 | event.recycle(); |
| 626 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 632 | * previously been notified, i.e. it became visible after the drag operation |
| 633 | * was begun. This is a rare case. |
| 634 | */ |
| 635 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 636 | if (mDragInProgress) { |
| 637 | // If we have sent the drag-started, we needn't do so again |
| 638 | for (WindowState ws : mNotifiedWindows) { |
| 639 | if (ws == newWin) { |
| 640 | return; |
| 641 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 642 | } |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 643 | if (DEBUG_DRAG) { |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 644 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 645 | } |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 646 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 647 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 650 | void broadcastDragEndedLw() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 651 | if (DEBUG_DRAG) { |
| 652 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 653 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 654 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
| 655 | 0, 0, null, null, mDragResult); |
| 656 | for (WindowState ws: mNotifiedWindows) { |
| 657 | try { |
| 658 | ws.mClient.dispatchDragEvent(evt); |
| 659 | } catch (RemoteException e) { |
| 660 | Slog.w(TAG, "Unable to drag-end window " + ws); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 661 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 662 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 663 | mNotifiedWindows.clear(); |
| 664 | mDragInProgress = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 665 | evt.recycle(); |
| 666 | } |
| 667 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 668 | void endDragLw() { |
| 669 | mDragState.broadcastDragEndedLw(); |
| 670 | |
| 671 | // stop intercepting input |
| 672 | mDragState.unregister(); |
| 673 | mInputMonitor.updateInputWindowsLw(); |
| 674 | |
| 675 | // free our resources and drop all the object references |
| 676 | mDragState.reset(); |
| 677 | mDragState = null; |
| 678 | } |
| 679 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 680 | void notifyMoveLw(float x, float y) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 681 | final int myPid = Process.myPid(); |
| 682 | |
| 683 | // Move the surface to the given touch |
| 684 | mSurface.openTransaction(); |
| 685 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 686 | mSurface.closeTransaction(); |
| 687 | |
| 688 | // Tell the affected window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 689 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 690 | if (mLocalOnly) { |
| 691 | final IBinder touchedBinder = touchedWin.mClient.asBinder(); |
| 692 | if (touchedBinder != mLocalWin) { |
| 693 | // This drag is pinned only to the originating window, but the drag |
| 694 | // point is outside that window. Pretend it's over empty space. |
| 695 | touchedWin = null; |
| 696 | } |
| 697 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 698 | try { |
| 699 | // have we dragged over a new window? |
| 700 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 701 | if (DEBUG_DRAG) { |
| 702 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 703 | } |
| 704 | // force DRAG_EXITED_EVENT if appropriate |
| 705 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 706 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 707 | null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 708 | mTargetWindow.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 709 | if (myPid != mTargetWindow.mSession.mPid) { |
| 710 | evt.recycle(); |
| 711 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 712 | } |
| 713 | if (touchedWin != null) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 714 | if (false && DEBUG_DRAG) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 715 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 716 | } |
| 717 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 718 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 719 | null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 720 | touchedWin.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 721 | if (myPid != touchedWin.mSession.mPid) { |
| 722 | evt.recycle(); |
| 723 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 724 | } |
| 725 | } catch (RemoteException e) { |
| 726 | Slog.w(TAG, "can't send drag notification to windows"); |
| 727 | } |
| 728 | mTargetWindow = touchedWin; |
| 729 | } |
| 730 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 731 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 732 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 733 | // result from the recipient. |
| 734 | boolean notifyDropLw(float x, float y) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 735 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 736 | if (touchedWin == null) { |
| 737 | // "drop" outside a valid window -- no recipient to apply a |
| 738 | // timeout to, and we can send the drag-ended message immediately. |
| 739 | mDragResult = false; |
| 740 | return true; |
| 741 | } |
| 742 | |
| 743 | if (DEBUG_DRAG) { |
| 744 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 745 | } |
| 746 | final int myPid = Process.myPid(); |
| 747 | final IBinder token = touchedWin.mClient.asBinder(); |
| 748 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 749 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| 750 | null, mData, false); |
| 751 | try { |
| 752 | touchedWin.mClient.dispatchDragEvent(evt); |
| 753 | |
| 754 | // 5 second timeout for this window to respond to the drop |
| 755 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 756 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 757 | mH.sendMessageDelayed(msg, 5000); |
| 758 | } catch (RemoteException e) { |
| 759 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 760 | return true; |
| 761 | } finally { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 762 | if (myPid != touchedWin.mSession.mPid) { |
| 763 | evt.recycle(); |
| 764 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 765 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 766 | mToken = token; |
| 767 | return false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | // Find the visible, touch-deliverable window under the given point |
| 771 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 772 | WindowState touchedWin = null; |
| 773 | final int x = (int) xf; |
| 774 | final int y = (int) yf; |
| 775 | final ArrayList<WindowState> windows = mWindows; |
| 776 | final int N = windows.size(); |
| 777 | for (int i = N - 1; i >= 0; i--) { |
| 778 | WindowState child = windows.get(i); |
| 779 | final int flags = child.mAttrs.flags; |
| 780 | if (!child.isVisibleLw()) { |
| 781 | // not visible == don't tell about drags |
| 782 | continue; |
| 783 | } |
| 784 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 785 | // not touchable == don't tell about drags |
| 786 | continue; |
| 787 | } |
| 788 | // account for the window's decor etc |
| 789 | tmpRect.set(child.mFrame); |
| 790 | if (child.mTouchableInsets == ViewTreeObserver |
| 791 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 792 | // The point is inside of the window if it is |
| 793 | // inside the frame, AND the content part of that |
| 794 | // frame that was given by the application. |
| 795 | tmpRect.left += child.mGivenContentInsets.left; |
| 796 | tmpRect.top += child.mGivenContentInsets.top; |
| 797 | tmpRect.right -= child.mGivenContentInsets.right; |
| 798 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 799 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 800 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 801 | // The point is inside of the window if it is |
| 802 | // inside the frame, AND the visible part of that |
| 803 | // frame that was given by the application. |
| 804 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 805 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 806 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 807 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 808 | } |
| 809 | final int touchFlags = flags & |
| 810 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 811 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 812 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 813 | // Found it |
| 814 | touchedWin = child; |
| 815 | break; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | return touchedWin; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | DragState mDragState = null; |
| 824 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 825 | @Override |
| 826 | public void handleMotion(MotionEvent event, Runnable finishedCallback) { |
| 827 | boolean endDrag = false; |
| 828 | final float newX = event.getRawX(); |
| 829 | final float newY = event.getRawY(); |
| 830 | |
| 831 | try { |
| 832 | if (mDragState != null) { |
| 833 | switch (event.getAction()) { |
| 834 | case MotionEvent.ACTION_DOWN: { |
| 835 | if (DEBUG_DRAG) { |
| 836 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 837 | } |
| 838 | } break; |
| 839 | |
| 840 | case MotionEvent.ACTION_MOVE: { |
| 841 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 842 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 843 | mDragState.notifyMoveLw(newX, newY); |
| 844 | } |
| 845 | } break; |
| 846 | |
| 847 | case MotionEvent.ACTION_UP: { |
| 848 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 849 | + newX + "," + newY); |
| 850 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 851 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 852 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 853 | } break; |
| 854 | |
| 855 | case MotionEvent.ACTION_CANCEL: { |
| 856 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 857 | endDrag = true; |
| 858 | } break; |
| 859 | } |
| 860 | |
| 861 | if (endDrag) { |
| 862 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 863 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 864 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 865 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 866 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | } catch (Exception e) { |
| 870 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 871 | } finally { |
| 872 | finishedCallback.run(); |
| 873 | } |
| 874 | } |
| 875 | }; |
| 876 | |
| 877 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 878 | * Whether the UI is currently running in touch mode (not showing |
| 879 | * navigational focus because the user is directly pressing the screen). |
| 880 | */ |
| 881 | boolean mInTouchMode = false; |
| 882 | |
| 883 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 884 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 885 | new ArrayList<WindowChangeListener>(); |
| 886 | private boolean mWindowsChanged = false; |
| 887 | |
| 888 | public interface WindowChangeListener { |
| 889 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 890 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 893 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 894 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 895 | |
| 896 | // The frame use to limit the size of the app running in compatibility mode. |
| 897 | Rect mCompatibleScreenFrame = new Rect(); |
| 898 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 899 | Surface mBackgroundFillerSurface = null; |
| 900 | boolean mBackgroundFillerShown = false; |
| 901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | public static WindowManagerService main(Context context, |
| 903 | PowerManagerService pm, boolean haveInputMethods) { |
| 904 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 905 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | synchronized (thr) { |
| 908 | while (thr.mService == null) { |
| 909 | try { |
| 910 | thr.wait(); |
| 911 | } catch (InterruptedException e) { |
| 912 | } |
| 913 | } |
| 914 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | return thr.mService; |
| 917 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | static class WMThread extends Thread { |
| 920 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | private final Context mContext; |
| 923 | private final PowerManagerService mPM; |
| 924 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | public WMThread(Context context, PowerManagerService pm, |
| 927 | boolean haveInputMethods) { |
| 928 | super("WindowManager"); |
| 929 | mContext = context; |
| 930 | mPM = pm; |
| 931 | mHaveInputMethods = haveInputMethods; |
| 932 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | public void run() { |
| 935 | Looper.prepare(); |
| 936 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 937 | mHaveInputMethods); |
| 938 | android.os.Process.setThreadPriority( |
| 939 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 940 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | synchronized (this) { |
| 943 | mService = s; |
| 944 | notifyAll(); |
| 945 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | Looper.loop(); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | static class PolicyThread extends Thread { |
| 952 | private final WindowManagerPolicy mPolicy; |
| 953 | private final WindowManagerService mService; |
| 954 | private final Context mContext; |
| 955 | private final PowerManagerService mPM; |
| 956 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | public PolicyThread(WindowManagerPolicy policy, |
| 959 | WindowManagerService service, Context context, |
| 960 | PowerManagerService pm) { |
| 961 | super("WindowManagerPolicy"); |
| 962 | mPolicy = policy; |
| 963 | mService = service; |
| 964 | mContext = context; |
| 965 | mPM = pm; |
| 966 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | public void run() { |
| 969 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 970 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 973 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | android.os.Process.setThreadPriority( |
| 975 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 976 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 977 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | synchronized (this) { |
| 980 | mRunning = true; |
| 981 | notifyAll(); |
| 982 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 983 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | Looper.loop(); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | private WindowManagerService(Context context, PowerManagerService pm, |
| 989 | boolean haveInputMethods) { |
| 990 | mContext = context; |
| 991 | mHaveInputMethods = haveInputMethods; |
| 992 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 993 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 994 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | mPowerManager = pm; |
| 996 | mPowerManager.setPolicy(mPolicy); |
| 997 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 998 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 999 | "SCREEN_FROZEN"); |
| 1000 | mScreenFrozenLock.setReferenceCounted(false); |
| 1001 | |
| 1002 | mActivityManager = ActivityManagerNative.getDefault(); |
| 1003 | mBatteryStats = BatteryStatsService.getService(); |
| 1004 | |
| 1005 | // Get persisted window scale setting |
| 1006 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1007 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 1008 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1009 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1010 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1011 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 1012 | IntentFilter filter = new IntentFilter(); |
| 1013 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 1014 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 1015 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1016 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 1017 | "KEEP_SCREEN_ON_FLAG"); |
| 1018 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1020 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 1023 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | synchronized (thr) { |
| 1026 | while (!thr.mRunning) { |
| 1027 | try { |
| 1028 | thr.wait(); |
| 1029 | } catch (InterruptedException e) { |
| 1030 | } |
| 1031 | } |
| 1032 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1033 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1034 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | // Add ourself to the Watchdog monitors. |
| 1037 | Watchdog.getInstance().addMonitor(this); |
| 1038 | } |
| 1039 | |
| 1040 | @Override |
| 1041 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1042 | throws RemoteException { |
| 1043 | try { |
| 1044 | return super.onTransact(code, data, reply, flags); |
| 1045 | } catch (RuntimeException e) { |
| 1046 | // The window manager only throws security exceptions, so let's |
| 1047 | // log all others. |
| 1048 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1049 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | } |
| 1051 | throw e; |
| 1052 | } |
| 1053 | } |
| 1054 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1055 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1057 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | TAG, "Adding window " + window + " at " |
| 1059 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1060 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1061 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | } |
| 1063 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1064 | private void placeWindowBefore(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 + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1069 | mWindows.add(i, 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 | |
| 1073 | //This method finds out the index of a window that has the same app token as |
| 1074 | //win. used for z ordering the windows in mWindows |
| 1075 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1076 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1077 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | int jmax = localmWindows.size(); |
| 1079 | if(jmax == 0) { |
| 1080 | return -1; |
| 1081 | } |
| 1082 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1083 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | if(wentry.mAppToken == win.mAppToken) { |
| 1085 | return j; |
| 1086 | } |
| 1087 | } |
| 1088 | return -1; |
| 1089 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1092 | final IWindow client = win.mClient; |
| 1093 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1094 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1095 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | final int N = localmWindows.size(); |
| 1097 | final WindowState attached = win.mAttachedWindow; |
| 1098 | int i; |
| 1099 | if (attached == null) { |
| 1100 | int tokenWindowsPos = token.windows.size(); |
| 1101 | if (token.appWindowToken != null) { |
| 1102 | int index = tokenWindowsPos-1; |
| 1103 | if (index >= 0) { |
| 1104 | // If this application has existing windows, we |
| 1105 | // simply place the new window on top of them... but |
| 1106 | // keep the starting window on top. |
| 1107 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1108 | // Base windows go behind everything else. |
| 1109 | placeWindowBefore(token.windows.get(0), win); |
| 1110 | tokenWindowsPos = 0; |
| 1111 | } else { |
| 1112 | AppWindowToken atoken = win.mAppToken; |
| 1113 | if (atoken != null && |
| 1114 | token.windows.get(index) == atoken.startingWindow) { |
| 1115 | placeWindowBefore(token.windows.get(index), win); |
| 1116 | tokenWindowsPos--; |
| 1117 | } else { |
| 1118 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1119 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1120 | //there is a window above this one associated with the same |
| 1121 | //apptoken note that the window could be a floating window |
| 1122 | //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] | 1123 | //windows associated with this token. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1124 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1125 | TAG, "Adding window " + win + " at " |
| 1126 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1127 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1128 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1129 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1133 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | TAG, "Figuring out where to add app window " |
| 1135 | + client.asBinder() + " (token=" + token + ")"); |
| 1136 | // Figure out where the window should go, based on the |
| 1137 | // order of applications. |
| 1138 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1139 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | for (i=NA-1; i>=0; i--) { |
| 1141 | AppWindowToken t = mAppTokens.get(i); |
| 1142 | if (t == token) { |
| 1143 | i--; |
| 1144 | break; |
| 1145 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1146 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1147 | // We haven't reached the token yet; if this token |
| 1148 | // is not going to the bottom and has windows, we can |
| 1149 | // use it as an anchor for when we do reach the token. |
| 1150 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | pos = t.windows.get(0); |
| 1152 | } |
| 1153 | } |
| 1154 | // We now know the index into the apps. If we found |
| 1155 | // an app window above, that gives us the position; else |
| 1156 | // we need to look some more. |
| 1157 | if (pos != null) { |
| 1158 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1159 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | if (atoken != null) { |
| 1161 | final int NC = atoken.windows.size(); |
| 1162 | if (NC > 0) { |
| 1163 | WindowState bottom = atoken.windows.get(0); |
| 1164 | if (bottom.mSubLayer < 0) { |
| 1165 | pos = bottom; |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | placeWindowBefore(pos, win); |
| 1170 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1171 | // Continue looking down until we find the first |
| 1172 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | while (i >= 0) { |
| 1174 | AppWindowToken t = mAppTokens.get(i); |
| 1175 | final int NW = t.windows.size(); |
| 1176 | if (NW > 0) { |
| 1177 | pos = t.windows.get(NW-1); |
| 1178 | break; |
| 1179 | } |
| 1180 | i--; |
| 1181 | } |
| 1182 | if (pos != null) { |
| 1183 | // Move in front of any windows attached to this |
| 1184 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1185 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | if (atoken != null) { |
| 1187 | final int NC = atoken.windows.size(); |
| 1188 | if (NC > 0) { |
| 1189 | WindowState top = atoken.windows.get(NC-1); |
| 1190 | if (top.mSubLayer >= 0) { |
| 1191 | pos = top; |
| 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | placeWindowAfter(pos, win); |
| 1196 | } else { |
| 1197 | // Just search for the start of this layer. |
| 1198 | final int myLayer = win.mBaseLayer; |
| 1199 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1200 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | if (w.mBaseLayer > myLayer) { |
| 1202 | break; |
| 1203 | } |
| 1204 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1205 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1206 | TAG, "Adding window " + win + " at " |
| 1207 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1209 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | } |
| 1213 | } else { |
| 1214 | // Figure out where window should go, based on layer. |
| 1215 | final int myLayer = win.mBaseLayer; |
| 1216 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1217 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | i++; |
| 1219 | break; |
| 1220 | } |
| 1221 | } |
| 1222 | if (i < 0) i = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1223 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1224 | TAG, "Adding window " + win + " at " |
| 1225 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1227 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | } |
| 1229 | if (addToToken) { |
| 1230 | token.windows.add(tokenWindowsPos, win); |
| 1231 | } |
| 1232 | |
| 1233 | } else { |
| 1234 | // Figure out this window's ordering relative to the window |
| 1235 | // it is attached to. |
| 1236 | final int NA = token.windows.size(); |
| 1237 | final int sublayer = win.mSubLayer; |
| 1238 | int largestSublayer = Integer.MIN_VALUE; |
| 1239 | WindowState windowWithLargestSublayer = null; |
| 1240 | for (i=0; i<NA; i++) { |
| 1241 | WindowState w = token.windows.get(i); |
| 1242 | final int wSublayer = w.mSubLayer; |
| 1243 | if (wSublayer >= largestSublayer) { |
| 1244 | largestSublayer = wSublayer; |
| 1245 | windowWithLargestSublayer = w; |
| 1246 | } |
| 1247 | if (sublayer < 0) { |
| 1248 | // For negative sublayers, we go below all windows |
| 1249 | // in the same sublayer. |
| 1250 | if (wSublayer >= sublayer) { |
| 1251 | if (addToToken) { |
| 1252 | token.windows.add(i, win); |
| 1253 | } |
| 1254 | placeWindowBefore( |
| 1255 | wSublayer >= 0 ? attached : w, win); |
| 1256 | break; |
| 1257 | } |
| 1258 | } else { |
| 1259 | // For positive sublayers, we go above all windows |
| 1260 | // in the same sublayer. |
| 1261 | if (wSublayer > sublayer) { |
| 1262 | if (addToToken) { |
| 1263 | token.windows.add(i, win); |
| 1264 | } |
| 1265 | placeWindowBefore(w, win); |
| 1266 | break; |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | if (i >= NA) { |
| 1271 | if (addToToken) { |
| 1272 | token.windows.add(win); |
| 1273 | } |
| 1274 | if (sublayer < 0) { |
| 1275 | placeWindowBefore(attached, win); |
| 1276 | } else { |
| 1277 | placeWindowAfter(largestSublayer >= 0 |
| 1278 | ? windowWithLargestSublayer |
| 1279 | : attached, |
| 1280 | win); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | if (win.mAppToken != null && addToToken) { |
| 1286 | win.mAppToken.allAppWindows.add(win); |
| 1287 | } |
| 1288 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | static boolean canBeImeTarget(WindowState w) { |
| 1291 | final int fl = w.mAttrs.flags |
| 1292 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1293 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1294 | return w.isVisibleOrAdding(); |
| 1295 | } |
| 1296 | return false; |
| 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 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1300 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | final int N = localmWindows.size(); |
| 1302 | WindowState w = null; |
| 1303 | int i = N; |
| 1304 | while (i > 0) { |
| 1305 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1306 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1307 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1308 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1310 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1311 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | // Yet more tricksyness! If this window is a "starting" |
| 1314 | // window, we do actually want to be on top of it, but |
| 1315 | // it is not -really- where input will go. So if the caller |
| 1316 | // is not actually looking to move the IME, look down below |
| 1317 | // for a real window to target... |
| 1318 | if (!willMove |
| 1319 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1320 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1321 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1323 | i--; |
| 1324 | w = wb; |
| 1325 | } |
| 1326 | } |
| 1327 | break; |
| 1328 | } |
| 1329 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1332 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1333 | 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] | 1334 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | if (willMove && w != null) { |
| 1337 | final WindowState curTarget = mInputMethodTarget; |
| 1338 | if (curTarget != null && curTarget.mAppToken != null) { |
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 | // Now some fun for dealing with window animations that |
| 1341 | // modify the Z order. We need to look at all windows below |
| 1342 | // the current target that are in this app, finding the highest |
| 1343 | // visible one in layering. |
| 1344 | AppWindowToken token = curTarget.mAppToken; |
| 1345 | WindowState highestTarget = null; |
| 1346 | int highestPos = 0; |
| 1347 | if (token.animating || token.animation != null) { |
| 1348 | int pos = 0; |
| 1349 | pos = localmWindows.indexOf(curTarget); |
| 1350 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1351 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1352 | if (win.mAppToken != token) { |
| 1353 | break; |
| 1354 | } |
| 1355 | if (!win.mRemoved) { |
| 1356 | if (highestTarget == null || win.mAnimLayer > |
| 1357 | highestTarget.mAnimLayer) { |
| 1358 | highestTarget = win; |
| 1359 | highestPos = pos; |
| 1360 | } |
| 1361 | } |
| 1362 | pos--; |
| 1363 | } |
| 1364 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1367 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | + mNextAppTransition + " " + highestTarget |
| 1369 | + " animating=" + highestTarget.isAnimating() |
| 1370 | + " layer=" + highestTarget.mAnimLayer |
| 1371 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1372 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1373 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | // If we are currently setting up for an animation, |
| 1375 | // hold everything until we can find out what will happen. |
| 1376 | mInputMethodTargetWaitingAnim = true; |
| 1377 | mInputMethodTarget = highestTarget; |
| 1378 | return highestPos + 1; |
| 1379 | } else if (highestTarget.isAnimating() && |
| 1380 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1381 | // If the window we are currently targeting is involved |
| 1382 | // with an animation, and it is on top of the next target |
| 1383 | // we will be over, then hold off on moving until |
| 1384 | // that is done. |
| 1385 | mInputMethodTarget = highestTarget; |
| 1386 | return highestPos + 1; |
| 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1391 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1392 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | if (w != null) { |
| 1394 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1395 | if (DEBUG_INPUT_METHOD) { |
| 1396 | RuntimeException e = null; |
| 1397 | if (!HIDE_STACK_CRAWLS) { |
| 1398 | e = new RuntimeException(); |
| 1399 | e.fillInStackTrace(); |
| 1400 | } |
| 1401 | Slog.w(TAG, "Moving IM target from " |
| 1402 | + mInputMethodTarget + " to " + w, e); |
| 1403 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | mInputMethodTarget = w; |
| 1405 | if (w.mAppToken != null) { |
| 1406 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1407 | } else { |
| 1408 | setInputMethodAnimLayerAdjustment(0); |
| 1409 | } |
| 1410 | } |
| 1411 | return i+1; |
| 1412 | } |
| 1413 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1414 | if (DEBUG_INPUT_METHOD) { |
| 1415 | RuntimeException e = null; |
| 1416 | if (!HIDE_STACK_CRAWLS) { |
| 1417 | e = new RuntimeException(); |
| 1418 | e.fillInStackTrace(); |
| 1419 | } |
| 1420 | Slog.w(TAG, "Moving IM target from " |
| 1421 | + mInputMethodTarget + " to null", e); |
| 1422 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | mInputMethodTarget = null; |
| 1424 | setInputMethodAnimLayerAdjustment(0); |
| 1425 | } |
| 1426 | return -1; |
| 1427 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1430 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1431 | if (pos >= 0) { |
| 1432 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1433 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1434 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1436 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1437 | moveInputMethodDialogsLocked(pos+1); |
| 1438 | return; |
| 1439 | } |
| 1440 | win.mTargetAppToken = null; |
| 1441 | addWindowToListInOrderLocked(win, true); |
| 1442 | moveInputMethodDialogsLocked(pos); |
| 1443 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1445 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1446 | 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] | 1447 | mInputMethodAnimLayerAdjustment = adj; |
| 1448 | WindowState imw = mInputMethodWindow; |
| 1449 | if (imw != null) { |
| 1450 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1451 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | + " anim layer: " + imw.mAnimLayer); |
| 1453 | int wi = imw.mChildWindows.size(); |
| 1454 | while (wi > 0) { |
| 1455 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1456 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1457 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1458 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | + " anim layer: " + cw.mAnimLayer); |
| 1460 | } |
| 1461 | } |
| 1462 | int di = mInputMethodDialogs.size(); |
| 1463 | while (di > 0) { |
| 1464 | di --; |
| 1465 | imw = mInputMethodDialogs.get(di); |
| 1466 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1467 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | + " anim layer: " + imw.mAnimLayer); |
| 1469 | } |
| 1470 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1473 | int wpos = mWindows.indexOf(win); |
| 1474 | if (wpos >= 0) { |
| 1475 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1476 | 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] | 1477 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1478 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | int NC = win.mChildWindows.size(); |
| 1480 | while (NC > 0) { |
| 1481 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1482 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | int cpos = mWindows.indexOf(cw); |
| 1484 | if (cpos >= 0) { |
| 1485 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1486 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1487 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | mWindows.remove(cpos); |
| 1489 | } |
| 1490 | } |
| 1491 | } |
| 1492 | return interestingPos; |
| 1493 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1496 | addWindowToListInOrderLocked(win, false); |
| 1497 | // This is a hack to get all of the child windows added as well |
| 1498 | // at the right position. Child windows should be rare and |
| 1499 | // this case should be rare, so it shouldn't be that big a deal. |
| 1500 | int wpos = mWindows.indexOf(win); |
| 1501 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1502 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1503 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1504 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1505 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | reAddWindowLocked(wpos, win); |
| 1507 | } |
| 1508 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | void logWindowList(String prefix) { |
| 1511 | int N = mWindows.size(); |
| 1512 | while (N > 0) { |
| 1513 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1514 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | } |
| 1516 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | void moveInputMethodDialogsLocked(int pos) { |
| 1519 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1522 | 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] | 1523 | for (int i=0; i<N; i++) { |
| 1524 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1525 | } |
| 1526 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1527 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | logWindowList(" "); |
| 1529 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | if (pos >= 0) { |
| 1532 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1533 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1534 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1535 | if (wp == mInputMethodWindow) { |
| 1536 | pos++; |
| 1537 | } |
| 1538 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1539 | 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] | 1540 | for (int i=0; i<N; i++) { |
| 1541 | WindowState win = dialogs.get(i); |
| 1542 | win.mTargetAppToken = targetAppToken; |
| 1543 | pos = reAddWindowLocked(pos, win); |
| 1544 | } |
| 1545 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1546 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | logWindowList(" "); |
| 1548 | } |
| 1549 | return; |
| 1550 | } |
| 1551 | for (int i=0; i<N; i++) { |
| 1552 | WindowState win = dialogs.get(i); |
| 1553 | win.mTargetAppToken = null; |
| 1554 | reAddWindowToListInOrderLocked(win); |
| 1555 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1556 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | logWindowList(" "); |
| 1558 | } |
| 1559 | } |
| 1560 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1562 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1563 | final WindowState imWin = mInputMethodWindow; |
| 1564 | final int DN = mInputMethodDialogs.size(); |
| 1565 | if (imWin == null && DN == 0) { |
| 1566 | return false; |
| 1567 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1570 | if (imPos >= 0) { |
| 1571 | // In this case, the input method windows are to be placed |
| 1572 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | // First check to see if the input method windows are already |
| 1575 | // located here, and contiguous. |
| 1576 | final int N = mWindows.size(); |
| 1577 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1578 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | // Figure out the actual input method window that should be |
| 1581 | // at the bottom of their stack. |
| 1582 | WindowState baseImWin = imWin != null |
| 1583 | ? imWin : mInputMethodDialogs.get(0); |
| 1584 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1585 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1587 | } |
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 | if (firstImWin == baseImWin) { |
| 1590 | // The windows haven't moved... but are they still contiguous? |
| 1591 | // First find the top IM window. |
| 1592 | int pos = imPos+1; |
| 1593 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1594 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | break; |
| 1596 | } |
| 1597 | pos++; |
| 1598 | } |
| 1599 | pos++; |
| 1600 | // Now there should be no more input method windows above. |
| 1601 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1602 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | break; |
| 1604 | } |
| 1605 | pos++; |
| 1606 | } |
| 1607 | if (pos >= N) { |
| 1608 | // All is good! |
| 1609 | return false; |
| 1610 | } |
| 1611 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | if (imWin != null) { |
| 1614 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1615 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1616 | logWindowList(" "); |
| 1617 | } |
| 1618 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1619 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1620 | 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] | 1621 | logWindowList(" "); |
| 1622 | } |
| 1623 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1624 | reAddWindowLocked(imPos, imWin); |
| 1625 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1626 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | logWindowList(" "); |
| 1628 | } |
| 1629 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1630 | } else { |
| 1631 | moveInputMethodDialogsLocked(imPos); |
| 1632 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | } else { |
| 1635 | // In this case, the input method windows go in a fixed layer, |
| 1636 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1639 | 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] | 1640 | tmpRemoveWindowLocked(0, imWin); |
| 1641 | imWin.mTargetAppToken = null; |
| 1642 | reAddWindowToListInOrderLocked(imWin); |
| 1643 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1644 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | logWindowList(" "); |
| 1646 | } |
| 1647 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1648 | } else { |
| 1649 | moveInputMethodDialogsLocked(-1);; |
| 1650 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1654 | if (needAssignLayers) { |
| 1655 | assignLayersLocked(); |
| 1656 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | return true; |
| 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 | void adjustInputMethodDialogsLocked() { |
| 1662 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1663 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1664 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1665 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1666 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1667 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1668 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1669 | ? wallpaperTarget.mAppToken.animation : null) |
| 1670 | + " upper=" + mUpperWallpaperTarget |
| 1671 | + " lower=" + mLowerWallpaperTarget); |
| 1672 | return (wallpaperTarget != null |
| 1673 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1674 | && wallpaperTarget.mAppToken.animation != null))) |
| 1675 | || mUpperWallpaperTarget != null |
| 1676 | || mLowerWallpaperTarget != null; |
| 1677 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1678 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1679 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1680 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1681 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1682 | int adjustWallpaperWindowsLocked() { |
| 1683 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1684 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1685 | final int dw = mDisplay.getWidth(); |
| 1686 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1687 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1688 | // First find top-most window that has asked to be on top of the |
| 1689 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1690 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1691 | int N = localmWindows.size(); |
| 1692 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1693 | WindowState foundW = null; |
| 1694 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1695 | WindowState topCurW = null; |
| 1696 | int topCurI = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1697 | int i = N; |
| 1698 | while (i > 0) { |
| 1699 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1700 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1701 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1702 | if (topCurW == null) { |
| 1703 | topCurW = w; |
| 1704 | topCurI = i; |
| 1705 | } |
| 1706 | continue; |
| 1707 | } |
| 1708 | topCurW = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1709 | if (w.mAppToken != null) { |
| 1710 | // If this window's app token is hidden and not animating, |
| 1711 | // it is of no interest to us. |
| 1712 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1713 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1714 | "Skipping hidden or animating token: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1715 | topCurW = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1716 | continue; |
| 1717 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1718 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1719 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1720 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1721 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1722 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1723 | && (mWallpaperTarget == w |
| 1724 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1725 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1726 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1727 | foundW = w; |
| 1728 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1729 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1730 | && w.mAppToken.animation != null) |
| 1731 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1732 | // The current wallpaper target is animating, so we'll |
| 1733 | // look behind it for another possible target and figure |
| 1734 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1735 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1736 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1737 | continue; |
| 1738 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1739 | break; |
| 1740 | } |
| 1741 | } |
| 1742 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1743 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1744 | // If we are currently waiting for an app transition, and either |
| 1745 | // the current target or the next target are involved with it, |
| 1746 | // then hold off on doing anything with the wallpaper. |
| 1747 | // Note that we are checking here for just whether the target |
| 1748 | // is part of an app token... which is potentially overly aggressive |
| 1749 | // (the app token may not be involved in the transition), but good |
| 1750 | // enough (we'll just wait until whatever transition is pending |
| 1751 | // executes). |
| 1752 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1753 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1754 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1755 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1756 | } |
| 1757 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1758 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1759 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1760 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1761 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1762 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1763 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1764 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1765 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1766 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1767 | + " oldTarget: " + mWallpaperTarget); |
| 1768 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1769 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1770 | mLowerWallpaperTarget = null; |
| 1771 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1772 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1773 | WindowState oldW = mWallpaperTarget; |
| 1774 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1775 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1776 | // Now what is happening... if the current and new targets are |
| 1777 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1778 | if (foundW != null && oldW != null) { |
| 1779 | boolean oldAnim = oldW.mAnimation != null |
| 1780 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1781 | boolean foundAnim = foundW.mAnimation != null |
| 1782 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1783 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1784 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1785 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1786 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1787 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1788 | int oldI = localmWindows.indexOf(oldW); |
| 1789 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1790 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1791 | } |
| 1792 | if (oldI >= 0) { |
| 1793 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1794 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1795 | + "=" + oldW + "; new#" + foundI |
| 1796 | + "=" + foundW); |
| 1797 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1798 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1799 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1800 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
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, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1803 | } |
| 1804 | mWallpaperTarget = oldW; |
| 1805 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1806 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1807 | // Now set the upper and lower wallpaper targets |
| 1808 | // correctly, and make sure that we are positioning |
| 1809 | // the wallpaper below the lower. |
| 1810 | if (foundI > oldI) { |
| 1811 | // The new target is on top of the old one. |
| 1812 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1813 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1814 | } |
| 1815 | mUpperWallpaperTarget = foundW; |
| 1816 | mLowerWallpaperTarget = oldW; |
| 1817 | foundW = oldW; |
| 1818 | foundI = oldI; |
| 1819 | } else { |
| 1820 | // The new target is below the old one. |
| 1821 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1822 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1823 | } |
| 1824 | mUpperWallpaperTarget = oldW; |
| 1825 | mLowerWallpaperTarget = foundW; |
| 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1830 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1831 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1832 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1833 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1834 | || (mLowerWallpaperTarget.mAppToken != null |
| 1835 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1836 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1837 | || (mUpperWallpaperTarget.mAppToken != null |
| 1838 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1839 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1840 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1841 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1842 | } |
| 1843 | mLowerWallpaperTarget = null; |
| 1844 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1845 | } |
| 1846 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1847 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1848 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1849 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1850 | // The window is visible to the compositor... but is it visible |
| 1851 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1852 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1853 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1854 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1855 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1856 | // its layer adjustment. Only do this if we are not transfering |
| 1857 | // between two wallpaper targets. |
| 1858 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1859 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1860 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1861 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1862 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1863 | * TYPE_LAYER_MULTIPLIER |
| 1864 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1865 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1866 | // Now w is the window we are supposed to be behind... but we |
| 1867 | // 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] | 1868 | // AND any starting window associated with it, AND below the |
| 1869 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1870 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1871 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1872 | if (wb.mBaseLayer < maxLayer && |
| 1873 | wb.mAttachedWindow != foundW && |
Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1874 | wb.mAttachedWindow != foundW.mAttachedWindow && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1875 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1876 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1877 | // This window is not related to the previous one in any |
| 1878 | // interesting way, so stop here. |
| 1879 | break; |
| 1880 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1881 | foundW = wb; |
| 1882 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1883 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1884 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1885 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1886 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1887 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1888 | if (foundW == null && topCurW != null) { |
| 1889 | // There is no wallpaper target, so it goes at the bottom. |
| 1890 | // We will assume it is the same place as last time, if known. |
| 1891 | foundW = topCurW; |
| 1892 | foundI = topCurI+1; |
| 1893 | } else { |
| 1894 | // Okay i is the position immediately above the wallpaper. Look at |
| 1895 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1896 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1897 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1898 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1899 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1900 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1901 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1902 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1903 | } |
| 1904 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1905 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1906 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1907 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1908 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1909 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1910 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1911 | // are correctly placed. |
| 1912 | int curTokenIndex = mWallpaperTokens.size(); |
| 1913 | while (curTokenIndex > 0) { |
| 1914 | curTokenIndex--; |
| 1915 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1916 | if (token.hidden == visible) { |
| 1917 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1918 | token.hidden = !visible; |
| 1919 | // Need to do a layout to ensure the wallpaper now has the |
| 1920 | // correct size. |
| 1921 | mLayoutNeeded = true; |
| 1922 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1923 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1924 | int curWallpaperIndex = token.windows.size(); |
| 1925 | while (curWallpaperIndex > 0) { |
| 1926 | curWallpaperIndex--; |
| 1927 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1928 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1929 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1930 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1931 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1932 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1933 | // First, make sure the client has the current visibility |
| 1934 | // state. |
| 1935 | if (wallpaper.mWallpaperVisible != visible) { |
| 1936 | wallpaper.mWallpaperVisible = visible; |
| 1937 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1938 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1939 | "Setting visibility of wallpaper " + wallpaper |
| 1940 | + ": " + visible); |
| 1941 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1942 | } catch (RemoteException e) { |
| 1943 | } |
| 1944 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1945 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1946 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1947 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1948 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1949 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1950 | // First, if this window is at the current index, then all |
| 1951 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1952 | if (wallpaper == foundW) { |
| 1953 | foundI--; |
| 1954 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1955 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1956 | continue; |
| 1957 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1958 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1959 | // The window didn't match... the current wallpaper window, |
| 1960 | // wherever it is, is in the wrong place, so make sure it is |
| 1961 | // not in the list. |
| 1962 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1963 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1964 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1965 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1966 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1967 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1968 | if (oldIndex < foundI) { |
| 1969 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1970 | } |
| 1971 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1972 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1973 | // Now stick it in. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1974 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1975 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1976 | + " from " + oldIndex + " to " + foundI); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1977 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1978 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1979 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1980 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1981 | } |
| 1982 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1983 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1984 | return changed; |
| 1985 | } |
| 1986 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1987 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1988 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1989 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1990 | mWallpaperAnimLayerAdjustment = adj; |
| 1991 | int curTokenIndex = mWallpaperTokens.size(); |
| 1992 | while (curTokenIndex > 0) { |
| 1993 | curTokenIndex--; |
| 1994 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1995 | int curWallpaperIndex = token.windows.size(); |
| 1996 | while (curWallpaperIndex > 0) { |
| 1997 | curWallpaperIndex--; |
| 1998 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1999 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2000 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2001 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | } |
| 2005 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2006 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 2007 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2008 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2009 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2010 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2011 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2012 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 2013 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 2014 | changed = wallpaperWin.mXOffset != offset; |
| 2015 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2016 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2017 | + wallpaperWin + " x: " + offset); |
| 2018 | wallpaperWin.mXOffset = offset; |
| 2019 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2020 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2021 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2022 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2023 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2024 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2025 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2026 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2027 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2028 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2029 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2030 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2031 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2032 | + wallpaperWin + " y: " + offset); |
| 2033 | changed = true; |
| 2034 | wallpaperWin.mYOffset = offset; |
| 2035 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2036 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2037 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2038 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2039 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2040 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2041 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2042 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2043 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2044 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2045 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2046 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2047 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2048 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2049 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2050 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2051 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2052 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2053 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2054 | if (mWaitingOnWallpaper != null) { |
| 2055 | long start = SystemClock.uptimeMillis(); |
| 2056 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2057 | < start) { |
| 2058 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2059 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2060 | "Waiting for offset complete..."); |
| 2061 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2062 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2063 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2064 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2065 | if ((start+WALLPAPER_TIMEOUT) |
| 2066 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2067 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2068 | + wallpaperWin); |
| 2069 | mLastWallpaperTimeoutTime = start; |
| 2070 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2071 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2072 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2073 | } |
| 2074 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2075 | } catch (RemoteException e) { |
| 2076 | } |
| 2077 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2078 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2079 | return changed; |
| 2080 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2081 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2082 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2083 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2084 | if (mWaitingOnWallpaper != null && |
| 2085 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2086 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2087 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2091 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2092 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2093 | final int dw = mDisplay.getWidth(); |
| 2094 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2095 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2096 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2097 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2098 | WindowState target = mWallpaperTarget; |
| 2099 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2100 | if (target.mWallpaperX >= 0) { |
| 2101 | mLastWallpaperX = target.mWallpaperX; |
| 2102 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2103 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2104 | } |
| 2105 | if (target.mWallpaperY >= 0) { |
| 2106 | mLastWallpaperY = target.mWallpaperY; |
| 2107 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2108 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2109 | } |
| 2110 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2111 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2112 | int curTokenIndex = mWallpaperTokens.size(); |
| 2113 | while (curTokenIndex > 0) { |
| 2114 | curTokenIndex--; |
| 2115 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2116 | int curWallpaperIndex = token.windows.size(); |
| 2117 | while (curWallpaperIndex > 0) { |
| 2118 | curWallpaperIndex--; |
| 2119 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2120 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2121 | wallpaper.computeShownFrameLocked(); |
| 2122 | changed = true; |
| 2123 | // We only want to be synchronous with one wallpaper. |
| 2124 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2125 | } |
| 2126 | } |
| 2127 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2128 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2129 | return changed; |
| 2130 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2131 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2132 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2133 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2134 | final int dw = mDisplay.getWidth(); |
| 2135 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2136 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2137 | int curTokenIndex = mWallpaperTokens.size(); |
| 2138 | while (curTokenIndex > 0) { |
| 2139 | curTokenIndex--; |
| 2140 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2141 | if (token.hidden == visible) { |
| 2142 | token.hidden = !visible; |
| 2143 | // Need to do a layout to ensure the wallpaper now has the |
| 2144 | // correct size. |
| 2145 | mLayoutNeeded = true; |
| 2146 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2147 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2148 | int curWallpaperIndex = token.windows.size(); |
| 2149 | while (curWallpaperIndex > 0) { |
| 2150 | curWallpaperIndex--; |
| 2151 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2152 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2153 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2154 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2155 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2156 | if (wallpaper.mWallpaperVisible != visible) { |
| 2157 | wallpaper.mWallpaperVisible = visible; |
| 2158 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2159 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2160 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2161 | + ": " + visible); |
| 2162 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2163 | } catch (RemoteException e) { |
| 2164 | } |
| 2165 | } |
| 2166 | } |
| 2167 | } |
| 2168 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | public int addWindow(Session session, IWindow client, |
| 2171 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2172 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | int res = mPolicy.checkAddPermission(attrs); |
| 2174 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2175 | return res; |
| 2176 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | boolean reportNewConfig = false; |
| 2179 | WindowState attachedWindow = null; |
| 2180 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2181 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2185 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2186 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2189 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2190 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2191 | } |
| 2192 | |
| 2193 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2194 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2195 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2196 | 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] | 2197 | + attrs.token + ". Aborting."); |
| 2198 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2199 | } |
| 2200 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2201 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2202 | 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] | 2203 | + attrs.token + ". Aborting."); |
| 2204 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | boolean addToken = false; |
| 2209 | WindowToken token = mTokenMap.get(attrs.token); |
| 2210 | if (token == null) { |
| 2211 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2212 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2213 | 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] | 2214 | + attrs.token + ". Aborting."); |
| 2215 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2216 | } |
| 2217 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2218 | 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] | 2219 | + attrs.token + ". Aborting."); |
| 2220 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2221 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2222 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2223 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2224 | + attrs.token + ". Aborting."); |
| 2225 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2226 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2227 | token = new WindowToken(attrs.token, -1, false); |
| 2228 | addToken = true; |
| 2229 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2230 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2231 | AppWindowToken atoken = token.appWindowToken; |
| 2232 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2233 | 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] | 2234 | + token + ". Aborting."); |
| 2235 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2236 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2237 | 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] | 2238 | + token + ". Aborting."); |
| 2239 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2240 | } |
| 2241 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2242 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2243 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2244 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2245 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2246 | } |
| 2247 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2248 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2249 | 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] | 2250 | + attrs.token + ". Aborting."); |
| 2251 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2252 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2253 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2254 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2255 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2256 | + attrs.token + ". Aborting."); |
| 2257 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2258 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | win = new WindowState(session, client, token, |
| 2262 | attachedWindow, attrs, viewVisibility); |
| 2263 | if (win.mDeathRecipient == null) { |
| 2264 | // Client has apparently died, so there is no reason to |
| 2265 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2266 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | + " that is dead, aborting."); |
| 2268 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2269 | } |
| 2270 | |
| 2271 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2274 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2275 | return res; |
| 2276 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2277 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2278 | if (outInputChannel != null) { |
| 2279 | String name = win.makeInputChannelName(); |
| 2280 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2281 | win.mInputChannel = inputChannels[0]; |
| 2282 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2283 | |
| 2284 | mInputManager.registerInputChannel(win.mInputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2285 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | |
| 2287 | // From now on, no exceptions or errors allowed! |
| 2288 | |
| 2289 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2290 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2291 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2292 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | if (addToken) { |
| 2294 | mTokenMap.put(attrs.token, token); |
| 2295 | mTokenList.add(token); |
| 2296 | } |
| 2297 | win.attach(); |
| 2298 | mWindowMap.put(client.asBinder(), win); |
| 2299 | |
| 2300 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2301 | token.appWindowToken != null) { |
| 2302 | token.appWindowToken.startingWindow = win; |
| 2303 | } |
| 2304 | |
| 2305 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2308 | mInputMethodWindow = win; |
| 2309 | addInputMethodWindowToListLocked(win); |
| 2310 | imMayMove = false; |
| 2311 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2312 | mInputMethodDialogs.add(win); |
| 2313 | addWindowToListInOrderLocked(win, true); |
| 2314 | adjustInputMethodDialogsLocked(); |
| 2315 | imMayMove = false; |
| 2316 | } else { |
| 2317 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2318 | if (attrs.type == TYPE_WALLPAPER) { |
| 2319 | mLastWallpaperTimeoutTime = 0; |
| 2320 | adjustWallpaperWindowsLocked(); |
| 2321 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2322 | adjustWallpaperWindowsLocked(); |
| 2323 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2324 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2330 | if (mInTouchMode) { |
| 2331 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2332 | } |
| 2333 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2334 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2335 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2336 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2337 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | if (win.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2339 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2340 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | imMayMove = false; |
| 2342 | } |
| 2343 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2345 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2346 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2349 | assignLayersLocked(); |
| 2350 | // Don't do layout here, the window must call |
| 2351 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2353 | //dump(); |
| 2354 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2355 | if (focusChanged) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2356 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2357 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2358 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2359 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | TAG, "New client " + client.asBinder() |
| 2361 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2362 | |
| 2363 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2364 | reportNewConfig = true; |
| 2365 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | } |
| 2367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | if (reportNewConfig) { |
| 2369 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2370 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2372 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | return res; |
| 2375 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | public void removeWindow(Session session, IWindow client) { |
| 2378 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2379 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2380 | if (win == null) { |
| 2381 | return; |
| 2382 | } |
| 2383 | removeWindowLocked(session, win); |
| 2384 | } |
| 2385 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | public void removeWindowLocked(Session session, WindowState win) { |
| 2388 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2389 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | TAG, "Remove " + win + " client=" |
| 2391 | + Integer.toHexString(System.identityHashCode( |
| 2392 | win.mClient.asBinder())) |
| 2393 | + ", surface=" + win.mSurface); |
| 2394 | |
| 2395 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2396 | |
| 2397 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2398 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2399 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2401 | + " mExiting=" + win.mExiting |
| 2402 | + " isAnimating=" + win.isAnimating() |
| 2403 | + " app-animation=" |
| 2404 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2405 | + " inPendingTransaction=" |
| 2406 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2407 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2408 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2409 | boolean wasVisible = false; |
| 2410 | // First, see if we need to run an animation. If we do, we have |
| 2411 | // to hold off on removing the window until the animation is done. |
| 2412 | // If the display is frozen, just remove immediately, since the |
| 2413 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2414 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2415 | // If we are not currently running the exit animation, we |
| 2416 | // need to see about starting one. |
| 2417 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2419 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2420 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2421 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2422 | } |
| 2423 | // Try starting an animation. |
| 2424 | if (applyAnimationLocked(win, transit, false)) { |
| 2425 | win.mExiting = true; |
| 2426 | } |
| 2427 | } |
| 2428 | if (win.mExiting || win.isAnimating()) { |
| 2429 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2430 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | win.mExiting = true; |
| 2432 | win.mRemoveOnExit = true; |
| 2433 | mLayoutNeeded = true; |
| 2434 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2435 | performLayoutAndPlaceSurfacesLocked(); |
| 2436 | if (win.mAppToken != null) { |
| 2437 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2438 | } |
| 2439 | //dump(); |
| 2440 | Binder.restoreCallingIdentity(origId); |
| 2441 | return; |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | removeWindowInnerLocked(session, win); |
| 2446 | // Removing a visible window will effect the computed orientation |
| 2447 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2448 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2449 | != mForcedAppOrientation |
| 2450 | && updateOrientationFromAppTokensLocked()) { |
| 2451 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2452 | } |
| 2453 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2454 | Binder.restoreCallingIdentity(origId); |
| 2455 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | private void removeWindowInnerLocked(Session session, WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2460 | if (mInputMethodTarget == win) { |
| 2461 | moveInputMethodWindowsIfNeededLocked(false); |
| 2462 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2463 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2464 | if (false) { |
| 2465 | RuntimeException e = new RuntimeException("here"); |
| 2466 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2467 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2468 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | mPolicy.removeWindowLw(win); |
| 2471 | win.removeLocked(); |
| 2472 | |
| 2473 | mWindowMap.remove(win.mClient.asBinder()); |
| 2474 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2475 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2476 | 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] | 2477 | |
| 2478 | if (mInputMethodWindow == win) { |
| 2479 | mInputMethodWindow = null; |
| 2480 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2481 | mInputMethodDialogs.remove(win); |
| 2482 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2484 | final WindowToken token = win.mToken; |
| 2485 | final AppWindowToken atoken = win.mAppToken; |
| 2486 | token.windows.remove(win); |
| 2487 | if (atoken != null) { |
| 2488 | atoken.allAppWindows.remove(win); |
| 2489 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2490 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2491 | TAG, "**** Removing window " + win + ": count=" |
| 2492 | + token.windows.size()); |
| 2493 | if (token.windows.size() == 0) { |
| 2494 | if (!token.explicit) { |
| 2495 | mTokenMap.remove(token.token); |
| 2496 | mTokenList.remove(token); |
| 2497 | } else if (atoken != null) { |
| 2498 | atoken.firstWindowDrawn = false; |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | if (atoken != null) { |
| 2503 | if (atoken.startingWindow == win) { |
| 2504 | atoken.startingWindow = null; |
| 2505 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2506 | // If this is the last window and we had requested a starting |
| 2507 | // transition window, well there is no point now. |
| 2508 | atoken.startingData = null; |
| 2509 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2510 | // If this is the last window except for a starting transition |
| 2511 | // window, we need to get rid of the starting transition. |
| 2512 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2513 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | + ": no more real windows"); |
| 2515 | } |
| 2516 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2517 | mH.sendMessage(m); |
| 2518 | } |
| 2519 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2520 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2521 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2522 | mLastWallpaperTimeoutTime = 0; |
| 2523 | adjustWallpaperWindowsLocked(); |
| 2524 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2525 | adjustWallpaperWindowsLocked(); |
| 2526 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | if (!mInLayout) { |
| 2529 | assignLayersLocked(); |
| 2530 | mLayoutNeeded = true; |
| 2531 | performLayoutAndPlaceSurfacesLocked(); |
| 2532 | if (win.mAppToken != null) { |
| 2533 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2534 | } |
| 2535 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2536 | |
| 2537 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2540 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2541 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2542 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2543 | if (where != null) { |
| 2544 | Slog.i(TAG, str, where); |
| 2545 | } else { |
| 2546 | Slog.i(TAG, str); |
| 2547 | } |
| 2548 | } |
| 2549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2551 | long origId = Binder.clearCallingIdentity(); |
| 2552 | try { |
| 2553 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2554 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | if ((w != null) && (w.mSurface != null)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2556 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | Surface.openTransaction(); |
| 2558 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2559 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2560 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2561 | w.mSurface.setTransparentRegionHint(region); |
| 2562 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2563 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2564 | Surface.closeTransaction(); |
| 2565 | } |
| 2566 | } |
| 2567 | } |
| 2568 | } finally { |
| 2569 | Binder.restoreCallingIdentity(origId); |
| 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2574 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2575 | Rect visibleInsets) { |
| 2576 | long origId = Binder.clearCallingIdentity(); |
| 2577 | try { |
| 2578 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2579 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2580 | if (w != null) { |
| 2581 | w.mGivenInsetsPending = false; |
| 2582 | w.mGivenContentInsets.set(contentInsets); |
| 2583 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2584 | w.mTouchableInsets = touchableInsets; |
| 2585 | mLayoutNeeded = true; |
| 2586 | performLayoutAndPlaceSurfacesLocked(); |
| 2587 | } |
| 2588 | } |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(origId); |
| 2591 | } |
| 2592 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2595 | Rect outDisplayFrame) { |
| 2596 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2597 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | if (win == null) { |
| 2599 | outDisplayFrame.setEmpty(); |
| 2600 | return; |
| 2601 | } |
| 2602 | outDisplayFrame.set(win.mDisplayFrame); |
| 2603 | } |
| 2604 | } |
| 2605 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2606 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2607 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2608 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2609 | window.mWallpaperX = x; |
| 2610 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2611 | window.mWallpaperXStep = xStep; |
| 2612 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2613 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2614 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2615 | } |
| 2616 | } |
| 2617 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2618 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2619 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2620 | synchronized (mWindowMap) { |
| 2621 | if (mWaitingOnWallpaper != null && |
| 2622 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2623 | mWaitingOnWallpaper = null; |
| 2624 | mWindowMap.notifyAll(); |
| 2625 | } |
| 2626 | } |
| 2627 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2628 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2629 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2630 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2631 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2632 | || window == mUpperWallpaperTarget) { |
| 2633 | boolean doWait = sync; |
| 2634 | int curTokenIndex = mWallpaperTokens.size(); |
| 2635 | while (curTokenIndex > 0) { |
| 2636 | curTokenIndex--; |
| 2637 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2638 | int curWallpaperIndex = token.windows.size(); |
| 2639 | while (curWallpaperIndex > 0) { |
| 2640 | curWallpaperIndex--; |
| 2641 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2642 | try { |
| 2643 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2644 | x, y, z, extras, sync); |
| 2645 | // We only want to be synchronous with one wallpaper. |
| 2646 | sync = false; |
| 2647 | } catch (RemoteException e) { |
| 2648 | } |
| 2649 | } |
| 2650 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2651 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2652 | if (doWait) { |
| 2653 | // XXX Need to wait for result. |
| 2654 | } |
| 2655 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2656 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2657 | return null; |
| 2658 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2660 | public int relayoutWindow(Session session, IWindow client, |
| 2661 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2662 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2663 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2664 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2665 | boolean displayed = false; |
| 2666 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2667 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2671 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | if (win == null) { |
| 2673 | return 0; |
| 2674 | } |
| 2675 | win.mRequestedWidth = requestedWidth; |
| 2676 | win.mRequestedHeight = requestedHeight; |
| 2677 | |
| 2678 | if (attrs != null) { |
| 2679 | mPolicy.adjustWindowParamsLw(attrs); |
| 2680 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | int attrChanges = 0; |
| 2683 | int flagChanges = 0; |
| 2684 | if (attrs != null) { |
| 2685 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2686 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2687 | } |
| 2688 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2689 | 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] | 2690 | |
| 2691 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2692 | win.mAlpha = attrs.alpha; |
| 2693 | } |
| 2694 | |
| 2695 | final boolean scaledWindow = |
| 2696 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2697 | |
| 2698 | if (scaledWindow) { |
| 2699 | // requested{Width|Height} Surface's physical size |
| 2700 | // attrs.{width|height} Size on screen |
| 2701 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2702 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2703 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2704 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2705 | } else { |
| 2706 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | boolean imMayMove = (flagChanges&( |
| 2710 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2711 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2713 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2714 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2715 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2716 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2717 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2718 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | win.mRelayoutCalled = true; |
| 2721 | final int oldVisibility = win.mViewVisibility; |
| 2722 | win.mViewVisibility = viewVisibility; |
| 2723 | if (viewVisibility == View.VISIBLE && |
| 2724 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2725 | displayed = !win.isVisibleLw(); |
| 2726 | if (win.mExiting) { |
| 2727 | win.mExiting = false; |
| 2728 | win.mAnimation = null; |
| 2729 | } |
| 2730 | if (win.mDestroying) { |
| 2731 | win.mDestroying = false; |
| 2732 | mDestroySurface.remove(win); |
| 2733 | } |
| 2734 | if (oldVisibility == View.GONE) { |
| 2735 | win.mEnterAnimationPending = true; |
| 2736 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2737 | if (displayed) { |
| 2738 | if (win.mSurface != null && !win.mDrawPending |
| 2739 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2740 | && mPolicy.isScreenOn()) { |
| 2741 | applyEnterAnimationLocked(win); |
| 2742 | } |
| 2743 | if ((win.mAttrs.flags |
| 2744 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2745 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2746 | "Relayout window turning screen on: " + win); |
| 2747 | win.mTurnOnScreen = true; |
| 2748 | } |
| 2749 | int diff = 0; |
| 2750 | if (win.mConfiguration != mCurConfiguration |
| 2751 | && (win.mConfiguration == null |
| 2752 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2753 | win.mConfiguration = mCurConfiguration; |
| 2754 | if (DEBUG_CONFIGURATION) { |
| 2755 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2756 | + win.mConfiguration + " / 0x" |
| 2757 | + Integer.toHexString(diff)); |
| 2758 | } |
| 2759 | outConfig.setTo(mCurConfiguration); |
| 2760 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2763 | // To change the format, we need to re-build the surface. |
| 2764 | win.destroySurfaceLocked(); |
| 2765 | displayed = true; |
| 2766 | } |
| 2767 | try { |
| 2768 | Surface surface = win.createSurfaceLocked(); |
| 2769 | if (surface != null) { |
| 2770 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2771 | win.mReportDestroySurface = false; |
| 2772 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2773 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2774 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2776 | // For some reason there isn't a surface. Clear the |
| 2777 | // caller's object so they see the same state. |
| 2778 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2779 | } |
| 2780 | } catch (Exception e) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2781 | mInputMonitor.updateInputWindowsLw(); |
| 2782 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2783 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2784 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2785 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | Binder.restoreCallingIdentity(origId); |
| 2787 | return 0; |
| 2788 | } |
| 2789 | if (displayed) { |
| 2790 | focusMayChange = true; |
| 2791 | } |
| 2792 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2793 | && mInputMethodWindow == null) { |
| 2794 | mInputMethodWindow = win; |
| 2795 | imMayMove = true; |
| 2796 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2797 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2798 | && win.mAppToken != null |
| 2799 | && win.mAppToken.startingWindow != null) { |
| 2800 | // Special handling of starting window over the base |
| 2801 | // window of the app: propagate lock screen flags to it, |
| 2802 | // to provide the correct semantics while starting. |
| 2803 | final int mask = |
| 2804 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2805 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2806 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2807 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2808 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | } else { |
| 2811 | win.mEnterAnimationPending = false; |
| 2812 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2813 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2814 | + ": mExiting=" + win.mExiting |
| 2815 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | // If we are not currently running the exit animation, we |
| 2817 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2818 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | // Try starting an animation; if there isn't one, we |
| 2820 | // can destroy the surface right away. |
| 2821 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2822 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2823 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2824 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2825 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2827 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2828 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | } else if (win.isAnimating()) { |
| 2830 | // Currently in a hide animation... turn this into |
| 2831 | // an exit. |
| 2832 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2833 | } else if (win == mWallpaperTarget) { |
| 2834 | // If the wallpaper is currently behind this |
| 2835 | // window, we need to change both of them inside |
| 2836 | // of a transaction to avoid artifacts. |
| 2837 | win.mExiting = true; |
| 2838 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | } else { |
| 2840 | if (mInputMethodWindow == win) { |
| 2841 | mInputMethodWindow = null; |
| 2842 | } |
| 2843 | win.destroySurfaceLocked(); |
| 2844 | } |
| 2845 | } |
| 2846 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2847 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2848 | if (win.mSurface == null || (win.getAttrs().flags |
| 2849 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2850 | || win.mSurfacePendingDestroy) { |
| 2851 | // We are being called from a local process, which |
| 2852 | // means outSurface holds its current surface. Ensure the |
| 2853 | // surface object is cleared, but we don't want it actually |
| 2854 | // destroyed at this point. |
| 2855 | win.mSurfacePendingDestroy = false; |
| 2856 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2857 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2858 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2859 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2860 | "Keeping surface, will report destroy: " + win); |
| 2861 | win.mReportDestroySurface = true; |
| 2862 | outSurface.copyFrom(win.mSurface); |
| 2863 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | } |
| 2865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2866 | if (focusMayChange) { |
| 2867 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2868 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2869 | imMayMove = false; |
| 2870 | } |
| 2871 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2872 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2873 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2874 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2875 | // reassign them at this point if the IM window state gets shuffled |
| 2876 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2878 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2879 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2880 | // Little hack here -- we -should- be able to rely on the |
| 2881 | // function to return true if the IME has moved and needs |
| 2882 | // its layer recomputed. However, if the IME was hidden |
| 2883 | // and isn't actually moved in the list, its layer may be |
| 2884 | // 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] | 2885 | assignLayers = true; |
| 2886 | } |
| 2887 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2888 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2889 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2890 | assignLayers = true; |
| 2891 | } |
| 2892 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2894 | mLayoutNeeded = true; |
| 2895 | win.mGivenInsetsPending = insetsPending; |
| 2896 | if (assignLayers) { |
| 2897 | assignLayersLocked(); |
| 2898 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2899 | configChanged = updateOrientationFromAppTokensLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2901 | if (displayed && win.mIsWallpaper) { |
| 2902 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2903 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2904 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | if (win.mAppToken != null) { |
| 2906 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2907 | } |
| 2908 | outFrame.set(win.mFrame); |
| 2909 | outContentInsets.set(win.mContentInsets); |
| 2910 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2911 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2913 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2914 | + ", requestedHeight=" + requestedHeight |
| 2915 | + ", viewVisibility=" + viewVisibility |
| 2916 | + "\nRelayout returning frame=" + outFrame |
| 2917 | + ", surface=" + outSurface); |
| 2918 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2919 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2921 | |
| 2922 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2923 | |
| 2924 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | } |
| 2926 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2927 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | sendNewConfiguration(); |
| 2929 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2934 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2935 | } |
| 2936 | |
| 2937 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2938 | final long origId = Binder.clearCallingIdentity(); |
| 2939 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2940 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2941 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2942 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2943 | adjustWallpaperWindowsLocked(); |
| 2944 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2945 | mLayoutNeeded = true; |
| 2946 | performLayoutAndPlaceSurfacesLocked(); |
| 2947 | } |
| 2948 | } |
| 2949 | Binder.restoreCallingIdentity(origId); |
| 2950 | } |
| 2951 | |
| 2952 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2953 | 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] | 2954 | + (lp != null ? lp.packageName : null) |
| 2955 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2956 | if (lp != null && lp.windowAnimations != 0) { |
| 2957 | // If this is a system resource, don't try to load it from the |
| 2958 | // application resources. It is nice to avoid loading application |
| 2959 | // resources if we can. |
| 2960 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2961 | int resId = lp.windowAnimations; |
| 2962 | if ((resId&0xFF000000) == 0x01000000) { |
| 2963 | packageName = "android"; |
| 2964 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2965 | 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] | 2966 | + packageName); |
| 2967 | return AttributeCache.instance().get(packageName, resId, |
| 2968 | com.android.internal.R.styleable.WindowAnimation); |
| 2969 | } |
| 2970 | return null; |
| 2971 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2972 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2973 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2974 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2975 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2976 | if (packageName != null) { |
| 2977 | if ((resId&0xFF000000) == 0x01000000) { |
| 2978 | packageName = "android"; |
| 2979 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2980 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2981 | + packageName); |
| 2982 | return AttributeCache.instance().get(packageName, resId, |
| 2983 | com.android.internal.R.styleable.WindowAnimation); |
| 2984 | } |
| 2985 | return null; |
| 2986 | } |
| 2987 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | private void applyEnterAnimationLocked(WindowState win) { |
| 2989 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2990 | if (win.mEnterAnimationPending) { |
| 2991 | win.mEnterAnimationPending = false; |
| 2992 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2993 | } |
| 2994 | |
| 2995 | applyAnimationLocked(win, transit, true); |
| 2996 | } |
| 2997 | |
| 2998 | private boolean applyAnimationLocked(WindowState win, |
| 2999 | int transit, boolean isEntrance) { |
| 3000 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 3001 | // If we are trying to apply an animation, but already running |
| 3002 | // an animation of the same type, then just leave that one alone. |
| 3003 | return true; |
| 3004 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | // Only apply an animation if the display isn't frozen. If it is |
| 3007 | // frozen, there is no reason to animate and it can cause strange |
| 3008 | // artifacts when we unfreeze the display if some different animation |
| 3009 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3010 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 3012 | int attr = -1; |
| 3013 | Animation a = null; |
| 3014 | if (anim != 0) { |
| 3015 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 3016 | } else { |
| 3017 | switch (transit) { |
| 3018 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 3019 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 3020 | break; |
| 3021 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 3022 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 3023 | break; |
| 3024 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3025 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3026 | break; |
| 3027 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3028 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3029 | break; |
| 3030 | } |
| 3031 | if (attr >= 0) { |
| 3032 | a = loadAnimation(win.mAttrs, attr); |
| 3033 | } |
| 3034 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3035 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3037 | + " mAnimation=" + win.mAnimation |
| 3038 | + " isEntrance=" + isEntrance); |
| 3039 | if (a != null) { |
| 3040 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3041 | RuntimeException e = null; |
| 3042 | if (!HIDE_STACK_CRAWLS) { |
| 3043 | e = new RuntimeException(); |
| 3044 | e.fillInStackTrace(); |
| 3045 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3046 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | } |
| 3048 | win.setAnimation(a); |
| 3049 | win.mAnimationIsEntrance = isEntrance; |
| 3050 | } |
| 3051 | } else { |
| 3052 | win.clearAnimation(); |
| 3053 | } |
| 3054 | |
| 3055 | return win.mAnimation != null; |
| 3056 | } |
| 3057 | |
| 3058 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3059 | int anim = 0; |
| 3060 | Context context = mContext; |
| 3061 | if (animAttr >= 0) { |
| 3062 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3063 | if (ent != null) { |
| 3064 | context = ent.context; |
| 3065 | anim = ent.array.getResourceId(animAttr, 0); |
| 3066 | } |
| 3067 | } |
| 3068 | if (anim != 0) { |
| 3069 | return AnimationUtils.loadAnimation(context, anim); |
| 3070 | } |
| 3071 | return null; |
| 3072 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3073 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3074 | private Animation loadAnimation(String packageName, int resId) { |
| 3075 | int anim = 0; |
| 3076 | Context context = mContext; |
| 3077 | if (resId >= 0) { |
| 3078 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3079 | if (ent != null) { |
| 3080 | context = ent.context; |
| 3081 | anim = resId; |
| 3082 | } |
| 3083 | } |
| 3084 | if (anim != 0) { |
| 3085 | return AnimationUtils.loadAnimation(context, anim); |
| 3086 | } |
| 3087 | return null; |
| 3088 | } |
| 3089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3090 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3091 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3092 | // Only apply an animation if the display isn't frozen. If it is |
| 3093 | // frozen, there is no reason to animate and it can cause strange |
| 3094 | // artifacts when we unfreeze the display if some different animation |
| 3095 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3096 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3097 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3098 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3099 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3100 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3101 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3102 | } else if (mNextAppTransitionPackage != null) { |
| 3103 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3104 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3105 | } else { |
| 3106 | int animAttr = 0; |
| 3107 | switch (transit) { |
| 3108 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3109 | animAttr = enter |
| 3110 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3111 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3112 | break; |
| 3113 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3114 | animAttr = enter |
| 3115 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3116 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3117 | break; |
| 3118 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3119 | animAttr = enter |
| 3120 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3121 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3122 | break; |
| 3123 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3124 | animAttr = enter |
| 3125 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3126 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3127 | break; |
| 3128 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3129 | animAttr = enter |
| 3130 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3131 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3132 | break; |
| 3133 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3134 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3135 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3136 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3137 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3138 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3139 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3140 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3141 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3142 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3143 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3144 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3145 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3146 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3147 | break; |
| 3148 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3149 | animAttr = enter |
| 3150 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3151 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3152 | break; |
| 3153 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3154 | animAttr = enter |
| 3155 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3156 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3157 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3158 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3159 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3160 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3161 | + " anim=" + a |
| 3162 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3163 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | if (a != null) { |
| 3166 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3167 | RuntimeException e = null; |
| 3168 | if (!HIDE_STACK_CRAWLS) { |
| 3169 | e = new RuntimeException(); |
| 3170 | e.fillInStackTrace(); |
| 3171 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3172 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3173 | } |
| 3174 | wtoken.setAnimation(a); |
| 3175 | } |
| 3176 | } else { |
| 3177 | wtoken.clearAnimation(); |
| 3178 | } |
| 3179 | |
| 3180 | return wtoken.animation != null; |
| 3181 | } |
| 3182 | |
| 3183 | // ------------------------------------------------------------- |
| 3184 | // Application Window Tokens |
| 3185 | // ------------------------------------------------------------- |
| 3186 | |
| 3187 | public void validateAppTokens(List tokens) { |
| 3188 | int v = tokens.size()-1; |
| 3189 | int m = mAppTokens.size()-1; |
| 3190 | while (v >= 0 && m >= 0) { |
| 3191 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3192 | if (wtoken.removed) { |
| 3193 | m--; |
| 3194 | continue; |
| 3195 | } |
| 3196 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3197 | 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] | 3198 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3199 | } |
| 3200 | v--; |
| 3201 | m--; |
| 3202 | } |
| 3203 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3204 | 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] | 3205 | v--; |
| 3206 | } |
| 3207 | while (m >= 0) { |
| 3208 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3209 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3210 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | } |
| 3212 | m--; |
| 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | boolean checkCallingPermission(String permission, String func) { |
| 3217 | // Quick check: if the calling permission is me, it's all okay. |
| 3218 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3219 | return true; |
| 3220 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | if (mContext.checkCallingPermission(permission) |
| 3223 | == PackageManager.PERMISSION_GRANTED) { |
| 3224 | return true; |
| 3225 | } |
| 3226 | String msg = "Permission Denial: " + func + " from pid=" |
| 3227 | + Binder.getCallingPid() |
| 3228 | + ", uid=" + Binder.getCallingUid() |
| 3229 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3230 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3231 | return false; |
| 3232 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3235 | WindowToken wtoken = mTokenMap.get(token); |
| 3236 | if (wtoken == null) { |
| 3237 | return null; |
| 3238 | } |
| 3239 | return wtoken.appWindowToken; |
| 3240 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3242 | public void addWindowToken(IBinder token, int type) { |
| 3243 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3244 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3245 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3246 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3248 | synchronized(mWindowMap) { |
| 3249 | WindowToken wtoken = mTokenMap.get(token); |
| 3250 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3251 | 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] | 3252 | return; |
| 3253 | } |
| 3254 | wtoken = new WindowToken(token, type, true); |
| 3255 | mTokenMap.put(token, wtoken); |
| 3256 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3257 | if (type == TYPE_WALLPAPER) { |
| 3258 | mWallpaperTokens.add(wtoken); |
| 3259 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3260 | } |
| 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 removeWindowToken(IBinder token) { |
| 3264 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3265 | "removeWindowToken()")) { |
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 | } |
| 3268 | |
| 3269 | final long origId = Binder.clearCallingIdentity(); |
| 3270 | synchronized(mWindowMap) { |
| 3271 | WindowToken wtoken = mTokenMap.remove(token); |
| 3272 | mTokenList.remove(wtoken); |
| 3273 | if (wtoken != null) { |
| 3274 | boolean delayed = false; |
| 3275 | if (!wtoken.hidden) { |
| 3276 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | final int N = wtoken.windows.size(); |
| 3279 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | for (int i=0; i<N; i++) { |
| 3282 | WindowState win = wtoken.windows.get(i); |
| 3283 | |
| 3284 | if (win.isAnimating()) { |
| 3285 | delayed = true; |
| 3286 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3288 | if (win.isVisibleNow()) { |
| 3289 | applyAnimationLocked(win, |
| 3290 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3291 | changed = true; |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | if (changed) { |
| 3296 | mLayoutNeeded = true; |
| 3297 | performLayoutAndPlaceSurfacesLocked(); |
| 3298 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3299 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3301 | if (delayed) { |
| 3302 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3303 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3304 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | } |
| 3306 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3307 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3308 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3309 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3310 | 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] | 3311 | } |
| 3312 | } |
| 3313 | Binder.restoreCallingIdentity(origId); |
| 3314 | } |
| 3315 | |
| 3316 | public void addAppToken(int addPos, IApplicationToken token, |
| 3317 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3318 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3319 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3320 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3321 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3322 | |
| 3323 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3324 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3325 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3326 | // here we would run the chance of introducing a deadlock between the window manager |
| 3327 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3328 | // (which holds locks while querying the application token). |
| 3329 | long inputDispatchingTimeoutNanos; |
| 3330 | try { |
| 3331 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3332 | } catch (RemoteException ex) { |
| 3333 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3334 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3335 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | synchronized(mWindowMap) { |
| 3338 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3339 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3340 | 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] | 3341 | return; |
| 3342 | } |
| 3343 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3344 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | wtoken.groupId = groupId; |
| 3346 | wtoken.appFullscreen = fullscreen; |
| 3347 | wtoken.requestedOrientation = requestedOrientation; |
| 3348 | mAppTokens.add(addPos, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3349 | 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] | 3350 | mTokenMap.put(token.asBinder(), wtoken); |
| 3351 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | // Application tokens start out hidden. |
| 3354 | wtoken.hidden = true; |
| 3355 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3357 | //dump(); |
| 3358 | } |
| 3359 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3361 | public void setAppGroupId(IBinder token, int groupId) { |
| 3362 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3363 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3364 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | synchronized(mWindowMap) { |
| 3368 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3369 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3370 | 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] | 3371 | return; |
| 3372 | } |
| 3373 | wtoken.groupId = groupId; |
| 3374 | } |
| 3375 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | public int getOrientationFromWindowsLocked() { |
| 3378 | int pos = mWindows.size() - 1; |
| 3379 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3380 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | pos--; |
| 3382 | if (wtoken.mAppToken != null) { |
| 3383 | // We hit an application window. so the orientation will be determined by the |
| 3384 | // app window. No point in continuing further. |
| 3385 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3386 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3387 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3388 | continue; |
| 3389 | } |
| 3390 | int req = wtoken.mAttrs.screenOrientation; |
| 3391 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3392 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3393 | continue; |
| 3394 | } else { |
| 3395 | return req; |
| 3396 | } |
| 3397 | } |
| 3398 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3399 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3401 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3402 | int pos = mAppTokens.size() - 1; |
| 3403 | int curGroup = 0; |
| 3404 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3405 | boolean findingBehind = false; |
| 3406 | boolean haveGroup = false; |
| 3407 | boolean lastFullscreen = false; |
| 3408 | while (pos >= 0) { |
| 3409 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3410 | pos--; |
| 3411 | // if we're about to tear down this window and not seek for |
| 3412 | // the behind activity, don't use it for orientation |
| 3413 | if (!findingBehind |
| 3414 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3415 | continue; |
| 3416 | } |
| 3417 | |
| 3418 | if (!haveGroup) { |
| 3419 | // We ignore any hidden applications on the top. |
| 3420 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3421 | continue; |
| 3422 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3423 | haveGroup = true; |
| 3424 | curGroup = wtoken.groupId; |
| 3425 | lastOrientation = wtoken.requestedOrientation; |
| 3426 | } else if (curGroup != wtoken.groupId) { |
| 3427 | // If we have hit a new application group, and the bottom |
| 3428 | // of the previous group didn't explicitly say to use |
| 3429 | // the orientation behind it, and the last app was |
| 3430 | // full screen, then we'll stick with the |
| 3431 | // user's orientation. |
| 3432 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3433 | && lastFullscreen) { |
| 3434 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3436 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3437 | int or = wtoken.requestedOrientation; |
| 3438 | // If this application is fullscreen, and didn't explicitly say |
| 3439 | // to use the orientation behind it, then just take whatever |
| 3440 | // orientation it has and ignores whatever is under it. |
| 3441 | lastFullscreen = wtoken.appFullscreen; |
| 3442 | if (lastFullscreen |
| 3443 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3444 | return or; |
| 3445 | } |
| 3446 | // If this application has requested an explicit orientation, |
| 3447 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3448 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3449 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3450 | return or; |
| 3451 | } |
| 3452 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3453 | } |
| 3454 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3455 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3457 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3458 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3459 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3460 | "updateOrientationFromAppTokens()")) { |
| 3461 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3462 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3463 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3464 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3465 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3466 | |
| 3467 | synchronized(mWindowMap) { |
| 3468 | if (updateOrientationFromAppTokensLocked()) { |
| 3469 | if (freezeThisOneIfNeeded != null) { |
| 3470 | AppWindowToken wtoken = findAppWindowToken( |
| 3471 | freezeThisOneIfNeeded); |
| 3472 | if (wtoken != null) { |
| 3473 | startAppFreezingScreenLocked(wtoken, |
| 3474 | ActivityInfo.CONFIG_ORIENTATION); |
| 3475 | } |
| 3476 | } |
| 3477 | config = computeNewConfigurationLocked(); |
| 3478 | |
| 3479 | } else if (currentConfig != null) { |
| 3480 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3481 | // state mismatches the activity manager's, update it, |
| 3482 | // disregarding font scale, which should remain set to |
| 3483 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3484 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3485 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3486 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3487 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3488 | mWaitingForConfig = true; |
| 3489 | mLayoutNeeded = true; |
| 3490 | startFreezingDisplayLocked(); |
| 3491 | config = new Configuration(mTempConfiguration); |
| 3492 | } |
| 3493 | } |
| 3494 | } |
| 3495 | } |
| 3496 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3497 | Binder.restoreCallingIdentity(ident); |
| 3498 | return config; |
| 3499 | } |
| 3500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3502 | * Determine the new desired orientation of the display, returning |
| 3503 | * a non-null new Configuration if it has changed from the current |
| 3504 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3505 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3506 | * SCREEN. This will typically be done for you if you call |
| 3507 | * sendNewConfiguration(). |
| 3508 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | * The orientation is computed from non-application windows first. If none of |
| 3510 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3511 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3512 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3513 | * android.os.IBinder) |
| 3514 | */ |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3515 | boolean updateOrientationFromAppTokensLocked() { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3516 | if (mDisplayFrozen) { |
| 3517 | // If the display is frozen, some activities may be in the middle |
| 3518 | // of restarting, and thus have removed their old window. If the |
| 3519 | // window has the flag to hide the lock screen, then the lock screen |
| 3520 | // can re-appear and inflict its own orientation on us. Keep the |
| 3521 | // orientation stable until this all settles down. |
| 3522 | return false; |
| 3523 | } |
| 3524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3525 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | long ident = Binder.clearCallingIdentity(); |
| 3527 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3528 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3531 | mForcedAppOrientation = req; |
| 3532 | //send a message to Policy indicating orientation change to take |
| 3533 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3534 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3535 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3536 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3537 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | } |
| 3539 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3540 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3541 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | } finally { |
| 3543 | Binder.restoreCallingIdentity(ident); |
| 3544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3546 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3547 | int computeForcedAppOrientationLocked() { |
| 3548 | int req = getOrientationFromWindowsLocked(); |
| 3549 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3550 | req = getOrientationFromAppTokensLocked(); |
| 3551 | } |
| 3552 | return req; |
| 3553 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3554 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3555 | public void setNewConfiguration(Configuration config) { |
| 3556 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3557 | "setNewConfiguration()")) { |
| 3558 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3559 | } |
| 3560 | |
| 3561 | synchronized(mWindowMap) { |
| 3562 | mCurConfiguration = new Configuration(config); |
| 3563 | mWaitingForConfig = false; |
| 3564 | performLayoutAndPlaceSurfacesLocked(); |
| 3565 | } |
| 3566 | } |
| 3567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3569 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3570 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3571 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3574 | synchronized(mWindowMap) { |
| 3575 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3576 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3577 | 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] | 3578 | return; |
| 3579 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3581 | wtoken.requestedOrientation = requestedOrientation; |
| 3582 | } |
| 3583 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3585 | public int getAppOrientation(IApplicationToken token) { |
| 3586 | synchronized(mWindowMap) { |
| 3587 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3588 | if (wtoken == null) { |
| 3589 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3590 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | return wtoken.requestedOrientation; |
| 3593 | } |
| 3594 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3596 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3597 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3598 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3599 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | synchronized(mWindowMap) { |
| 3603 | boolean changed = false; |
| 3604 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3605 | 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] | 3606 | changed = mFocusedApp != null; |
| 3607 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3608 | if (changed) { |
| 3609 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3610 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3611 | } else { |
| 3612 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3613 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3614 | 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] | 3615 | return; |
| 3616 | } |
| 3617 | changed = mFocusedApp != newFocus; |
| 3618 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3619 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3620 | if (changed) { |
| 3621 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | if (moveFocusNow && changed) { |
| 3626 | final long origId = Binder.clearCallingIdentity(); |
| 3627 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3628 | Binder.restoreCallingIdentity(origId); |
| 3629 | } |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | public void prepareAppTransition(int transit) { |
| 3634 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3635 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3636 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3637 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3640 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | TAG, "Prepare app transition: transit=" + transit |
| 3642 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3643 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3644 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3645 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3646 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3647 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3648 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3649 | // Opening a new task always supersedes a close for the anim. |
| 3650 | mNextAppTransition = transit; |
| 3651 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3652 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3653 | // Opening a new activity always supersedes a close for the anim. |
| 3654 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3655 | } |
| 3656 | mAppTransitionReady = false; |
| 3657 | mAppTransitionTimeout = false; |
| 3658 | mStartingIconInTransition = false; |
| 3659 | mSkipAppTransitionAnimation = false; |
| 3660 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3661 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3662 | 5000); |
| 3663 | } |
| 3664 | } |
| 3665 | } |
| 3666 | |
| 3667 | public int getPendingAppTransition() { |
| 3668 | return mNextAppTransition; |
| 3669 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3670 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3671 | public void overridePendingAppTransition(String packageName, |
| 3672 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3673 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3674 | mNextAppTransitionPackage = packageName; |
| 3675 | mNextAppTransitionEnter = enterAnim; |
| 3676 | mNextAppTransitionExit = exitAnim; |
| 3677 | } |
| 3678 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3679 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | public void executeAppTransition() { |
| 3681 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3682 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3683 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3687 | if (DEBUG_APP_TRANSITIONS) { |
| 3688 | RuntimeException e = new RuntimeException("here"); |
| 3689 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3690 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3691 | + mNextAppTransition, e); |
| 3692 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3693 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | mAppTransitionReady = true; |
| 3695 | final long origId = Binder.clearCallingIdentity(); |
| 3696 | performLayoutAndPlaceSurfacesLocked(); |
| 3697 | Binder.restoreCallingIdentity(origId); |
| 3698 | } |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3703 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3704 | IBinder transferFrom, boolean createIfNeeded) { |
| 3705 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3706 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3707 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3711 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3712 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3713 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3716 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3717 | 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] | 3718 | return; |
| 3719 | } |
| 3720 | |
| 3721 | // If the display is frozen, we won't do anything until the |
| 3722 | // actual window is displayed so there is no reason to put in |
| 3723 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3724 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3725 | return; |
| 3726 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | if (wtoken.startingData != null) { |
| 3729 | return; |
| 3730 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3731 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3732 | if (transferFrom != null) { |
| 3733 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3734 | if (ttoken != null) { |
| 3735 | WindowState startingWindow = ttoken.startingWindow; |
| 3736 | if (startingWindow != null) { |
| 3737 | if (mStartingIconInTransition) { |
| 3738 | // In this case, the starting icon has already |
| 3739 | // been displayed, so start letting windows get |
| 3740 | // shown immediately without any more transitions. |
| 3741 | mSkipAppTransitionAnimation = true; |
| 3742 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3743 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | "Moving existing starting from " + ttoken |
| 3745 | + " to " + wtoken); |
| 3746 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | // Transfer the starting window over to the new |
| 3749 | // token. |
| 3750 | wtoken.startingData = ttoken.startingData; |
| 3751 | wtoken.startingView = ttoken.startingView; |
| 3752 | wtoken.startingWindow = startingWindow; |
| 3753 | ttoken.startingData = null; |
| 3754 | ttoken.startingView = null; |
| 3755 | ttoken.startingWindow = null; |
| 3756 | ttoken.startingMoved = true; |
| 3757 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3758 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3759 | startingWindow.mAppToken = wtoken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3760 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3761 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3763 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3764 | ttoken.windows.remove(startingWindow); |
| 3765 | ttoken.allAppWindows.remove(startingWindow); |
| 3766 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3768 | // Propagate other interesting state between the |
| 3769 | // tokens. If the old token is displayed, we should |
| 3770 | // immediately force the new one to be displayed. If |
| 3771 | // it is animating, we need to move that animation to |
| 3772 | // the new one. |
| 3773 | if (ttoken.allDrawn) { |
| 3774 | wtoken.allDrawn = true; |
| 3775 | } |
| 3776 | if (ttoken.firstWindowDrawn) { |
| 3777 | wtoken.firstWindowDrawn = true; |
| 3778 | } |
| 3779 | if (!ttoken.hidden) { |
| 3780 | wtoken.hidden = false; |
| 3781 | wtoken.hiddenRequested = false; |
| 3782 | wtoken.willBeHidden = false; |
| 3783 | } |
| 3784 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3785 | wtoken.clientHidden = ttoken.clientHidden; |
| 3786 | wtoken.sendAppVisibilityToClients(); |
| 3787 | } |
| 3788 | if (ttoken.animation != null) { |
| 3789 | wtoken.animation = ttoken.animation; |
| 3790 | wtoken.animating = ttoken.animating; |
| 3791 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3792 | ttoken.animation = null; |
| 3793 | ttoken.animLayerAdjustment = 0; |
| 3794 | wtoken.updateLayers(); |
| 3795 | ttoken.updateLayers(); |
| 3796 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3798 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | mLayoutNeeded = true; |
| 3800 | performLayoutAndPlaceSurfacesLocked(); |
| 3801 | Binder.restoreCallingIdentity(origId); |
| 3802 | return; |
| 3803 | } else if (ttoken.startingData != null) { |
| 3804 | // The previous app was getting ready to show a |
| 3805 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3806 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | "Moving pending starting from " + ttoken |
| 3808 | + " to " + wtoken); |
| 3809 | wtoken.startingData = ttoken.startingData; |
| 3810 | ttoken.startingData = null; |
| 3811 | ttoken.startingMoved = true; |
| 3812 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3813 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3814 | // want to process the message ASAP, before any other queued |
| 3815 | // messages. |
| 3816 | mH.sendMessageAtFrontOfQueue(m); |
| 3817 | return; |
| 3818 | } |
| 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | // There is no existing starting window, and the caller doesn't |
| 3823 | // want us to create one, so that's it! |
| 3824 | if (!createIfNeeded) { |
| 3825 | return; |
| 3826 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3827 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3828 | // If this is a translucent or wallpaper window, then don't |
| 3829 | // show a starting window -- the current effect (a full-screen |
| 3830 | // opaque starting window that fades away to the real contents |
| 3831 | // when it is ready) does not work for this. |
| 3832 | if (theme != 0) { |
| 3833 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3834 | com.android.internal.R.styleable.Window); |
| 3835 | if (ent.array.getBoolean( |
| 3836 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3837 | return; |
| 3838 | } |
| 3839 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3840 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3841 | return; |
| 3842 | } |
| 3843 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3844 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3845 | return; |
| 3846 | } |
| 3847 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3849 | mStartingIconInTransition = true; |
| 3850 | wtoken.startingData = new StartingData( |
| 3851 | pkg, theme, nonLocalizedLabel, |
| 3852 | labelRes, icon); |
| 3853 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3854 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3855 | // want to process the message ASAP, before any other queued |
| 3856 | // messages. |
| 3857 | mH.sendMessageAtFrontOfQueue(m); |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | public void setAppWillBeHidden(IBinder token) { |
| 3862 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3863 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3864 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | AppWindowToken wtoken; |
| 3868 | |
| 3869 | synchronized(mWindowMap) { |
| 3870 | wtoken = findAppWindowToken(token); |
| 3871 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3872 | 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] | 3873 | return; |
| 3874 | } |
| 3875 | wtoken.willBeHidden = true; |
| 3876 | } |
| 3877 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3879 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3880 | boolean visible, int transit, boolean performLayout) { |
| 3881 | boolean delayed = false; |
| 3882 | |
| 3883 | if (wtoken.clientHidden == visible) { |
| 3884 | wtoken.clientHidden = !visible; |
| 3885 | wtoken.sendAppVisibilityToClients(); |
| 3886 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3888 | wtoken.willBeHidden = false; |
| 3889 | if (wtoken.hidden == visible) { |
| 3890 | final int N = wtoken.allAppWindows.size(); |
| 3891 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3892 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3893 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3894 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3897 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3898 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | if (wtoken.animation == sDummyAnimation) { |
| 3900 | wtoken.animation = null; |
| 3901 | } |
| 3902 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3903 | changed = true; |
| 3904 | if (wtoken.animation != null) { |
| 3905 | delayed = runningAppAnimation = true; |
| 3906 | } |
| 3907 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | for (int i=0; i<N; i++) { |
| 3910 | WindowState win = wtoken.allAppWindows.get(i); |
| 3911 | if (win == wtoken.startingWindow) { |
| 3912 | continue; |
| 3913 | } |
| 3914 | |
| 3915 | if (win.isAnimating()) { |
| 3916 | delayed = true; |
| 3917 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3918 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3919 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3920 | //win.dump(" "); |
| 3921 | if (visible) { |
| 3922 | if (!win.isVisibleNow()) { |
| 3923 | if (!runningAppAnimation) { |
| 3924 | applyAnimationLocked(win, |
| 3925 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3926 | } |
| 3927 | changed = true; |
| 3928 | } |
| 3929 | } else if (win.isVisibleNow()) { |
| 3930 | if (!runningAppAnimation) { |
| 3931 | applyAnimationLocked(win, |
| 3932 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3934 | changed = true; |
| 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3939 | if (!visible) { |
| 3940 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3941 | } else { |
| 3942 | // If we are being set visible, and the starting window is |
| 3943 | // not yet displayed, then make sure it doesn't get displayed. |
| 3944 | WindowState swin = wtoken.startingWindow; |
| 3945 | if (swin != null && (swin.mDrawPending |
| 3946 | || swin.mCommitDrawPending)) { |
| 3947 | swin.mPolicyVisibility = false; |
| 3948 | swin.mPolicyVisibilityAfterAnim = false; |
| 3949 | } |
| 3950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3951 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3952 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3953 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3954 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3955 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3956 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | mLayoutNeeded = true; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3958 | if (performLayout) { |
| 3959 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3960 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3961 | } else { |
| 3962 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3963 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | } |
| 3965 | } |
| 3966 | |
| 3967 | if (wtoken.animation != null) { |
| 3968 | delayed = true; |
| 3969 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | return delayed; |
| 3972 | } |
| 3973 | |
| 3974 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3975 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3976 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3977 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3978 | } |
| 3979 | |
| 3980 | AppWindowToken wtoken; |
| 3981 | |
| 3982 | synchronized(mWindowMap) { |
| 3983 | wtoken = findAppWindowToken(token); |
| 3984 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3985 | 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] | 3986 | return; |
| 3987 | } |
| 3988 | |
| 3989 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3990 | RuntimeException e = null; |
| 3991 | if (!HIDE_STACK_CRAWLS) { |
| 3992 | e = new RuntimeException(); |
| 3993 | e.fillInStackTrace(); |
| 3994 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3995 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | + "): mNextAppTransition=" + mNextAppTransition |
| 3997 | + " hidden=" + wtoken.hidden |
| 3998 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3999 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | // If we are preparing an app transition, then delay changing |
| 4002 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4003 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 4004 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | // Already in requested state, don't do anything more. |
| 4006 | if (wtoken.hiddenRequested != visible) { |
| 4007 | return; |
| 4008 | } |
| 4009 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4010 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4011 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | TAG, "Setting dummy animation on: " + wtoken); |
| 4013 | wtoken.setDummyAnimation(); |
| 4014 | mOpeningApps.remove(wtoken); |
| 4015 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4016 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4017 | wtoken.inPendingTransaction = true; |
| 4018 | if (visible) { |
| 4019 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4020 | wtoken.startingDisplayed = false; |
| 4021 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4022 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4023 | // If the token is currently hidden (should be the |
| 4024 | // common case), then we need to set up to wait for |
| 4025 | // its windows to be ready. |
| 4026 | if (wtoken.hidden) { |
| 4027 | wtoken.allDrawn = false; |
| 4028 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4029 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4030 | if (wtoken.clientHidden) { |
| 4031 | // In the case where we are making an app visible |
| 4032 | // but holding off for a transition, we still need |
| 4033 | // to tell the client to make its windows visible so |
| 4034 | // they get drawn. Otherwise, we will wait on |
| 4035 | // performing the transition until all windows have |
| 4036 | // been drawn, they never will be, and we are sad. |
| 4037 | wtoken.clientHidden = false; |
| 4038 | wtoken.sendAppVisibilityToClients(); |
| 4039 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | } |
| 4041 | } else { |
| 4042 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4043 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4044 | // If the token is currently visible (should be the |
| 4045 | // common case), then set up to wait for it to be hidden. |
| 4046 | if (!wtoken.hidden) { |
| 4047 | wtoken.waitingToHide = true; |
| 4048 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | } |
| 4050 | return; |
| 4051 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4053 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4054 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | wtoken.updateReportedVisibilityLocked(); |
| 4056 | Binder.restoreCallingIdentity(origId); |
| 4057 | } |
| 4058 | } |
| 4059 | |
| 4060 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4061 | boolean unfreezeSurfaceNow, boolean force) { |
| 4062 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4063 | 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] | 4064 | + " force=" + force); |
| 4065 | final int N = wtoken.allAppWindows.size(); |
| 4066 | boolean unfrozeWindows = false; |
| 4067 | for (int i=0; i<N; i++) { |
| 4068 | WindowState w = wtoken.allAppWindows.get(i); |
| 4069 | if (w.mAppFreezing) { |
| 4070 | w.mAppFreezing = false; |
| 4071 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4072 | w.mOrientationChanging = true; |
| 4073 | } |
| 4074 | unfrozeWindows = true; |
| 4075 | } |
| 4076 | } |
| 4077 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4078 | 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] | 4079 | wtoken.freezingScreen = false; |
| 4080 | mAppsFreezingScreen--; |
| 4081 | } |
| 4082 | if (unfreezeSurfaceNow) { |
| 4083 | if (unfrozeWindows) { |
| 4084 | mLayoutNeeded = true; |
| 4085 | performLayoutAndPlaceSurfacesLocked(); |
| 4086 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4087 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | } |
| 4089 | } |
| 4090 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4093 | int configChanges) { |
| 4094 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4095 | RuntimeException e = null; |
| 4096 | if (!HIDE_STACK_CRAWLS) { |
| 4097 | e = new RuntimeException(); |
| 4098 | e.fillInStackTrace(); |
| 4099 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4100 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4101 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4102 | + wtoken.freezingScreen, e); |
| 4103 | } |
| 4104 | if (!wtoken.hiddenRequested) { |
| 4105 | if (!wtoken.freezingScreen) { |
| 4106 | wtoken.freezingScreen = true; |
| 4107 | mAppsFreezingScreen++; |
| 4108 | if (mAppsFreezingScreen == 1) { |
| 4109 | startFreezingDisplayLocked(); |
| 4110 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4111 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4112 | 5000); |
| 4113 | } |
| 4114 | } |
| 4115 | final int N = wtoken.allAppWindows.size(); |
| 4116 | for (int i=0; i<N; i++) { |
| 4117 | WindowState w = wtoken.allAppWindows.get(i); |
| 4118 | w.mAppFreezing = true; |
| 4119 | } |
| 4120 | } |
| 4121 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4123 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4124 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4125 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4126 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4130 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4131 | 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] | 4132 | return; |
| 4133 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4136 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4137 | 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] | 4138 | return; |
| 4139 | } |
| 4140 | final long origId = Binder.clearCallingIdentity(); |
| 4141 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4142 | Binder.restoreCallingIdentity(origId); |
| 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 stopAppFreezingScreen(IBinder token, boolean force) { |
| 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) { |
| 4153 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4154 | if (wtoken == null || wtoken.appToken == null) { |
| 4155 | return; |
| 4156 | } |
| 4157 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4158 | 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] | 4159 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4160 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4161 | Binder.restoreCallingIdentity(origId); |
| 4162 | } |
| 4163 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | public void removeAppToken(IBinder token) { |
| 4166 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4167 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4168 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | } |
| 4170 | |
| 4171 | AppWindowToken wtoken = null; |
| 4172 | AppWindowToken startingToken = null; |
| 4173 | boolean delayed = false; |
| 4174 | |
| 4175 | final long origId = Binder.clearCallingIdentity(); |
| 4176 | synchronized(mWindowMap) { |
| 4177 | WindowToken basewtoken = mTokenMap.remove(token); |
| 4178 | mTokenList.remove(basewtoken); |
| 4179 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4180 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4181 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | wtoken.inPendingTransaction = false; |
| 4183 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4184 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | if (mClosingApps.contains(wtoken)) { |
| 4186 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4187 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4189 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4190 | delayed = true; |
| 4191 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4192 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4194 | + " animation=" + wtoken.animation |
| 4195 | + " animating=" + wtoken.animating); |
| 4196 | if (delayed) { |
| 4197 | // set the token aside because it has an active animation to be finished |
| 4198 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4199 | } else { |
| 4200 | // Make sure there is no animation running on this token, |
| 4201 | // so any windows associated with it will be removed as |
| 4202 | // soon as their animations are complete |
| 4203 | wtoken.animation = null; |
| 4204 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | } |
| 4206 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4207 | if (mLastEnterAnimToken == wtoken) { |
| 4208 | mLastEnterAnimToken = null; |
| 4209 | mLastEnterAnimParams = null; |
| 4210 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | wtoken.removed = true; |
| 4212 | if (wtoken.startingData != null) { |
| 4213 | startingToken = wtoken; |
| 4214 | } |
| 4215 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4216 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4217 | 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] | 4218 | mFocusedApp = null; |
| 4219 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4220 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | } |
| 4222 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4223 | 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] | 4224 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | if (!delayed && wtoken != null) { |
| 4227 | wtoken.updateReportedVisibilityLocked(); |
| 4228 | } |
| 4229 | } |
| 4230 | Binder.restoreCallingIdentity(origId); |
| 4231 | |
| 4232 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4233 | 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] | 4234 | + startingToken + ": app token removed"); |
| 4235 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4236 | mH.sendMessage(m); |
| 4237 | } |
| 4238 | } |
| 4239 | |
| 4240 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4241 | final int NW = token.windows.size(); |
| 4242 | for (int i=0; i<NW; i++) { |
| 4243 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4244 | 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] | 4245 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4246 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | int j = win.mChildWindows.size(); |
| 4248 | while (j > 0) { |
| 4249 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4250 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4251 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4252 | "Tmp removing child window " + cwin); |
| 4253 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | } |
| 4255 | } |
| 4256 | return NW > 0; |
| 4257 | } |
| 4258 | |
| 4259 | void dumpAppTokensLocked() { |
| 4260 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4261 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4262 | } |
| 4263 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4265 | void dumpWindowsLocked() { |
| 4266 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4267 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | } |
| 4269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | private int findWindowOffsetLocked(int tokenPos) { |
| 4272 | final int NW = mWindows.size(); |
| 4273 | |
| 4274 | if (tokenPos >= mAppTokens.size()) { |
| 4275 | int i = NW; |
| 4276 | while (i > 0) { |
| 4277 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4278 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4279 | if (win.getAppToken() != null) { |
| 4280 | return i+1; |
| 4281 | } |
| 4282 | } |
| 4283 | } |
| 4284 | |
| 4285 | while (tokenPos > 0) { |
| 4286 | // Find the first app token below the new position that has |
| 4287 | // a window displayed. |
| 4288 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4289 | 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] | 4290 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4291 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4292 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4293 | "Skipping token -- currently sending to bottom"); |
| 4294 | tokenPos--; |
| 4295 | continue; |
| 4296 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4297 | int i = wtoken.windows.size(); |
| 4298 | while (i > 0) { |
| 4299 | i--; |
| 4300 | WindowState win = wtoken.windows.get(i); |
| 4301 | int j = win.mChildWindows.size(); |
| 4302 | while (j > 0) { |
| 4303 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4304 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4305 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | for (int pos=NW-1; pos>=0; pos--) { |
| 4307 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4308 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | "Found child win @" + (pos+1)); |
| 4310 | return pos+1; |
| 4311 | } |
| 4312 | } |
| 4313 | } |
| 4314 | } |
| 4315 | for (int pos=NW-1; pos>=0; pos--) { |
| 4316 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4317 | 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] | 4318 | return pos+1; |
| 4319 | } |
| 4320 | } |
| 4321 | } |
| 4322 | tokenPos--; |
| 4323 | } |
| 4324 | |
| 4325 | return 0; |
| 4326 | } |
| 4327 | |
| 4328 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4329 | final int NCW = win.mChildWindows.size(); |
| 4330 | boolean added = false; |
| 4331 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4332 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4334 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4335 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4336 | mWindows.add(index, win); |
| 4337 | index++; |
| 4338 | added = true; |
| 4339 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4340 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4341 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4342 | mWindows.add(index, cwin); |
| 4343 | index++; |
| 4344 | } |
| 4345 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4346 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4347 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | mWindows.add(index, win); |
| 4349 | index++; |
| 4350 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4351 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4352 | return index; |
| 4353 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4356 | final int NW = token.windows.size(); |
| 4357 | for (int i=0; i<NW; i++) { |
| 4358 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4359 | } |
| 4360 | return index; |
| 4361 | } |
| 4362 | |
| 4363 | public void moveAppToken(int index, IBinder token) { |
| 4364 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4365 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4366 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4370 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4372 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4373 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4374 | 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] | 4375 | + token + " (" + wtoken + ")"); |
| 4376 | return; |
| 4377 | } |
| 4378 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4379 | 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] | 4380 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4382 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4383 | 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] | 4384 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4385 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4386 | 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] | 4387 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4388 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4389 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4391 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4392 | mLayoutNeeded = true; |
| 4393 | performLayoutAndPlaceSurfacesLocked(); |
| 4394 | } |
| 4395 | Binder.restoreCallingIdentity(origId); |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4400 | // XXX This should be done more efficiently! |
| 4401 | // (take advantage of the fact that both lists should be |
| 4402 | // ordered in the same way.) |
| 4403 | int N = tokens.size(); |
| 4404 | for (int i=0; i<N; i++) { |
| 4405 | IBinder token = tokens.get(i); |
| 4406 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4407 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4408 | 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] | 4409 | + token + " (" + wtoken + ")"); |
| 4410 | i--; |
| 4411 | N--; |
| 4412 | } |
| 4413 | } |
| 4414 | } |
| 4415 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4416 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4417 | boolean updateFocusAndLayout) { |
| 4418 | // First remove all of the windows from the list. |
| 4419 | tmpRemoveAppWindowsLocked(wtoken); |
| 4420 | |
| 4421 | // Where to start adding? |
| 4422 | int pos = findWindowOffsetLocked(tokenPos); |
| 4423 | |
| 4424 | // And now add them back at the correct place. |
| 4425 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4426 | |
| 4427 | if (updateFocusAndLayout) { |
| 4428 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4429 | assignLayersLocked(); |
| 4430 | } |
| 4431 | mLayoutNeeded = true; |
| 4432 | performLayoutAndPlaceSurfacesLocked(); |
| 4433 | } |
| 4434 | } |
| 4435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4437 | // First remove all of the windows from the list. |
| 4438 | final int N = tokens.size(); |
| 4439 | int i; |
| 4440 | for (i=0; i<N; i++) { |
| 4441 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4442 | if (token != null) { |
| 4443 | tmpRemoveAppWindowsLocked(token); |
| 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | // Where to start adding? |
| 4448 | int pos = findWindowOffsetLocked(tokenPos); |
| 4449 | |
| 4450 | // And now add them back at the correct place. |
| 4451 | for (i=0; i<N; i++) { |
| 4452 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4453 | if (token != null) { |
| 4454 | pos = reAddAppWindowsLocked(pos, token); |
| 4455 | } |
| 4456 | } |
| 4457 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4458 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4459 | assignLayersLocked(); |
| 4460 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | mLayoutNeeded = true; |
| 4462 | performLayoutAndPlaceSurfacesLocked(); |
| 4463 | |
| 4464 | //dump(); |
| 4465 | } |
| 4466 | |
| 4467 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4468 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4469 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4470 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | final long origId = Binder.clearCallingIdentity(); |
| 4474 | synchronized(mWindowMap) { |
| 4475 | removeAppTokensLocked(tokens); |
| 4476 | final int N = tokens.size(); |
| 4477 | for (int i=0; i<N; i++) { |
| 4478 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4479 | if (wt != null) { |
| 4480 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4481 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4482 | mToTopApps.remove(wt); |
| 4483 | mToBottomApps.remove(wt); |
| 4484 | mToTopApps.add(wt); |
| 4485 | wt.sendingToBottom = false; |
| 4486 | wt.sendingToTop = true; |
| 4487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | } |
| 4489 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4490 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4491 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4492 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | } |
| 4495 | Binder.restoreCallingIdentity(origId); |
| 4496 | } |
| 4497 | |
| 4498 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4499 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4500 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4501 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | final long origId = Binder.clearCallingIdentity(); |
| 4505 | synchronized(mWindowMap) { |
| 4506 | removeAppTokensLocked(tokens); |
| 4507 | final int N = tokens.size(); |
| 4508 | int pos = 0; |
| 4509 | for (int i=0; i<N; i++) { |
| 4510 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4511 | if (wt != null) { |
| 4512 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4513 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4514 | mToTopApps.remove(wt); |
| 4515 | mToBottomApps.remove(wt); |
| 4516 | mToBottomApps.add(i, wt); |
| 4517 | wt.sendingToTop = false; |
| 4518 | wt.sendingToBottom = true; |
| 4519 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4520 | pos++; |
| 4521 | } |
| 4522 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4523 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4524 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4525 | moveAppWindowsLocked(tokens, 0); |
| 4526 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | } |
| 4528 | Binder.restoreCallingIdentity(origId); |
| 4529 | } |
| 4530 | |
| 4531 | // ------------------------------------------------------------- |
| 4532 | // Misc IWindowSession methods |
| 4533 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4534 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4535 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4536 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4537 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4538 | // called before DevicePolicyManagerService has started. |
| 4539 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4540 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4541 | Context.DEVICE_POLICY_SERVICE); |
| 4542 | if (dpm != null) { |
| 4543 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4544 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4545 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4546 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4547 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4548 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4549 | } |
| 4550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4551 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4552 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4553 | != PackageManager.PERMISSION_GRANTED) { |
| 4554 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4555 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4556 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4557 | synchronized (mKeyguardTokenWatcher) { |
| 4558 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4559 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4560 | } |
| 4561 | |
| 4562 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4563 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4564 | != PackageManager.PERMISSION_GRANTED) { |
| 4565 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4566 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4567 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4568 | synchronized (mKeyguardTokenWatcher) { |
| 4569 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4570 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4571 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4572 | // If we are the last one to reenable the keyguard wait until |
| 4573 | // we have actually finished reenabling until returning. |
| 4574 | // It is possible that reenableKeyguard() can be called before |
| 4575 | // the previous disableKeyguard() is handled, in which case |
| 4576 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4577 | // be called. In that case mKeyguardDisabled will be false here |
| 4578 | // and we have nothing to wait for. |
| 4579 | while (mKeyguardDisabled) { |
| 4580 | try { |
| 4581 | mKeyguardTokenWatcher.wait(); |
| 4582 | } catch (InterruptedException e) { |
| 4583 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | } |
| 4585 | } |
| 4586 | } |
| 4587 | } |
| 4588 | } |
| 4589 | |
| 4590 | /** |
| 4591 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4592 | */ |
| 4593 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4594 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4595 | != PackageManager.PERMISSION_GRANTED) { |
| 4596 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4597 | } |
| 4598 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4599 | public void onKeyguardExitResult(boolean success) { |
| 4600 | try { |
| 4601 | callback.onKeyguardExitResult(success); |
| 4602 | } catch (RemoteException e) { |
| 4603 | // Client has died, we don't care. |
| 4604 | } |
| 4605 | } |
| 4606 | }); |
| 4607 | } |
| 4608 | |
| 4609 | public boolean inKeyguardRestrictedInputMode() { |
| 4610 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4611 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4612 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4613 | public void closeSystemDialogs(String reason) { |
| 4614 | synchronized(mWindowMap) { |
| 4615 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4616 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4617 | if (w.mSurface != null) { |
| 4618 | try { |
| 4619 | w.mClient.closeSystemDialogs(reason); |
| 4620 | } catch (RemoteException e) { |
| 4621 | } |
| 4622 | } |
| 4623 | } |
| 4624 | } |
| 4625 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | static float fixScale(float scale) { |
| 4628 | if (scale < 0) scale = 0; |
| 4629 | else if (scale > 20) scale = 20; |
| 4630 | return Math.abs(scale); |
| 4631 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4633 | public void setAnimationScale(int which, float scale) { |
| 4634 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4635 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4636 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | if (scale < 0) scale = 0; |
| 4640 | else if (scale > 20) scale = 20; |
| 4641 | scale = Math.abs(scale); |
| 4642 | switch (which) { |
| 4643 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4644 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4647 | // Persist setting |
| 4648 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4651 | public void setAnimationScales(float[] scales) { |
| 4652 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4653 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4654 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | if (scales != null) { |
| 4658 | if (scales.length >= 1) { |
| 4659 | mWindowAnimationScale = fixScale(scales[0]); |
| 4660 | } |
| 4661 | if (scales.length >= 2) { |
| 4662 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4663 | } |
| 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 float getAnimationScale(int which) { |
| 4671 | switch (which) { |
| 4672 | case 0: return mWindowAnimationScale; |
| 4673 | case 1: return mTransitionAnimationScale; |
| 4674 | } |
| 4675 | return 0; |
| 4676 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4678 | public float[] getAnimationScales() { |
| 4679 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4680 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | public int getSwitchState(int sw) { |
| 4683 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4684 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4685 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4686 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4687 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4688 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4691 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4692 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4693 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4695 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4696 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4698 | public int getScancodeState(int sw) { |
| 4699 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4700 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4701 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4702 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4703 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4704 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4707 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4708 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4709 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4710 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4711 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4712 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4713 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4714 | public int getTrackballScancodeState(int sw) { |
| 4715 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4716 | "getTrackballScancodeState()")) { |
| 4717 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4718 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4719 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | public int getDPadScancodeState(int sw) { |
| 4723 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4724 | "getDPadScancodeState()")) { |
| 4725 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4726 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4727 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4728 | } |
| 4729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4730 | public int getKeycodeState(int sw) { |
| 4731 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4732 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4733 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4734 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4735 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4736 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4738 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4739 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4740 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4741 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4742 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4743 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4744 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4745 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4746 | public int getTrackballKeycodeState(int sw) { |
| 4747 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4748 | "getTrackballKeycodeState()")) { |
| 4749 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4750 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4751 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4752 | } |
| 4753 | |
| 4754 | public int getDPadKeycodeState(int sw) { |
| 4755 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4756 | "getDPadKeycodeState()")) { |
| 4757 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4758 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4759 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4760 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4762 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4763 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4764 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4765 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4766 | public InputChannel monitorInput(String inputChannelName) { |
| 4767 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4768 | "monitorInput()")) { |
| 4769 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4770 | } |
| 4771 | return mInputManager.monitorInput(inputChannelName); |
| 4772 | } |
| 4773 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4774 | public InputDevice getInputDevice(int deviceId) { |
| 4775 | return mInputManager.getInputDevice(deviceId); |
| 4776 | } |
| 4777 | |
| 4778 | public int[] getInputDeviceIds() { |
| 4779 | return mInputManager.getInputDeviceIds(); |
| 4780 | } |
| 4781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4782 | public void enableScreenAfterBoot() { |
| 4783 | synchronized(mWindowMap) { |
| 4784 | if (mSystemBooted) { |
| 4785 | return; |
| 4786 | } |
| 4787 | mSystemBooted = true; |
| 4788 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4790 | performEnableScreen(); |
| 4791 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4793 | public void enableScreenIfNeededLocked() { |
| 4794 | if (mDisplayEnabled) { |
| 4795 | return; |
| 4796 | } |
| 4797 | if (!mSystemBooted) { |
| 4798 | return; |
| 4799 | } |
| 4800 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4801 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4803 | public void performEnableScreen() { |
| 4804 | synchronized(mWindowMap) { |
| 4805 | if (mDisplayEnabled) { |
| 4806 | return; |
| 4807 | } |
| 4808 | if (!mSystemBooted) { |
| 4809 | return; |
| 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 | // Don't enable the screen until all existing windows |
| 4813 | // have been drawn. |
| 4814 | final int N = mWindows.size(); |
| 4815 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4816 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4817 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | return; |
| 4819 | } |
| 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 | mDisplayEnabled = true; |
| 4823 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4824 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4825 | StringWriter sw = new StringWriter(); |
| 4826 | PrintWriter pw = new PrintWriter(sw); |
| 4827 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4828 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4829 | } |
| 4830 | try { |
| 4831 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4832 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4833 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | Parcel data = Parcel.obtain(); |
| 4835 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4836 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4837 | data, null, 0); |
| 4838 | data.recycle(); |
| 4839 | } |
| 4840 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4841 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | } |
| 4843 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4845 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4847 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4848 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4849 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4850 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4852 | public void setInTouchMode(boolean mode) { |
| 4853 | synchronized(mWindowMap) { |
| 4854 | mInTouchMode = mode; |
| 4855 | } |
| 4856 | } |
| 4857 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4858 | public void freezeRotation() { |
| 4859 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 4860 | "setRotation()")) { |
| 4861 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4862 | } |
| 4863 | |
| 4864 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 4865 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4866 | } |
| 4867 | |
| 4868 | public void thawRotation() { |
| 4869 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 4870 | "setRotation()")) { |
| 4871 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4872 | } |
| 4873 | |
| 4874 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 4875 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4876 | } |
| 4877 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4878 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4879 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4880 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4881 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4882 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | } |
| 4884 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4885 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4887 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4888 | public void setRotationUnchecked(int rotation, |
| 4889 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4890 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4891 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | long origId = Binder.clearCallingIdentity(); |
| 4894 | boolean changed; |
| 4895 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4896 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4897 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4898 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4899 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | sendNewConfiguration(); |
| 4901 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4903 | Binder.restoreCallingIdentity(origId); |
| 4904 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4905 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4906 | /** |
| 4907 | * Apply a new rotation to the screen, respecting the requests of |
| 4908 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4909 | * re-evaluate the desired rotation. |
| 4910 | * |
| 4911 | * Returns null if the rotation has been changed. In this case YOU |
| 4912 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4913 | */ |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4914 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4915 | boolean changed; |
| 4916 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4917 | rotation = mRequestedRotation; |
| 4918 | } else { |
| 4919 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4920 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4921 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4922 | 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] | 4923 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4924 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4925 | 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] | 4926 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4928 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4929 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4930 | "Rotation changed to " + rotation |
| 4931 | + " from " + mRotation |
| 4932 | + " (forceApp=" + mForcedAppOrientation |
| 4933 | + ", req=" + mRequestedRotation + ")"); |
| 4934 | mRotation = rotation; |
| 4935 | mWindowsFreezingScreen = true; |
| 4936 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4937 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4938 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4939 | mWaitingForConfig = true; |
| 4940 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4941 | startFreezingDisplayLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4942 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4943 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4944 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4945 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4946 | } |
| 4947 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4948 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4949 | if (w.mSurface != null) { |
| 4950 | w.mOrientationChanging = true; |
| 4951 | } |
| 4952 | } |
| 4953 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4954 | try { |
| 4955 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4956 | } catch (RemoteException e) { |
| 4957 | } |
| 4958 | } |
| 4959 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4961 | return changed; |
| 4962 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4964 | public int getRotation() { |
| 4965 | return mRotation; |
| 4966 | } |
| 4967 | |
| 4968 | public int watchRotation(IRotationWatcher watcher) { |
| 4969 | final IBinder watcherBinder = watcher.asBinder(); |
| 4970 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4971 | public void binderDied() { |
| 4972 | synchronized (mWindowMap) { |
| 4973 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4974 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4975 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4976 | if (removed != null) { |
| 4977 | removed.asBinder().unlinkToDeath(this, 0); |
| 4978 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4979 | i--; |
| 4980 | } |
| 4981 | } |
| 4982 | } |
| 4983 | } |
| 4984 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4986 | synchronized (mWindowMap) { |
| 4987 | try { |
| 4988 | watcher.asBinder().linkToDeath(dr, 0); |
| 4989 | mRotationWatchers.add(watcher); |
| 4990 | } catch (RemoteException e) { |
| 4991 | // Client died, no cleanup needed. |
| 4992 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4994 | return mRotation; |
| 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | /** |
| 4999 | * Starts the view server on the specified port. |
| 5000 | * |
| 5001 | * @param port The port to listener to. |
| 5002 | * |
| 5003 | * @return True if the server was successfully started, false otherwise. |
| 5004 | * |
| 5005 | * @see com.android.server.ViewServer |
| 5006 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 5007 | */ |
| 5008 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5009 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5010 | return false; |
| 5011 | } |
| 5012 | |
| 5013 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5014 | return false; |
| 5015 | } |
| 5016 | |
| 5017 | if (port < 1024) { |
| 5018 | return false; |
| 5019 | } |
| 5020 | |
| 5021 | if (mViewServer != null) { |
| 5022 | if (!mViewServer.isRunning()) { |
| 5023 | try { |
| 5024 | return mViewServer.start(); |
| 5025 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5026 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5027 | } |
| 5028 | } |
| 5029 | return false; |
| 5030 | } |
| 5031 | |
| 5032 | try { |
| 5033 | mViewServer = new ViewServer(this, port); |
| 5034 | return mViewServer.start(); |
| 5035 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5036 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5037 | } |
| 5038 | return false; |
| 5039 | } |
| 5040 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5041 | private boolean isSystemSecure() { |
| 5042 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5043 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5044 | } |
| 5045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5046 | /** |
| 5047 | * Stops the view server if it exists. |
| 5048 | * |
| 5049 | * @return True if the server stopped, false if it wasn't started or |
| 5050 | * couldn't be stopped. |
| 5051 | * |
| 5052 | * @see com.android.server.ViewServer |
| 5053 | */ |
| 5054 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5055 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5056 | return false; |
| 5057 | } |
| 5058 | |
| 5059 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5060 | return false; |
| 5061 | } |
| 5062 | |
| 5063 | if (mViewServer != null) { |
| 5064 | return mViewServer.stop(); |
| 5065 | } |
| 5066 | return false; |
| 5067 | } |
| 5068 | |
| 5069 | /** |
| 5070 | * Indicates whether the view server is running. |
| 5071 | * |
| 5072 | * @return True if the server is running, false otherwise. |
| 5073 | * |
| 5074 | * @see com.android.server.ViewServer |
| 5075 | */ |
| 5076 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5077 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5078 | return false; |
| 5079 | } |
| 5080 | |
| 5081 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5082 | return false; |
| 5083 | } |
| 5084 | |
| 5085 | return mViewServer != null && mViewServer.isRunning(); |
| 5086 | } |
| 5087 | |
| 5088 | /** |
| 5089 | * Lists all availble windows in the system. The listing is written in the |
| 5090 | * specified Socket's output stream with the following syntax: |
| 5091 | * windowHashCodeInHexadecimal windowName |
| 5092 | * Each line of the ouput represents a different window. |
| 5093 | * |
| 5094 | * @param client The remote client to send the listing to. |
| 5095 | * @return False if an error occured, true otherwise. |
| 5096 | */ |
| 5097 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5098 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5099 | return false; |
| 5100 | } |
| 5101 | |
| 5102 | boolean result = true; |
| 5103 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5104 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5105 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5106 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5107 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | BufferedWriter out = null; |
| 5111 | |
| 5112 | // Any uncaught exception will crash the system process |
| 5113 | try { |
| 5114 | OutputStream clientStream = client.getOutputStream(); |
| 5115 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5116 | |
| 5117 | final int count = windows.length; |
| 5118 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5119 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5120 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5121 | out.write(' '); |
| 5122 | out.append(w.mAttrs.getTitle()); |
| 5123 | out.write('\n'); |
| 5124 | } |
| 5125 | |
| 5126 | out.write("DONE.\n"); |
| 5127 | out.flush(); |
| 5128 | } catch (Exception e) { |
| 5129 | result = false; |
| 5130 | } finally { |
| 5131 | if (out != null) { |
| 5132 | try { |
| 5133 | out.close(); |
| 5134 | } catch (IOException e) { |
| 5135 | result = false; |
| 5136 | } |
| 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | return result; |
| 5141 | } |
| 5142 | |
| 5143 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5144 | * Returns the focused window in the following format: |
| 5145 | * windowHashCodeInHexadecimal windowName |
| 5146 | * |
| 5147 | * @param client The remote client to send the listing to. |
| 5148 | * @return False if an error occurred, true otherwise. |
| 5149 | */ |
| 5150 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5151 | if (isSystemSecure()) { |
| 5152 | return false; |
| 5153 | } |
| 5154 | |
| 5155 | boolean result = true; |
| 5156 | |
| 5157 | WindowState focusedWindow = getFocusedWindow(); |
| 5158 | |
| 5159 | BufferedWriter out = null; |
| 5160 | |
| 5161 | // Any uncaught exception will crash the system process |
| 5162 | try { |
| 5163 | OutputStream clientStream = client.getOutputStream(); |
| 5164 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5165 | |
| 5166 | if(focusedWindow != null) { |
| 5167 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5168 | out.write(' '); |
| 5169 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5170 | } |
| 5171 | out.write('\n'); |
| 5172 | out.flush(); |
| 5173 | } catch (Exception e) { |
| 5174 | result = false; |
| 5175 | } finally { |
| 5176 | if (out != null) { |
| 5177 | try { |
| 5178 | out.close(); |
| 5179 | } catch (IOException e) { |
| 5180 | result = false; |
| 5181 | } |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | return result; |
| 5186 | } |
| 5187 | |
| 5188 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5189 | * Sends a command to a target window. The result of the command, if any, will be |
| 5190 | * written in the output stream of the specified socket. |
| 5191 | * |
| 5192 | * The parameters must follow this syntax: |
| 5193 | * windowHashcode extra |
| 5194 | * |
| 5195 | * Where XX is the length in characeters of the windowTitle. |
| 5196 | * |
| 5197 | * The first parameter is the target window. The window with the specified hashcode |
| 5198 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5199 | * will be delivered to the target window and as parameters to the command itself. |
| 5200 | * |
| 5201 | * @param client The remote client to sent the result, if any, to. |
| 5202 | * @param command The command to execute. |
| 5203 | * @param parameters The command parameters. |
| 5204 | * |
| 5205 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5206 | * not indicate whether the command itself was successful. |
| 5207 | */ |
| 5208 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5209 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5210 | return false; |
| 5211 | } |
| 5212 | |
| 5213 | boolean success = true; |
| 5214 | Parcel data = null; |
| 5215 | Parcel reply = null; |
| 5216 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5217 | BufferedWriter out = null; |
| 5218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5219 | // Any uncaught exception will crash the system process |
| 5220 | try { |
| 5221 | // Find the hashcode of the window |
| 5222 | int index = parameters.indexOf(' '); |
| 5223 | if (index == -1) { |
| 5224 | index = parameters.length(); |
| 5225 | } |
| 5226 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5227 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5228 | |
| 5229 | // Extract the command's parameter after the window description |
| 5230 | if (index < parameters.length()) { |
| 5231 | parameters = parameters.substring(index + 1); |
| 5232 | } else { |
| 5233 | parameters = ""; |
| 5234 | } |
| 5235 | |
| 5236 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5237 | if (window == null) { |
| 5238 | return false; |
| 5239 | } |
| 5240 | |
| 5241 | data = Parcel.obtain(); |
| 5242 | data.writeInterfaceToken("android.view.IWindow"); |
| 5243 | data.writeString(command); |
| 5244 | data.writeString(parameters); |
| 5245 | data.writeInt(1); |
| 5246 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5247 | |
| 5248 | reply = Parcel.obtain(); |
| 5249 | |
| 5250 | final IBinder binder = window.mClient.asBinder(); |
| 5251 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5252 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5253 | |
| 5254 | reply.readException(); |
| 5255 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5256 | if (!client.isOutputShutdown()) { |
| 5257 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5258 | out.write("DONE\n"); |
| 5259 | out.flush(); |
| 5260 | } |
| 5261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5263 | 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] | 5264 | success = false; |
| 5265 | } finally { |
| 5266 | if (data != null) { |
| 5267 | data.recycle(); |
| 5268 | } |
| 5269 | if (reply != null) { |
| 5270 | reply.recycle(); |
| 5271 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5272 | if (out != null) { |
| 5273 | try { |
| 5274 | out.close(); |
| 5275 | } catch (IOException e) { |
| 5276 | |
| 5277 | } |
| 5278 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | return success; |
| 5282 | } |
| 5283 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5284 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5285 | synchronized(mWindowMap) { |
| 5286 | mWindowChangeListeners.add(listener); |
| 5287 | } |
| 5288 | } |
| 5289 | |
| 5290 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5291 | synchronized(mWindowMap) { |
| 5292 | mWindowChangeListeners.remove(listener); |
| 5293 | } |
| 5294 | } |
| 5295 | |
| 5296 | private void notifyWindowsChanged() { |
| 5297 | WindowChangeListener[] windowChangeListeners; |
| 5298 | synchronized(mWindowMap) { |
| 5299 | if(mWindowChangeListeners.isEmpty()) { |
| 5300 | return; |
| 5301 | } |
| 5302 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5303 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5304 | } |
| 5305 | int N = windowChangeListeners.length; |
| 5306 | for(int i = 0; i < N; i++) { |
| 5307 | windowChangeListeners[i].windowsChanged(); |
| 5308 | } |
| 5309 | } |
| 5310 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5311 | private void notifyFocusChanged() { |
| 5312 | WindowChangeListener[] windowChangeListeners; |
| 5313 | synchronized(mWindowMap) { |
| 5314 | if(mWindowChangeListeners.isEmpty()) { |
| 5315 | return; |
| 5316 | } |
| 5317 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5318 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5319 | } |
| 5320 | int N = windowChangeListeners.length; |
| 5321 | for(int i = 0; i < N; i++) { |
| 5322 | windowChangeListeners[i].focusChanged(); |
| 5323 | } |
| 5324 | } |
| 5325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | private WindowState findWindow(int hashCode) { |
| 5327 | if (hashCode == -1) { |
| 5328 | return getFocusedWindow(); |
| 5329 | } |
| 5330 | |
| 5331 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5332 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | final int count = windows.size(); |
| 5334 | |
| 5335 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5336 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5337 | if (System.identityHashCode(w) == hashCode) { |
| 5338 | return w; |
| 5339 | } |
| 5340 | } |
| 5341 | } |
| 5342 | |
| 5343 | return null; |
| 5344 | } |
| 5345 | |
| 5346 | /* |
| 5347 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5348 | * that to config-changed listeners if appropriate. |
| 5349 | */ |
| 5350 | void sendNewConfiguration() { |
| 5351 | try { |
| 5352 | mActivityManager.updateConfiguration(null); |
| 5353 | } catch (RemoteException e) { |
| 5354 | } |
| 5355 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5357 | public Configuration computeNewConfiguration() { |
| 5358 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5359 | return computeNewConfigurationLocked(); |
| 5360 | } |
| 5361 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5362 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5363 | Configuration computeNewConfigurationLocked() { |
| 5364 | Configuration config = new Configuration(); |
| 5365 | if (!computeNewConfigurationLocked(config)) { |
| 5366 | return null; |
| 5367 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5368 | return config; |
| 5369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5370 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5371 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5372 | if (mDisplay == null) { |
| 5373 | return false; |
| 5374 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5375 | |
| 5376 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5377 | |
| 5378 | // Use the effective "visual" dimensions based on current rotation |
| 5379 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5380 | || mRotation == Surface.ROTATION_270); |
| 5381 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5382 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5383 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5384 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5385 | if (dw < dh) { |
| 5386 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5387 | } else if (dw > dh) { |
| 5388 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5389 | } |
| 5390 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5391 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5392 | DisplayMetrics dm = new DisplayMetrics(); |
| 5393 | mDisplay.getMetrics(dm); |
| 5394 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5395 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5396 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5397 | // Note we only do this once because at this point we don't |
| 5398 | // expect the screen to change in this way at runtime, and want |
| 5399 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5400 | int longSize = dw; |
| 5401 | int shortSize = dh; |
| 5402 | if (longSize < shortSize) { |
| 5403 | int tmp = longSize; |
| 5404 | longSize = shortSize; |
| 5405 | shortSize = tmp; |
| 5406 | } |
| 5407 | longSize = (int)(longSize/dm.density); |
| 5408 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5409 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5410 | // These semi-magic numbers define our compatibility modes for |
| 5411 | // applications with different screens. Don't change unless you |
| 5412 | // make sure to test lots and lots of apps! |
| 5413 | if (longSize < 470) { |
| 5414 | // This is shorter than an HVGA normal density screen (which |
| 5415 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5416 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5417 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5418 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5419 | // What size is this screen screen? |
| 5420 | if (longSize >= 800 && shortSize >= 600) { |
| 5421 | // SVGA or larger screens at medium density are the point |
| 5422 | // at which we consider it to be an extra large screen. |
| 5423 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5424 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5425 | // SVGA or larger screens at high density are the point |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5426 | // at which we consider it to be a large screen. |
| 5427 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5428 | } else { |
| 5429 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5430 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5431 | // If this screen is wider than normal HVGA, or taller |
| 5432 | // than FWVGA, then for old apps we want to run in size |
| 5433 | // compatibility mode. |
| 5434 | if (shortSize > 321 || longSize > 570) { |
| 5435 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5436 | } |
| 5437 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5438 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5439 | // Is this a long screen? |
| 5440 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5441 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5442 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5443 | } else { |
| 5444 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5445 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5446 | } |
| 5447 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5448 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5449 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5450 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5451 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5452 | mPolicy.adjustConfigurationLw(config); |
| 5453 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5454 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5455 | |
| 5456 | // ------------------------------------------------------------- |
| 5457 | // Drag and drop |
| 5458 | // ------------------------------------------------------------- |
| 5459 | |
| 5460 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| 5461 | boolean localOnly, int width, int height, Surface outSurface) { |
| 5462 | if (DEBUG_DRAG) { |
| 5463 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| 5464 | + " local=" + localOnly + " win=" + window |
| 5465 | + " asbinder=" + window.asBinder()); |
| 5466 | } |
| 5467 | |
| 5468 | final int callerPid = Binder.getCallingPid(); |
| 5469 | final long origId = Binder.clearCallingIdentity(); |
| 5470 | IBinder token = null; |
| 5471 | |
| 5472 | try { |
| 5473 | synchronized (mWindowMap) { |
| 5474 | try { |
| 5475 | // !!! TODO: fail if the given window does not currently have touch focus? |
| 5476 | |
| 5477 | if (mDragState == null) { |
| 5478 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5479 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5480 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5481 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5482 | token = new Binder(); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5483 | mDragState = new DragState(token, surface, localOnly, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5484 | mDragState.mSurface = surface; |
| 5485 | mDragState.mLocalOnly = localOnly; |
| 5486 | token = mDragState.mToken = new Binder(); |
| 5487 | |
| 5488 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5489 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5490 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5491 | mH.sendMessageDelayed(msg, 5000); |
| 5492 | } else { |
| 5493 | Slog.w(TAG, "Drag already in progress"); |
| 5494 | } |
| 5495 | } catch (Surface.OutOfResourcesException e) { |
| 5496 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5497 | if (mDragState != null) { |
| 5498 | mDragState.reset(); |
| 5499 | mDragState = null; |
| 5500 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5501 | } |
| 5502 | } |
| 5503 | } finally { |
| 5504 | Binder.restoreCallingIdentity(origId); |
| 5505 | } |
| 5506 | |
| 5507 | return token; |
| 5508 | } |
| 5509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5510 | // ------------------------------------------------------------- |
| 5511 | // Input Events and Focus Management |
| 5512 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5513 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5514 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5515 | |
| 5516 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5517 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5518 | * other relevant Window Manager state transitions. */ |
| 5519 | final class InputMonitor { |
| 5520 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5521 | private WindowState mInputFocus; |
| 5522 | |
| 5523 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5524 | private boolean mInputDispatchFrozen; |
| 5525 | |
| 5526 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5527 | private boolean mInputDispatchEnabled = true; |
| 5528 | |
| 5529 | // Temporary list of windows information to provide to the input dispatcher. |
| 5530 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5531 | |
| 5532 | // Temporary input application object to provide to the input dispatcher. |
| 5533 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5534 | |
| 5535 | /* Notifies the window manager about a broken input channel. |
| 5536 | * |
| 5537 | * Called by the InputManager. |
| 5538 | */ |
| 5539 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5540 | synchronized (mWindowMap) { |
| 5541 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5542 | if (windowState == null) { |
| 5543 | return; // irrelevant |
| 5544 | } |
| 5545 | |
| 5546 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5547 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5548 | } |
| 5549 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5550 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5551 | /* Notifies the window manager about an application that is not responding. |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5552 | * 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] | 5553 | * |
| 5554 | * Called by the InputManager. |
| 5555 | */ |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5556 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 5557 | AppWindowToken appWindowToken = null; |
| 5558 | if (inputChannel != null) { |
| 5559 | synchronized (mWindowMap) { |
| 5560 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5561 | if (windowState != null) { |
| 5562 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5563 | + windowState.mAttrs.getTitle()); |
| 5564 | appWindowToken = windowState.mAppToken; |
| 5565 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5566 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5567 | } |
| 5568 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5569 | if (appWindowToken == null && token != null) { |
| 5570 | appWindowToken = (AppWindowToken) token; |
| 5571 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5572 | + appWindowToken.stringName); |
| 5573 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5574 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5575 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5576 | try { |
| 5577 | // Notify the activity manager about the timeout and let it decide whether |
| 5578 | // to abort dispatching or keep waiting. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5579 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5580 | if (! abort) { |
| 5581 | // The activity manager declined to abort dispatching. |
| 5582 | // Wait a bit longer and timeout again later. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5583 | return appWindowToken.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5584 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5585 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5586 | } |
| 5587 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5588 | return 0; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5589 | } |
| 5590 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5591 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5592 | synchronized (mWindowMap) { |
| 5593 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5594 | } |
| 5595 | } |
| 5596 | |
| 5597 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5598 | int windowCount = mWindows.size(); |
| 5599 | for (int i = 0; i < windowCount; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5600 | WindowState windowState = mWindows.get(i); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5601 | if (windowState.mInputChannel == inputChannel) { |
| 5602 | return windowState; |
| 5603 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5604 | } |
| 5605 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5606 | return null; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5607 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5608 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5609 | private void addDragInputWindowLw(InputWindowList windowList) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5610 | final InputWindow inputWindow = windowList.add(); |
| 5611 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5612 | inputWindow.name = "drag"; |
| 5613 | inputWindow.layoutParamsFlags = 0; |
| 5614 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5615 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5616 | inputWindow.visible = true; |
| 5617 | inputWindow.canReceiveKeys = false; |
| 5618 | inputWindow.hasFocus = true; |
| 5619 | inputWindow.hasWallpaper = false; |
| 5620 | inputWindow.paused = false; |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5621 | inputWindow.layer = mDragState.getDragLayerLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5622 | inputWindow.ownerPid = Process.myPid(); |
| 5623 | inputWindow.ownerUid = Process.myUid(); |
| 5624 | |
| 5625 | // The drag window covers the entire display |
| 5626 | inputWindow.frameLeft = 0; |
| 5627 | inputWindow.frameTop = 0; |
| 5628 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5629 | inputWindow.frameBottom = mDisplay.getHeight(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5630 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5631 | inputWindow.visibleFrameLeft = inputWindow.frameLeft; |
| 5632 | inputWindow.visibleFrameTop = inputWindow.frameTop; |
| 5633 | inputWindow.visibleFrameRight = inputWindow.frameRight; |
| 5634 | inputWindow.visibleFrameBottom = inputWindow.frameBottom; |
| 5635 | |
| 5636 | inputWindow.touchableAreaLeft = inputWindow.frameLeft; |
| 5637 | inputWindow.touchableAreaTop = inputWindow.frameTop; |
| 5638 | inputWindow.touchableAreaRight = inputWindow.frameRight; |
| 5639 | inputWindow.touchableAreaBottom = inputWindow.frameBottom; |
| 5640 | } |
| 5641 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5642 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5643 | public void updateInputWindowsLw() { |
| 5644 | // Populate the input window list with information about all of the windows that |
| 5645 | // could potentially receive input. |
| 5646 | // As an optimization, we could try to prune the list of windows but this turns |
| 5647 | // out to be difficult because only the native code knows for sure which window |
| 5648 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5649 | final ArrayList<WindowState> windows = mWindows; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5650 | |
| 5651 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5652 | final boolean inDrag = (mDragState != null); |
| 5653 | if (inDrag) { |
| 5654 | if (DEBUG_DRAG) { |
| 5655 | Log.d(TAG, "Inserting drag window"); |
| 5656 | } |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5657 | addDragInputWindowLw(mTempInputWindows); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5658 | } |
| 5659 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5660 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5661 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5662 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5663 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5664 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5665 | continue; |
| 5666 | } |
| 5667 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5668 | final int flags = child.mAttrs.flags; |
| 5669 | final int type = child.mAttrs.type; |
| 5670 | |
| 5671 | final boolean hasFocus = (child == mInputFocus); |
| 5672 | final boolean isVisible = child.isVisibleLw(); |
| 5673 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5674 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5675 | |
| 5676 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5677 | // make sure it's been told about the drag |
| 5678 | if (inDrag && isVisible) { |
| 5679 | mDragState.sendDragStartedIfNeededLw(child); |
| 5680 | } |
| 5681 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5682 | // Add a window to our list of input windows. |
| 5683 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5684 | inputWindow.inputChannel = child.mInputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5685 | inputWindow.name = child.toString(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5686 | inputWindow.layoutParamsFlags = flags; |
| 5687 | inputWindow.layoutParamsType = type; |
| 5688 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5689 | inputWindow.visible = isVisible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5690 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5691 | inputWindow.hasFocus = hasFocus; |
| 5692 | inputWindow.hasWallpaper = hasWallpaper; |
| 5693 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5694 | inputWindow.layer = child.mLayer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5695 | inputWindow.ownerPid = child.mSession.mPid; |
| 5696 | inputWindow.ownerUid = child.mSession.mUid; |
| 5697 | |
| 5698 | final Rect frame = child.mFrame; |
| 5699 | inputWindow.frameLeft = frame.left; |
| 5700 | inputWindow.frameTop = frame.top; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5701 | inputWindow.frameRight = frame.right; |
| 5702 | inputWindow.frameBottom = frame.bottom; |
| 5703 | |
| 5704 | final Rect visibleFrame = child.mVisibleFrame; |
| 5705 | inputWindow.visibleFrameLeft = visibleFrame.left; |
| 5706 | inputWindow.visibleFrameTop = visibleFrame.top; |
| 5707 | inputWindow.visibleFrameRight = visibleFrame.right; |
| 5708 | inputWindow.visibleFrameBottom = visibleFrame.bottom; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5709 | |
| 5710 | switch (child.mTouchableInsets) { |
| 5711 | default: |
| 5712 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5713 | inputWindow.touchableAreaLeft = frame.left; |
| 5714 | inputWindow.touchableAreaTop = frame.top; |
| 5715 | inputWindow.touchableAreaRight = frame.right; |
| 5716 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5717 | break; |
| 5718 | |
| 5719 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5720 | Rect inset = child.mGivenContentInsets; |
| 5721 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5722 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5723 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5724 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5725 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5726 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5727 | |
| 5728 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5729 | Rect inset = child.mGivenVisibleInsets; |
| 5730 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5731 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5732 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5733 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5734 | break; |
| 5735 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5736 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5737 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5738 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5739 | // Send windows to native code. |
| 5740 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5741 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5742 | // Clear the list in preparation for the next round. |
| 5743 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5744 | mTempInputWindows.clear(); |
| 5745 | } |
| 5746 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5747 | /* Notifies that the lid switch changed state. */ |
| 5748 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5749 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5750 | } |
| 5751 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5752 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5753 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5754 | public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags, |
| 5755 | int keyCode, int scanCode, int policyFlags, boolean isScreenOn) { |
| 5756 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags, |
| 5757 | keyCode, scanCode, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | /* Provides an opportunity for the window manager policy to process a key before |
| 5761 | * ordinary dispatch. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5762 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5763 | int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount, |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5764 | int policyFlags) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5765 | WindowState windowState = getWindowStateForInputChannel(focus); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5766 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5767 | keyCode, scanCode, metaState, repeatCount, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | /* Called when the current input focus changes. |
| 5771 | * Layer assignment is assumed to be complete by the time this is called. |
| 5772 | */ |
| 5773 | public void setInputFocusLw(WindowState newWindow) { |
| 5774 | if (DEBUG_INPUT) { |
| 5775 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5776 | } |
| 5777 | |
| 5778 | if (newWindow != mInputFocus) { |
| 5779 | if (newWindow != null && newWindow.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5780 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5781 | // This is to protect against bugs if someone pauses dispatching but |
| 5782 | // forgets to resume. |
| 5783 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5784 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5785 | |
| 5786 | mInputFocus = newWindow; |
| 5787 | updateInputWindowsLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5788 | } |
| 5789 | } |
| 5790 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5791 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5792 | // Focused app has changed. |
| 5793 | if (newApp == null) { |
| 5794 | mInputManager.setFocusedApplication(null); |
| 5795 | } else { |
| 5796 | mTempInputApplication.name = newApp.toString(); |
| 5797 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5798 | newApp.inputDispatchingTimeoutNanos; |
| 5799 | mTempInputApplication.token = newApp; |
| 5800 | |
| 5801 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5802 | } |
| 5803 | } |
| 5804 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5805 | public void pauseDispatchingLw(WindowToken window) { |
| 5806 | if (! window.paused) { |
| 5807 | if (DEBUG_INPUT) { |
| 5808 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5809 | } |
| 5810 | |
| 5811 | window.paused = true; |
| 5812 | updateInputWindowsLw(); |
| 5813 | } |
| 5814 | } |
| 5815 | |
| 5816 | public void resumeDispatchingLw(WindowToken window) { |
| 5817 | if (window.paused) { |
| 5818 | if (DEBUG_INPUT) { |
| 5819 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5820 | } |
| 5821 | |
| 5822 | window.paused = false; |
| 5823 | updateInputWindowsLw(); |
| 5824 | } |
| 5825 | } |
| 5826 | |
| 5827 | public void freezeInputDispatchingLw() { |
| 5828 | if (! mInputDispatchFrozen) { |
| 5829 | if (DEBUG_INPUT) { |
| 5830 | Slog.v(TAG, "Freezing input dispatching"); |
| 5831 | } |
| 5832 | |
| 5833 | mInputDispatchFrozen = true; |
| 5834 | updateInputDispatchModeLw(); |
| 5835 | } |
| 5836 | } |
| 5837 | |
| 5838 | public void thawInputDispatchingLw() { |
| 5839 | if (mInputDispatchFrozen) { |
| 5840 | if (DEBUG_INPUT) { |
| 5841 | Slog.v(TAG, "Thawing input dispatching"); |
| 5842 | } |
| 5843 | |
| 5844 | mInputDispatchFrozen = false; |
| 5845 | updateInputDispatchModeLw(); |
| 5846 | } |
| 5847 | } |
| 5848 | |
| 5849 | public void setEventDispatchingLw(boolean enabled) { |
| 5850 | if (mInputDispatchEnabled != enabled) { |
| 5851 | if (DEBUG_INPUT) { |
| 5852 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5853 | } |
| 5854 | |
| 5855 | mInputDispatchEnabled = enabled; |
| 5856 | updateInputDispatchModeLw(); |
| 5857 | } |
| 5858 | } |
| 5859 | |
| 5860 | private void updateInputDispatchModeLw() { |
| 5861 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5862 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5863 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5865 | public void pauseKeyDispatching(IBinder _token) { |
| 5866 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5867 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5868 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | synchronized (mWindowMap) { |
| 5872 | WindowToken token = mTokenMap.get(_token); |
| 5873 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5874 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5875 | } |
| 5876 | } |
| 5877 | } |
| 5878 | |
| 5879 | public void resumeKeyDispatching(IBinder _token) { |
| 5880 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5881 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5882 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | synchronized (mWindowMap) { |
| 5886 | WindowToken token = mTokenMap.get(_token); |
| 5887 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5888 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5889 | } |
| 5890 | } |
| 5891 | } |
| 5892 | |
| 5893 | public void setEventDispatching(boolean enabled) { |
| 5894 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5895 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5896 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5900 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5901 | } |
| 5902 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5904 | /** |
| 5905 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5906 | * Even when sync is false, this method may block while waiting for current |
| 5907 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5908 | * |
| 5909 | * @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] | 5910 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5911 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5912 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5913 | */ |
| 5914 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5915 | long downTime = ev.getDownTime(); |
| 5916 | long eventTime = ev.getEventTime(); |
| 5917 | |
| 5918 | int action = ev.getAction(); |
| 5919 | int code = ev.getKeyCode(); |
| 5920 | int repeatCount = ev.getRepeatCount(); |
| 5921 | int metaState = ev.getMetaState(); |
| 5922 | int deviceId = ev.getDeviceId(); |
| 5923 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5924 | int source = ev.getSource(); |
| 5925 | |
| 5926 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5927 | source = InputDevice.SOURCE_KEYBOARD; |
| 5928 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5929 | |
| 5930 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5931 | if (downTime == 0) downTime = eventTime; |
| 5932 | |
| 5933 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5934 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5935 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5936 | final int pid = Binder.getCallingPid(); |
| 5937 | final int uid = Binder.getCallingUid(); |
| 5938 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5939 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5940 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5941 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5942 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5943 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5944 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5945 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5946 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | /** |
| 5950 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5951 | * Even when sync is false, this method may block while waiting for current |
| 5952 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5953 | * |
| 5954 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5955 | * {@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] | 5956 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5957 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5958 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5959 | */ |
| 5960 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5961 | final int pid = Binder.getCallingPid(); |
| 5962 | final int uid = Binder.getCallingUid(); |
| 5963 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5964 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5965 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5966 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5967 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5968 | } |
| 5969 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5970 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5971 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5972 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5973 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5974 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5975 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5976 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5977 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5979 | /** |
| 5980 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5981 | * Even when sync is false, this method may block while waiting for current |
| 5982 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5983 | * |
| 5984 | * @param ev A motion event describing the trackball action. (As noted in |
| 5985 | * {@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] | 5986 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5987 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5988 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5989 | */ |
| 5990 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5991 | final int pid = Binder.getCallingPid(); |
| 5992 | final int uid = Binder.getCallingUid(); |
| 5993 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5994 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5995 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5996 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5997 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5998 | } |
| 5999 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6000 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6001 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6002 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6003 | INJECTION_TIMEOUT_MILLIS); |
| 6004 | |
| 6005 | Binder.restoreCallingIdentity(ident); |
| 6006 | return reportInjectionResult(result); |
| 6007 | } |
| 6008 | |
| 6009 | /** |
| 6010 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 6011 | * This variant is useful for fire-and-forget input event injection. It does not |
| 6012 | * block any longer than it takes to enqueue the input event. |
| 6013 | * |
| 6014 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 6015 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6016 | */ |
| 6017 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 6018 | final int pid = Binder.getCallingPid(); |
| 6019 | final int uid = Binder.getCallingUid(); |
| 6020 | final long ident = Binder.clearCallingIdentity(); |
| 6021 | |
| 6022 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 6023 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 6024 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6025 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6026 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6027 | return reportInjectionResult(result); |
| 6028 | } |
| 6029 | |
| 6030 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6031 | switch (result) { |
| 6032 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6033 | Slog.w(TAG, "Input event injection permission denied."); |
| 6034 | throw new SecurityException( |
| 6035 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6036 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 6037 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6038 | return true; |
| 6039 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6040 | Slog.w(TAG, "Input event injection timed out."); |
| 6041 | return false; |
| 6042 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6043 | default: |
| 6044 | Slog.w(TAG, "Input event injection failed."); |
| 6045 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6046 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6047 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6049 | private WindowState getFocusedWindow() { |
| 6050 | synchronized (mWindowMap) { |
| 6051 | return getFocusedWindowLocked(); |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | private WindowState getFocusedWindowLocked() { |
| 6056 | return mCurrentFocus; |
| 6057 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6059 | public boolean detectSafeMode() { |
| 6060 | mSafeMode = mPolicy.detectSafeMode(); |
| 6061 | return mSafeMode; |
| 6062 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6063 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6064 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6065 | synchronized(mWindowMap) { |
| 6066 | if (mDisplay != null) { |
| 6067 | throw new IllegalStateException("Display already initialized"); |
| 6068 | } |
| 6069 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6070 | mDisplay = wm.getDefaultDisplay(); |
| 6071 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6072 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 6073 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 6074 | } |
| 6075 | |
| 6076 | try { |
| 6077 | mActivityManager.updateConfiguration(null); |
| 6078 | } catch (RemoteException e) { |
| 6079 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6080 | |
| 6081 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6082 | } |
| 6083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6084 | // ------------------------------------------------------------- |
| 6085 | // Client Session State |
| 6086 | // ------------------------------------------------------------- |
| 6087 | |
| 6088 | private final class Session extends IWindowSession.Stub |
| 6089 | implements IBinder.DeathRecipient { |
| 6090 | final IInputMethodClient mClient; |
| 6091 | final IInputContext mInputContext; |
| 6092 | final int mUid; |
| 6093 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6094 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6095 | SurfaceSession mSurfaceSession; |
| 6096 | int mNumWindow = 0; |
| 6097 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6100 | mClient = client; |
| 6101 | mInputContext = inputContext; |
| 6102 | mUid = Binder.getCallingUid(); |
| 6103 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6104 | StringBuilder sb = new StringBuilder(); |
| 6105 | sb.append("Session{"); |
| 6106 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6107 | sb.append(" uid "); |
| 6108 | sb.append(mUid); |
| 6109 | sb.append("}"); |
| 6110 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6112 | synchronized (mWindowMap) { |
| 6113 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6114 | IBinder b = ServiceManager.getService( |
| 6115 | Context.INPUT_METHOD_SERVICE); |
| 6116 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6117 | } |
| 6118 | } |
| 6119 | long ident = Binder.clearCallingIdentity(); |
| 6120 | try { |
| 6121 | // Note: it is safe to call in to the input method manager |
| 6122 | // here because we are not holding our lock. |
| 6123 | if (mInputMethodManager != null) { |
| 6124 | mInputMethodManager.addClient(client, inputContext, |
| 6125 | mUid, mPid); |
| 6126 | } else { |
| 6127 | client.setUsingInputMethod(false); |
| 6128 | } |
| 6129 | client.asBinder().linkToDeath(this, 0); |
| 6130 | } catch (RemoteException e) { |
| 6131 | // The caller has died, so we can just forget about this. |
| 6132 | try { |
| 6133 | if (mInputMethodManager != null) { |
| 6134 | mInputMethodManager.removeClient(client); |
| 6135 | } |
| 6136 | } catch (RemoteException ee) { |
| 6137 | } |
| 6138 | } finally { |
| 6139 | Binder.restoreCallingIdentity(ident); |
| 6140 | } |
| 6141 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6143 | @Override |
| 6144 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6145 | throws RemoteException { |
| 6146 | try { |
| 6147 | return super.onTransact(code, data, reply, flags); |
| 6148 | } catch (RuntimeException e) { |
| 6149 | // Log all 'real' exceptions thrown to the caller |
| 6150 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6151 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6152 | } |
| 6153 | throw e; |
| 6154 | } |
| 6155 | } |
| 6156 | |
| 6157 | public void binderDied() { |
| 6158 | // Note: it is safe to call in to the input method manager |
| 6159 | // here because we are not holding our lock. |
| 6160 | try { |
| 6161 | if (mInputMethodManager != null) { |
| 6162 | mInputMethodManager.removeClient(mClient); |
| 6163 | } |
| 6164 | } catch (RemoteException e) { |
| 6165 | } |
| 6166 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6167 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | mClientDead = true; |
| 6169 | killSessionLocked(); |
| 6170 | } |
| 6171 | } |
| 6172 | |
| 6173 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6174 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6175 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6176 | outInputChannel); |
| 6177 | } |
| 6178 | |
| 6179 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6181 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6182 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6184 | public void remove(IWindow window) { |
| 6185 | removeWindow(this, window); |
| 6186 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6189 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6190 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6191 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6192 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6193 | int res = relayoutWindow(this, window, attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6195 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6196 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6197 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6198 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6200 | public void setTransparentRegion(IWindow window, Region region) { |
| 6201 | setTransparentRegionWindow(this, window, region); |
| 6202 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6204 | public void setInsets(IWindow window, int touchableInsets, |
| 6205 | Rect contentInsets, Rect visibleInsets) { |
| 6206 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6207 | visibleInsets); |
| 6208 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6210 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6211 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6212 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6214 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6215 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6216 | TAG, "IWindow finishDrawing called for " + window); |
| 6217 | finishDrawingWindow(this, window); |
| 6218 | } |
| 6219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6220 | public void setInTouchMode(boolean mode) { |
| 6221 | synchronized(mWindowMap) { |
| 6222 | mInTouchMode = mode; |
| 6223 | } |
| 6224 | } |
| 6225 | |
| 6226 | public boolean getInTouchMode() { |
| 6227 | synchronized(mWindowMap) { |
| 6228 | return mInTouchMode; |
| 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6233 | boolean always) { |
| 6234 | synchronized(mWindowMap) { |
| 6235 | long ident = Binder.clearCallingIdentity(); |
| 6236 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6237 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6238 | windowForClientLocked(this, window, true), |
| 6239 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6240 | } finally { |
| 6241 | Binder.restoreCallingIdentity(ident); |
| 6242 | } |
| 6243 | } |
| 6244 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6245 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6246 | /* Drag/drop */ |
| 6247 | public IBinder prepareDrag(IWindow window, boolean localOnly, |
| 6248 | int width, int height, Surface outSurface) { |
| 6249 | return prepareDragSurface(window, mSurfaceSession, localOnly, |
| 6250 | width, height, outSurface); |
| 6251 | } |
| 6252 | |
| 6253 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6254 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6255 | ClipData data) { |
| 6256 | if (DEBUG_DRAG) { |
| 6257 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6258 | } |
| 6259 | |
| 6260 | synchronized (mWindowMap) { |
| 6261 | if (mDragState == null) { |
| 6262 | Slog.w(TAG, "No drag prepared"); |
| 6263 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6264 | } |
| 6265 | |
| 6266 | if (dragToken != mDragState.mToken) { |
| 6267 | Slog.w(TAG, "Performing mismatched drag"); |
| 6268 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6269 | } |
| 6270 | |
| 6271 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6272 | if (callingWin == null) { |
| 6273 | Slog.w(TAG, "Bad requesting window " + window); |
| 6274 | return false; // !!! TODO: throw here? |
| 6275 | } |
| 6276 | |
| 6277 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6278 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6279 | // called performDrag() |
| 6280 | |
| 6281 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6282 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6283 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6284 | // will let us eliminate the (touchX,touchY) parameters from the API. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6285 | |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6286 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6287 | // the actual drag event dispatch stuff in the dragstate |
| 6288 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6289 | mDragState.register(); |
| 6290 | mInputMonitor.updateInputWindowsLw(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6291 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6292 | mDragState.mServerChannel)) { |
| 6293 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6294 | mDragState.unregister(); |
| 6295 | mDragState = null; |
| 6296 | mInputMonitor.updateInputWindowsLw(); |
| 6297 | return false; |
| 6298 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6299 | |
| 6300 | mDragState.mData = data; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6301 | mDragState.mCurrentX = touchX; |
| 6302 | mDragState.mCurrentY = touchY; |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6303 | mDragState.broadcastDragStartedLw(touchX, touchY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6304 | |
| 6305 | // remember the thumb offsets for later |
| 6306 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6307 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6308 | |
| 6309 | // Make the surface visible at the proper location |
| 6310 | final Surface surface = mDragState.mSurface; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6311 | Surface.openTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6312 | try { |
| 6313 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6314 | (int)(touchY - thumbCenterY)); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6315 | surface.setAlpha(.7071f); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6316 | surface.setLayer(mDragState.getDragLayerLw()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6317 | surface.show(); |
| 6318 | } finally { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6319 | Surface.closeTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6320 | } |
| 6321 | } |
| 6322 | |
| 6323 | return true; // success! |
| 6324 | } |
| 6325 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6326 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6327 | IBinder token = window.asBinder(); |
| 6328 | if (DEBUG_DRAG) { |
| 6329 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6330 | } |
| 6331 | |
| 6332 | synchronized (mWindowMap) { |
| 6333 | if (mDragState.mToken != token) { |
| 6334 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6335 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6336 | } |
| 6337 | |
| 6338 | // The right window has responded, even if it's no longer around, |
| 6339 | // so be sure to halt the timeout even if the later WindowState |
| 6340 | // lookup fails. |
| 6341 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6342 | |
| 6343 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6344 | if (callingWin == null) { |
| 6345 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6346 | return; // !!! TODO: throw here? |
| 6347 | } |
| 6348 | |
| 6349 | mDragState.mDragResult = consumed; |
| 6350 | mDragState.endDragLw(); |
| 6351 | } |
| 6352 | } |
| 6353 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6354 | public void dragRecipientEntered(IWindow window) { |
| 6355 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6356 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6357 | } |
| 6358 | } |
| 6359 | |
| 6360 | public void dragRecipientExited(IWindow window) { |
| 6361 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6362 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6363 | } |
| 6364 | } |
| 6365 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6366 | 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] | 6367 | synchronized(mWindowMap) { |
| 6368 | long ident = Binder.clearCallingIdentity(); |
| 6369 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6370 | setWindowWallpaperPositionLocked( |
| 6371 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6372 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6373 | } finally { |
| 6374 | Binder.restoreCallingIdentity(ident); |
| 6375 | } |
| 6376 | } |
| 6377 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6378 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6379 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6380 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6381 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6382 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6383 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6384 | int z, Bundle extras, boolean sync) { |
| 6385 | synchronized(mWindowMap) { |
| 6386 | long ident = Binder.clearCallingIdentity(); |
| 6387 | try { |
| 6388 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6389 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6390 | action, x, y, z, extras, sync); |
| 6391 | } finally { |
| 6392 | Binder.restoreCallingIdentity(ident); |
| 6393 | } |
| 6394 | } |
| 6395 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6396 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6397 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6398 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6399 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | void windowAddedLocked() { |
| 6402 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6403 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6404 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6405 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6406 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6407 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6408 | mSessions.add(this); |
| 6409 | } |
| 6410 | mNumWindow++; |
| 6411 | } |
| 6412 | |
| 6413 | void windowRemovedLocked() { |
| 6414 | mNumWindow--; |
| 6415 | killSessionLocked(); |
| 6416 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6418 | void killSessionLocked() { |
| 6419 | if (mNumWindow <= 0 && mClientDead) { |
| 6420 | mSessions.remove(this); |
| 6421 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6422 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6423 | TAG, "Last window removed from " + this |
| 6424 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6425 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6426 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6427 | try { |
| 6428 | mSurfaceSession.kill(); |
| 6429 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6430 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6431 | + mSurfaceSession + " in session " + this |
| 6432 | + ": " + e.toString()); |
| 6433 | } |
| 6434 | mSurfaceSession = null; |
| 6435 | } |
| 6436 | } |
| 6437 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6439 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6440 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6441 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6442 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | @Override |
| 6446 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6447 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | } |
| 6449 | } |
| 6450 | |
| 6451 | // ------------------------------------------------------------- |
| 6452 | // Client Window State |
| 6453 | // ------------------------------------------------------------- |
| 6454 | |
| 6455 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6456 | final Session mSession; |
| 6457 | final IWindow mClient; |
| 6458 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6459 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6460 | AppWindowToken mAppToken; |
| 6461 | AppWindowToken mTargetAppToken; |
| 6462 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6463 | final DeathRecipient mDeathRecipient; |
| 6464 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6465 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | final int mBaseLayer; |
| 6467 | final int mSubLayer; |
| 6468 | final boolean mLayoutAttached; |
| 6469 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6470 | final boolean mIsWallpaper; |
| 6471 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6472 | int mViewVisibility; |
| 6473 | boolean mPolicyVisibility = true; |
| 6474 | boolean mPolicyVisibilityAfterAnim = true; |
| 6475 | boolean mAppFreezing; |
| 6476 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6477 | boolean mReportDestroySurface; |
| 6478 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6479 | boolean mAttachedHidden; // is our parent window hidden? |
| 6480 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6481 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | int mRequestedWidth; |
| 6483 | int mRequestedHeight; |
| 6484 | int mLastRequestedWidth; |
| 6485 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6486 | int mLayer; |
| 6487 | int mAnimLayer; |
| 6488 | int mLastLayer; |
| 6489 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6490 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6491 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6492 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6493 | int mLayoutSeq = -1; |
| 6494 | |
| 6495 | Configuration mConfiguration = null; |
| 6496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6497 | // Actual frame shown on-screen (may be modified by animation) |
| 6498 | final Rect mShownFrame = new Rect(); |
| 6499 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6501 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6502 | * Set when we have changed the size of the surface, to know that |
| 6503 | * we must tell them application to resize (and thus redraw itself). |
| 6504 | */ |
| 6505 | boolean mSurfaceResized; |
| 6506 | |
| 6507 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | * Insets that determine the actually visible area |
| 6509 | */ |
| 6510 | final Rect mVisibleInsets = new Rect(); |
| 6511 | final Rect mLastVisibleInsets = new Rect(); |
| 6512 | boolean mVisibleInsetsChanged; |
| 6513 | |
| 6514 | /** |
| 6515 | * Insets that are covered by system windows |
| 6516 | */ |
| 6517 | final Rect mContentInsets = new Rect(); |
| 6518 | final Rect mLastContentInsets = new Rect(); |
| 6519 | boolean mContentInsetsChanged; |
| 6520 | |
| 6521 | /** |
| 6522 | * Set to true if we are waiting for this window to receive its |
| 6523 | * given internal insets before laying out other windows based on it. |
| 6524 | */ |
| 6525 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6527 | /** |
| 6528 | * These are the content insets that were given during layout for |
| 6529 | * this window, to be applied to windows behind it. |
| 6530 | */ |
| 6531 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | /** |
| 6534 | * These are the visible insets that were given during layout for |
| 6535 | * this window, to be applied to windows behind it. |
| 6536 | */ |
| 6537 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | /** |
| 6540 | * Flag indicating whether the touchable region should be adjusted by |
| 6541 | * the visible insets; if false the area outside the visible insets is |
| 6542 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6543 | * tests. |
| 6544 | */ |
| 6545 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6547 | // Current transformation being applied. |
| 6548 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6549 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6550 | float mHScale=1, mVScale=1; |
| 6551 | float mLastHScale=1, mLastVScale=1; |
| 6552 | final Matrix mTmpMatrix = new Matrix(); |
| 6553 | |
| 6554 | // "Real" frame that the application sees. |
| 6555 | final Rect mFrame = new Rect(); |
| 6556 | final Rect mLastFrame = new Rect(); |
| 6557 | |
| 6558 | final Rect mContainingFrame = new Rect(); |
| 6559 | final Rect mDisplayFrame = new Rect(); |
| 6560 | final Rect mContentFrame = new Rect(); |
| 6561 | final Rect mVisibleFrame = new Rect(); |
| 6562 | |
| 6563 | float mShownAlpha = 1; |
| 6564 | float mAlpha = 1; |
| 6565 | float mLastAlpha = 1; |
| 6566 | |
| 6567 | // Set to true if, when the window gets displayed, it should perform |
| 6568 | // an enter animation. |
| 6569 | boolean mEnterAnimationPending; |
| 6570 | |
| 6571 | // Currently running animation. |
| 6572 | boolean mAnimating; |
| 6573 | boolean mLocalAnimating; |
| 6574 | Animation mAnimation; |
| 6575 | boolean mAnimationIsEntrance; |
| 6576 | boolean mHasTransformation; |
| 6577 | boolean mHasLocalTransformation; |
| 6578 | final Transformation mTransformation = new Transformation(); |
| 6579 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6580 | // If a window showing a wallpaper: the requested offset for the |
| 6581 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6582 | float mWallpaperX = -1; |
| 6583 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6584 | |
| 6585 | // If a window showing a wallpaper: what fraction of the offset |
| 6586 | // range corresponds to a full virtual screen. |
| 6587 | float mWallpaperXStep = -1; |
| 6588 | float mWallpaperYStep = -1; |
| 6589 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6590 | // Wallpaper windows: pixels offset based on above variables. |
| 6591 | int mXOffset; |
| 6592 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6594 | // This is set after IWindowSession.relayout() has been called at |
| 6595 | // least once for the window. It allows us to detect the situation |
| 6596 | // where we don't yet have a surface, but should have one soon, so |
| 6597 | // we can give the window focus before waiting for the relayout. |
| 6598 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6600 | // This is set after the Surface has been created but before the |
| 6601 | // window has been drawn. During this time the surface is hidden. |
| 6602 | boolean mDrawPending; |
| 6603 | |
| 6604 | // This is set after the window has finished drawing for the first |
| 6605 | // time but before its surface is shown. The surface will be |
| 6606 | // displayed when the next layout is run. |
| 6607 | boolean mCommitDrawPending; |
| 6608 | |
| 6609 | // This is set during the time after the window's drawing has been |
| 6610 | // committed, and before its surface is actually shown. It is used |
| 6611 | // to delay showing the surface until all windows in a token are ready |
| 6612 | // to be shown. |
| 6613 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | // Set when the window has been shown in the screen the first time. |
| 6616 | boolean mHasDrawn; |
| 6617 | |
| 6618 | // Currently running an exit animation? |
| 6619 | boolean mExiting; |
| 6620 | |
| 6621 | // Currently on the mDestroySurface list? |
| 6622 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | // Completely remove from window manager after exit animation? |
| 6625 | boolean mRemoveOnExit; |
| 6626 | |
| 6627 | // Set when the orientation is changing and this window has not yet |
| 6628 | // been updated for the new orientation. |
| 6629 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6631 | // Is this window now (or just being) removed? |
| 6632 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6633 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6634 | // For debugging, this is the last information given to the surface flinger. |
| 6635 | boolean mSurfaceShown; |
| 6636 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6637 | int mSurfaceLayer; |
| 6638 | float mSurfaceAlpha; |
| 6639 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6640 | // Input channel |
| 6641 | InputChannel mInputChannel; |
| 6642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6643 | WindowState(Session s, IWindow c, WindowToken token, |
| 6644 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6645 | int viewVisibility) { |
| 6646 | mSession = s; |
| 6647 | mClient = c; |
| 6648 | mToken = token; |
| 6649 | mAttrs.copyFrom(a); |
| 6650 | mViewVisibility = viewVisibility; |
| 6651 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6652 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6653 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6654 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6655 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6656 | try { |
| 6657 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6658 | } catch (RemoteException e) { |
| 6659 | mDeathRecipient = null; |
| 6660 | mAttachedWindow = null; |
| 6661 | mLayoutAttached = false; |
| 6662 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6663 | mIsWallpaper = false; |
| 6664 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6665 | mBaseLayer = 0; |
| 6666 | mSubLayer = 0; |
| 6667 | return; |
| 6668 | } |
| 6669 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6671 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6672 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6673 | // The multiplier here is to reserve space for multiple |
| 6674 | // windows in the same type layer. |
| 6675 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6676 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6677 | + TYPE_LAYER_OFFSET; |
| 6678 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6679 | mAttachedWindow = attachedWindow; |
| 6680 | mAttachedWindow.mChildWindows.add(this); |
| 6681 | mLayoutAttached = mAttrs.type != |
| 6682 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6683 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6684 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6685 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6686 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6687 | } else { |
| 6688 | // The multiplier here is to reserve space for multiple |
| 6689 | // windows in the same type layer. |
| 6690 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6691 | * TYPE_LAYER_MULTIPLIER |
| 6692 | + TYPE_LAYER_OFFSET; |
| 6693 | mSubLayer = 0; |
| 6694 | mAttachedWindow = null; |
| 6695 | mLayoutAttached = false; |
| 6696 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6697 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6698 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6699 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | WindowState appWin = this; |
| 6703 | while (appWin.mAttachedWindow != null) { |
| 6704 | appWin = mAttachedWindow; |
| 6705 | } |
| 6706 | WindowToken appToken = appWin.mToken; |
| 6707 | while (appToken.appWindowToken == null) { |
| 6708 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6709 | if (parent == null || appToken == parent) { |
| 6710 | break; |
| 6711 | } |
| 6712 | appToken = parent; |
| 6713 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6714 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | mAppToken = appToken.appWindowToken; |
| 6716 | |
| 6717 | mSurface = null; |
| 6718 | mRequestedWidth = 0; |
| 6719 | mRequestedHeight = 0; |
| 6720 | mLastRequestedWidth = 0; |
| 6721 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6722 | mXOffset = 0; |
| 6723 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6724 | mLayer = 0; |
| 6725 | mAnimLayer = 0; |
| 6726 | mLastLayer = 0; |
| 6727 | } |
| 6728 | |
| 6729 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6730 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6731 | TAG, "Attaching " + this + " token=" + mToken |
| 6732 | + ", list=" + mToken.windows); |
| 6733 | mSession.windowAddedLocked(); |
| 6734 | } |
| 6735 | |
| 6736 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6737 | mHaveFrame = true; |
| 6738 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6739 | final Rect container = mContainingFrame; |
| 6740 | container.set(pf); |
| 6741 | |
| 6742 | final Rect display = mDisplayFrame; |
| 6743 | display.set(df); |
| 6744 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6745 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6746 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6747 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6748 | display.intersect(mCompatibleScreenFrame); |
| 6749 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | final int pw = container.right - container.left; |
| 6753 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6754 | |
| 6755 | int w,h; |
| 6756 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6757 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6758 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6759 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6760 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6761 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6762 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6764 | final Rect content = mContentFrame; |
| 6765 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6767 | final Rect visible = mVisibleFrame; |
| 6768 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6770 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6771 | final int fw = frame.width(); |
| 6772 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6773 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6774 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6775 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6776 | |
| 6777 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6778 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6779 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6780 | |
| 6781 | //System.out.println("Out: " + mFrame); |
| 6782 | |
| 6783 | // Now make sure the window fits in the overall display. |
| 6784 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6786 | // Make sure the content and visible frames are inside of the |
| 6787 | // final window frame. |
| 6788 | if (content.left < frame.left) content.left = frame.left; |
| 6789 | if (content.top < frame.top) content.top = frame.top; |
| 6790 | if (content.right > frame.right) content.right = frame.right; |
| 6791 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6792 | if (visible.left < frame.left) visible.left = frame.left; |
| 6793 | if (visible.top < frame.top) visible.top = frame.top; |
| 6794 | if (visible.right > frame.right) visible.right = frame.right; |
| 6795 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | final Rect contentInsets = mContentInsets; |
| 6798 | contentInsets.left = content.left-frame.left; |
| 6799 | contentInsets.top = content.top-frame.top; |
| 6800 | contentInsets.right = frame.right-content.right; |
| 6801 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6803 | final Rect visibleInsets = mVisibleInsets; |
| 6804 | visibleInsets.left = visible.left-frame.left; |
| 6805 | visibleInsets.top = visible.top-frame.top; |
| 6806 | visibleInsets.right = frame.right-visible.right; |
| 6807 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6808 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6809 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6810 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6811 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6812 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6814 | if (localLOGV) { |
| 6815 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6816 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6817 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6818 | + mRequestedWidth + ", mRequestedheight=" |
| 6819 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6820 | + "): frame=" + mFrame.toShortString() |
| 6821 | + " ci=" + contentInsets.toShortString() |
| 6822 | + " vi=" + visibleInsets.toShortString()); |
| 6823 | //} |
| 6824 | } |
| 6825 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | public Rect getFrameLw() { |
| 6828 | return mFrame; |
| 6829 | } |
| 6830 | |
| 6831 | public Rect getShownFrameLw() { |
| 6832 | return mShownFrame; |
| 6833 | } |
| 6834 | |
| 6835 | public Rect getDisplayFrameLw() { |
| 6836 | return mDisplayFrame; |
| 6837 | } |
| 6838 | |
| 6839 | public Rect getContentFrameLw() { |
| 6840 | return mContentFrame; |
| 6841 | } |
| 6842 | |
| 6843 | public Rect getVisibleFrameLw() { |
| 6844 | return mVisibleFrame; |
| 6845 | } |
| 6846 | |
| 6847 | public boolean getGivenInsetsPendingLw() { |
| 6848 | return mGivenInsetsPending; |
| 6849 | } |
| 6850 | |
| 6851 | public Rect getGivenContentInsetsLw() { |
| 6852 | return mGivenContentInsets; |
| 6853 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6855 | public Rect getGivenVisibleInsetsLw() { |
| 6856 | return mGivenVisibleInsets; |
| 6857 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6859 | public WindowManager.LayoutParams getAttrs() { |
| 6860 | return mAttrs; |
| 6861 | } |
| 6862 | |
| 6863 | public int getSurfaceLayer() { |
| 6864 | return mLayer; |
| 6865 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6866 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | public IApplicationToken getAppToken() { |
| 6868 | return mAppToken != null ? mAppToken.appToken : null; |
| 6869 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6870 | |
| 6871 | public long getInputDispatchingTimeoutNanos() { |
| 6872 | return mAppToken != null |
| 6873 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6874 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6875 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6876 | |
| 6877 | public boolean hasAppShownWindows() { |
| 6878 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6879 | } |
| 6880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6881 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6882 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | TAG, "Setting animation in " + this + ": " + anim); |
| 6884 | mAnimating = false; |
| 6885 | mLocalAnimating = false; |
| 6886 | mAnimation = anim; |
| 6887 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6888 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6889 | } |
| 6890 | |
| 6891 | public void clearAnimation() { |
| 6892 | if (mAnimation != null) { |
| 6893 | mAnimating = true; |
| 6894 | mLocalAnimating = false; |
| 6895 | mAnimation = null; |
| 6896 | } |
| 6897 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | Surface createSurfaceLocked() { |
| 6900 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6901 | mReportDestroySurface = false; |
| 6902 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6903 | mDrawPending = true; |
| 6904 | mCommitDrawPending = false; |
| 6905 | mReadyToShow = false; |
| 6906 | if (mAppToken != null) { |
| 6907 | mAppToken.allDrawn = false; |
| 6908 | } |
| 6909 | |
| 6910 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6911 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6912 | flags |= Surface.PUSH_BUFFERS; |
| 6913 | } |
| 6914 | |
| 6915 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6916 | flags |= Surface.SECURE; |
| 6917 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6918 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6919 | TAG, "Creating surface in session " |
| 6920 | + mSession.mSurfaceSession + " window " + this |
| 6921 | + " w=" + mFrame.width() |
| 6922 | + " h=" + mFrame.height() + " format=" |
| 6923 | + mAttrs.format + " flags=" + flags); |
| 6924 | |
| 6925 | int w = mFrame.width(); |
| 6926 | int h = mFrame.height(); |
| 6927 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6928 | // for a scaled surface, we always want the requested |
| 6929 | // size. |
| 6930 | w = mRequestedWidth; |
| 6931 | h = mRequestedHeight; |
| 6932 | } |
| 6933 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6934 | // Something is wrong and SurfaceFlinger will not like this, |
| 6935 | // try to revert to sane values |
| 6936 | if (w <= 0) w = 1; |
| 6937 | if (h <= 0) h = 1; |
| 6938 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6939 | mSurfaceShown = false; |
| 6940 | mSurfaceLayer = 0; |
| 6941 | mSurfaceAlpha = 1; |
| 6942 | mSurfaceX = 0; |
| 6943 | mSurfaceY = 0; |
| 6944 | mSurfaceW = w; |
| 6945 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | try { |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 6947 | final boolean isHwAccelerated = (mAttrs.flags & |
| 6948 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 6949 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 6950 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 6951 | flags |= Surface.OPAQUE; |
| 6952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6954 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6955 | mAttrs.getTitle().toString(), |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 6956 | 0, w, h, format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6957 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6958 | + mSurface + " IN SESSION " |
| 6959 | + mSession.mSurfaceSession |
| 6960 | + ": pid=" + mSession.mPid + " format=" |
| 6961 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6962 | + Integer.toHexString(flags) |
| 6963 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6965 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6966 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6967 | return null; |
| 6968 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6969 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | return null; |
| 6971 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6972 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6973 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6974 | TAG, "Got surface: " + mSurface |
| 6975 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6976 | + ", animLayer=" + mAnimLayer); |
| 6977 | if (SHOW_TRANSACTIONS) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6978 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6979 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6980 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6981 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6982 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6983 | } |
| 6984 | Surface.openTransaction(); |
| 6985 | try { |
| 6986 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6987 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6988 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6989 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6990 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6991 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6992 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | mSurface.hide(); |
| 6994 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6995 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6996 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6997 | Surface.SURFACE_DITHER); |
| 6998 | } |
| 6999 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7000 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7001 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7002 | } |
| 7003 | mLastHidden = true; |
| 7004 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7005 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7006 | Surface.closeTransaction(); |
| 7007 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7008 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7009 | TAG, "Created surface " + this); |
| 7010 | } |
| 7011 | return mSurface; |
| 7012 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7015 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7016 | mAppToken.startingDisplayed = false; |
| 7017 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7019 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7020 | mDrawPending = false; |
| 7021 | mCommitDrawPending = false; |
| 7022 | mReadyToShow = false; |
| 7023 | |
| 7024 | int i = mChildWindows.size(); |
| 7025 | while (i > 0) { |
| 7026 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7027 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7028 | c.mAttachedHidden = true; |
| 7029 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7030 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7031 | if (mReportDestroySurface) { |
| 7032 | mReportDestroySurface = false; |
| 7033 | mSurfacePendingDestroy = true; |
| 7034 | try { |
| 7035 | mClient.dispatchGetNewSurface(); |
| 7036 | // We'll really destroy on the next time around. |
| 7037 | return; |
| 7038 | } catch (RemoteException e) { |
| 7039 | } |
| 7040 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7042 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7043 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7044 | RuntimeException e = null; |
| 7045 | if (!HIDE_STACK_CRAWLS) { |
| 7046 | e = new RuntimeException(); |
| 7047 | e.fillInStackTrace(); |
| 7048 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7049 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7050 | + mSurface + ", session " + mSession, e); |
| 7051 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7052 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7053 | RuntimeException e = null; |
| 7054 | if (!HIDE_STACK_CRAWLS) { |
| 7055 | e = new RuntimeException(); |
| 7056 | e.fillInStackTrace(); |
| 7057 | } |
| 7058 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7059 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7060 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7061 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7062 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | + " surface " + mSurface + " session " + mSession |
| 7064 | + ": " + e.toString()); |
| 7065 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7066 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7067 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7068 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7069 | } |
| 7070 | } |
| 7071 | |
| 7072 | boolean finishDrawingLocked() { |
| 7073 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7074 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | TAG, "finishDrawingLocked: " + mSurface); |
| 7076 | mCommitDrawPending = true; |
| 7077 | mDrawPending = false; |
| 7078 | return true; |
| 7079 | } |
| 7080 | return false; |
| 7081 | } |
| 7082 | |
| 7083 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7084 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7085 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7086 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7087 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7088 | } |
| 7089 | mCommitDrawPending = false; |
| 7090 | mReadyToShow = true; |
| 7091 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7092 | final AppWindowToken atoken = mAppToken; |
| 7093 | if (atoken == null || atoken.allDrawn || starting) { |
| 7094 | performShowLocked(); |
| 7095 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7096 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7097 | } |
| 7098 | |
| 7099 | // This must be called while inside a transaction. |
| 7100 | boolean performShowLocked() { |
| 7101 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7102 | RuntimeException e = null; |
| 7103 | if (!HIDE_STACK_CRAWLS) { |
| 7104 | e = new RuntimeException(); |
| 7105 | e.fillInStackTrace(); |
| 7106 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7107 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7108 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7109 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7110 | } |
| 7111 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7112 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7113 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7114 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7115 | + " during animation: policyVis=" + mPolicyVisibility |
| 7116 | + " attHidden=" + mAttachedHidden |
| 7117 | + " tok.hiddenRequested=" |
| 7118 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7119 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7120 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7121 | + " animating=" + mAnimating |
| 7122 | + " tok animating=" |
| 7123 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7124 | if (!showSurfaceRobustlyLocked(this)) { |
| 7125 | return false; |
| 7126 | } |
| 7127 | mLastAlpha = -1; |
| 7128 | mHasDrawn = true; |
| 7129 | mLastHidden = false; |
| 7130 | mReadyToShow = false; |
| 7131 | enableScreenIfNeededLocked(); |
| 7132 | |
| 7133 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7135 | int i = mChildWindows.size(); |
| 7136 | while (i > 0) { |
| 7137 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7138 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7139 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7140 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7141 | if (c.mSurface != null) { |
| 7142 | c.performShowLocked(); |
| 7143 | // It hadn't been shown, which means layout not |
| 7144 | // performed on it, so now we want to make sure to |
| 7145 | // do a layout. If called from within the transaction |
| 7146 | // loop, this will cause it to restart with a new |
| 7147 | // layout. |
| 7148 | mLayoutNeeded = true; |
| 7149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7150 | } |
| 7151 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7153 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7154 | && mAppToken != null) { |
| 7155 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7156 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7157 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7158 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7159 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7160 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7161 | // If this initial window is animating, stop it -- we |
| 7162 | // will do an animation to reveal it from behind the |
| 7163 | // starting window, so there is no need for it to also |
| 7164 | // be doing its own stuff. |
| 7165 | if (mAnimation != null) { |
| 7166 | mAnimation = null; |
| 7167 | // Make sure we clean up the animation. |
| 7168 | mAnimating = true; |
| 7169 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7170 | mFinishedStarting.add(mAppToken); |
| 7171 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7172 | } |
| 7173 | mAppToken.updateReportedVisibilityLocked(); |
| 7174 | } |
| 7175 | } |
| 7176 | return true; |
| 7177 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7179 | // This must be called while inside a transaction. Returns true if |
| 7180 | // there is more animation to run. |
| 7181 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7182 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7183 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7185 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7186 | mHasTransformation = true; |
| 7187 | mHasLocalTransformation = true; |
| 7188 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7189 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7190 | TAG, "Starting animation in " + this + |
| 7191 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7192 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7193 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7194 | mAnimation.setStartTime(currentTime); |
| 7195 | mLocalAnimating = true; |
| 7196 | mAnimating = true; |
| 7197 | } |
| 7198 | mTransformation.clear(); |
| 7199 | final boolean more = mAnimation.getTransformation( |
| 7200 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7201 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7202 | TAG, "Stepped animation in " + this + |
| 7203 | ": more=" + more + ", xform=" + mTransformation); |
| 7204 | if (more) { |
| 7205 | // we're not done! |
| 7206 | return true; |
| 7207 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7208 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7209 | TAG, "Finished animation in " + this + |
| 7210 | " @ " + currentTime); |
| 7211 | mAnimation = null; |
| 7212 | //WindowManagerService.this.dump(); |
| 7213 | } |
| 7214 | mHasLocalTransformation = false; |
| 7215 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7216 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7217 | // When our app token is animating, we kind-of pretend like |
| 7218 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7219 | // part of this check means that we will only do this if |
| 7220 | // our window is not currently exiting, or it is not |
| 7221 | // locally animating itself. The idea being that one that |
| 7222 | // is exiting and doing a local animation should be removed |
| 7223 | // once that animation is done. |
| 7224 | mAnimating = true; |
| 7225 | mHasTransformation = true; |
| 7226 | mTransformation.clear(); |
| 7227 | return false; |
| 7228 | } else if (mHasTransformation) { |
| 7229 | // Little trick to get through the path below to act like |
| 7230 | // we have finished an animation. |
| 7231 | mAnimating = true; |
| 7232 | } else if (isAnimating()) { |
| 7233 | mAnimating = true; |
| 7234 | } |
| 7235 | } else if (mAnimation != null) { |
| 7236 | // If the display is frozen, and there is a pending animation, |
| 7237 | // clear it and make sure we run the cleanup code. |
| 7238 | mAnimating = true; |
| 7239 | mLocalAnimating = true; |
| 7240 | mAnimation = null; |
| 7241 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | if (!mAnimating && !mLocalAnimating) { |
| 7244 | return false; |
| 7245 | } |
| 7246 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7247 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7248 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7249 | + ", reportedVisible=" |
| 7250 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | mAnimating = false; |
| 7253 | mLocalAnimating = false; |
| 7254 | mAnimation = null; |
| 7255 | mAnimLayer = mLayer; |
| 7256 | if (mIsImWindow) { |
| 7257 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7258 | } else if (mIsWallpaper) { |
| 7259 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7260 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7261 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | + " anim layer: " + mAnimLayer); |
| 7263 | mHasTransformation = false; |
| 7264 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7265 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7266 | if (DEBUG_VISIBILITY) { |
| 7267 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7268 | + mPolicyVisibilityAfterAnim); |
| 7269 | } |
| 7270 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7271 | if (!mPolicyVisibility) { |
| 7272 | if (mCurrentFocus == this) { |
| 7273 | mFocusMayChange = true; |
| 7274 | } |
| 7275 | // Window is no longer visible -- make sure if we were waiting |
| 7276 | // for it to be displayed before enabling the display, that |
| 7277 | // we allow the display to be enabled now. |
| 7278 | enableScreenIfNeededLocked(); |
| 7279 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7280 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7281 | mTransformation.clear(); |
| 7282 | if (mHasDrawn |
| 7283 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7284 | && mAppToken != null |
| 7285 | && mAppToken.firstWindowDrawn |
| 7286 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7287 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7288 | + mToken + ": first real window done animating"); |
| 7289 | mFinishedStarting.add(mAppToken); |
| 7290 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7291 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7292 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7293 | finishExit(); |
| 7294 | |
| 7295 | if (mAppToken != null) { |
| 7296 | mAppToken.updateReportedVisibilityLocked(); |
| 7297 | } |
| 7298 | |
| 7299 | return false; |
| 7300 | } |
| 7301 | |
| 7302 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7303 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7304 | TAG, "finishExit in " + this |
| 7305 | + ": exiting=" + mExiting |
| 7306 | + " remove=" + mRemoveOnExit |
| 7307 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7309 | final int N = mChildWindows.size(); |
| 7310 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7311 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7312 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7314 | if (!mExiting) { |
| 7315 | return; |
| 7316 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7318 | if (isWindowAnimating()) { |
| 7319 | return; |
| 7320 | } |
| 7321 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7322 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7323 | TAG, "Exit animation finished in " + this |
| 7324 | + ": remove=" + mRemoveOnExit); |
| 7325 | if (mSurface != null) { |
| 7326 | mDestroySurface.add(this); |
| 7327 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7328 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7329 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7330 | try { |
| 7331 | mSurface.hide(); |
| 7332 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7333 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | } |
| 7335 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7336 | } |
| 7337 | mExiting = false; |
| 7338 | if (mRemoveOnExit) { |
| 7339 | mPendingRemove.add(this); |
| 7340 | mRemoveOnExit = false; |
| 7341 | } |
| 7342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7345 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7346 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7347 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7348 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7349 | return true; |
| 7350 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7352 | void computeShownFrameLocked() { |
| 7353 | final boolean selfTransformation = mHasLocalTransformation; |
| 7354 | Transformation attachedTransformation = |
| 7355 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7356 | ? mAttachedWindow.mTransformation : null; |
| 7357 | Transformation appTransformation = |
| 7358 | (mAppToken != null && mAppToken.hasTransformation) |
| 7359 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7360 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7361 | // Wallpapers are animated based on the "real" window they |
| 7362 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7363 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7364 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7365 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7366 | mWallpaperTarget.mAnimation != null && |
| 7367 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7368 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7369 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7370 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7371 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7372 | } |
| 7373 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7374 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7375 | mWallpaperTarget.mAppToken.animation != null && |
| 7376 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7377 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7378 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7379 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7380 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7381 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7382 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7383 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7384 | if (selfTransformation || attachedTransformation != null |
| 7385 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7386 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | final Rect frame = mFrame; |
| 7388 | final float tmpFloats[] = mTmpFloats; |
| 7389 | final Matrix tmpMatrix = mTmpMatrix; |
| 7390 | |
| 7391 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7392 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7394 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7395 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7396 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7397 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7398 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7399 | } |
| 7400 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7401 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7402 | } |
| 7403 | |
| 7404 | // "convert" it into SurfaceFlinger's format |
| 7405 | // (a 2x2 matrix + an offset) |
| 7406 | // Here we must not transform the position of the surface |
| 7407 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7408 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7410 | tmpMatrix.getValues(tmpFloats); |
| 7411 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7412 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7413 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7414 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7415 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7416 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7417 | int w = frame.width(); |
| 7418 | int h = frame.height(); |
| 7419 | mShownFrame.set(x, y, x+w, y+h); |
| 7420 | |
| 7421 | // Now set the alpha... but because our current hardware |
| 7422 | // can't do alpha transformation on a non-opaque surface, |
| 7423 | // turn it off if we are running an animation that is also |
| 7424 | // transforming since it is more important to have that |
| 7425 | // animation be smooth. |
| 7426 | mShownAlpha = mAlpha; |
| 7427 | if (!mLimitedAlphaCompositing |
| 7428 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7429 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7430 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7431 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7432 | if (selfTransformation) { |
| 7433 | mShownAlpha *= mTransformation.getAlpha(); |
| 7434 | } |
| 7435 | if (attachedTransformation != null) { |
| 7436 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7437 | } |
| 7438 | if (appTransformation != null) { |
| 7439 | mShownAlpha *= appTransformation.getAlpha(); |
| 7440 | } |
| 7441 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7442 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7443 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7444 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7445 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7446 | TAG, "Continuing animation in " + this + |
| 7447 | ": " + mShownFrame + |
| 7448 | ", alpha=" + mTransformation.getAlpha()); |
| 7449 | return; |
| 7450 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7452 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7453 | if (mXOffset != 0 || mYOffset != 0) { |
| 7454 | mShownFrame.offset(mXOffset, mYOffset); |
| 7455 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7456 | mShownAlpha = mAlpha; |
| 7457 | mDsDx = 1; |
| 7458 | mDtDx = 0; |
| 7459 | mDsDy = 0; |
| 7460 | mDtDy = 1; |
| 7461 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7463 | /** |
| 7464 | * Is this window visible? It is not visible if there is no |
| 7465 | * surface, or we are in the process of running an exit animation |
| 7466 | * that will remove the surface, or its app token has been hidden. |
| 7467 | */ |
| 7468 | public boolean isVisibleLw() { |
| 7469 | final AppWindowToken atoken = mAppToken; |
| 7470 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7471 | && (atoken == null || !atoken.hiddenRequested) |
| 7472 | && !mExiting && !mDestroying; |
| 7473 | } |
| 7474 | |
| 7475 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7476 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7477 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7478 | * things like window flags that impact the keyguard. |
| 7479 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7480 | * for this "hidden behind keyguard" state rather than overloading |
| 7481 | * mPolicyVisibility. Ungh. |
| 7482 | */ |
| 7483 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7484 | final AppWindowToken atoken = mAppToken; |
| 7485 | return mSurface != null && !mAttachedHidden |
| 7486 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7487 | && !mDrawPending && !mCommitDrawPending |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7488 | && !mExiting && !mDestroying; |
| 7489 | } |
| 7490 | |
| 7491 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7492 | * Is this window visible, ignoring its app token? It is not visible |
| 7493 | * if there is no surface, or we are in the process of running an exit animation |
| 7494 | * that will remove the surface. |
| 7495 | */ |
| 7496 | public boolean isWinVisibleLw() { |
| 7497 | final AppWindowToken atoken = mAppToken; |
| 7498 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7499 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7500 | && !mExiting && !mDestroying; |
| 7501 | } |
| 7502 | |
| 7503 | /** |
| 7504 | * The same as isVisible(), but follows the current hidden state of |
| 7505 | * the associated app token, not the pending requested hidden state. |
| 7506 | */ |
| 7507 | boolean isVisibleNow() { |
| 7508 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7509 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7513 | * Can this window possibly be a drag/drop target? The test here is |
| 7514 | * a combination of the above "visible now" with the check that the |
| 7515 | * Input Manager uses when discarding windows from input consideration. |
| 7516 | */ |
| 7517 | boolean isPotentialDragTarget() { |
| 7518 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7519 | } |
| 7520 | |
| 7521 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7522 | * Same as isVisible(), but we also count it as visible between the |
| 7523 | * call to IWindowSession.add() and the first relayout(). |
| 7524 | */ |
| 7525 | boolean isVisibleOrAdding() { |
| 7526 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7527 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7528 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7529 | && mPolicyVisibility && !mAttachedHidden |
| 7530 | && (atoken == null || !atoken.hiddenRequested) |
| 7531 | && !mExiting && !mDestroying; |
| 7532 | } |
| 7533 | |
| 7534 | /** |
| 7535 | * Is this window currently on-screen? It is on-screen either if it |
| 7536 | * is visible or it is currently running an animation before no longer |
| 7537 | * being visible. |
| 7538 | */ |
| 7539 | boolean isOnScreen() { |
| 7540 | final AppWindowToken atoken = mAppToken; |
| 7541 | if (atoken != null) { |
| 7542 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7543 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7544 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7545 | } else { |
| 7546 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7547 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7548 | } |
| 7549 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7551 | /** |
| 7552 | * Like isOnScreen(), but we don't return true if the window is part |
| 7553 | * of a transition that has not yet been started. |
| 7554 | */ |
| 7555 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7556 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7557 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7558 | return false; |
| 7559 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7561 | final boolean animating = atoken != null |
| 7562 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7563 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7564 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7565 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7566 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | /** Is the window or its container currently animating? */ |
| 7570 | boolean isAnimating() { |
| 7571 | final WindowState attached = mAttachedWindow; |
| 7572 | final AppWindowToken atoken = mAppToken; |
| 7573 | return mAnimation != null |
| 7574 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7575 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7576 | (atoken.animation != null |
| 7577 | || atoken.inPendingTransaction)); |
| 7578 | } |
| 7579 | |
| 7580 | /** Is this window currently animating? */ |
| 7581 | boolean isWindowAnimating() { |
| 7582 | return mAnimation != null; |
| 7583 | } |
| 7584 | |
| 7585 | /** |
| 7586 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7587 | * been drawn. |
| 7588 | */ |
| 7589 | public boolean isDisplayedLw() { |
| 7590 | final AppWindowToken atoken = mAppToken; |
| 7591 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7592 | && !mDrawPending && !mCommitDrawPending |
| 7593 | && ((!mAttachedHidden && |
| 7594 | (atoken == null || !atoken.hiddenRequested)) |
| 7595 | || mAnimating); |
| 7596 | } |
| 7597 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7598 | /** |
| 7599 | * Returns true if the window has a surface that it has drawn a |
| 7600 | * complete UI in to. |
| 7601 | */ |
| 7602 | public boolean isDrawnLw() { |
| 7603 | final AppWindowToken atoken = mAppToken; |
| 7604 | return mSurface != null && !mDestroying |
| 7605 | && !mDrawPending && !mCommitDrawPending; |
| 7606 | } |
| 7607 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7608 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7609 | * Return true if the window is opaque and fully drawn. This indicates |
| 7610 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7611 | */ |
| 7612 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7613 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7614 | || mAttrs.type == TYPE_WALLPAPER) |
| 7615 | && mSurface != null && mAnimation == null |
| 7616 | && (mAppToken == null || mAppToken.animation == null) |
| 7617 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7618 | } |
| 7619 | |
| 7620 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7621 | return |
| 7622 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7623 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7624 | // only if it's visible |
| 7625 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7626 | // and only if the application fills the compatible screen |
| 7627 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7628 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7629 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7630 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7631 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7632 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7633 | } |
| 7634 | |
| 7635 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7636 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7637 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7641 | disposeInputChannel(); |
| 7642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7643 | if (mAttachedWindow != null) { |
| 7644 | mAttachedWindow.mChildWindows.remove(this); |
| 7645 | } |
| 7646 | destroySurfaceLocked(); |
| 7647 | mSession.windowRemovedLocked(); |
| 7648 | try { |
| 7649 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7650 | } catch (RuntimeException e) { |
| 7651 | // Ignore if it has already been removed (usually because |
| 7652 | // we are doing this as part of processing a death note.) |
| 7653 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7657 | if (mInputChannel != null) { |
| 7658 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7659 | |
| 7660 | mInputChannel.dispose(); |
| 7661 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7662 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7663 | } |
| 7664 | |
| 7665 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7666 | public void binderDied() { |
| 7667 | try { |
| 7668 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7669 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7670 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7671 | if (win != null) { |
| 7672 | removeWindowLocked(mSession, win); |
| 7673 | } |
| 7674 | } |
| 7675 | } catch (IllegalArgumentException ex) { |
| 7676 | // This will happen if the window has already been |
| 7677 | // removed. |
| 7678 | } |
| 7679 | } |
| 7680 | } |
| 7681 | |
| 7682 | /** Returns true if this window desires key events. */ |
| 7683 | public final boolean canReceiveKeys() { |
| 7684 | return isVisibleOrAdding() |
| 7685 | && (mViewVisibility == View.VISIBLE) |
| 7686 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7687 | } |
| 7688 | |
| 7689 | public boolean hasDrawnLw() { |
| 7690 | return mHasDrawn; |
| 7691 | } |
| 7692 | |
| 7693 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7694 | return showLw(doAnimation, true); |
| 7695 | } |
| 7696 | |
| 7697 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7698 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7699 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7700 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7701 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7702 | if (doAnimation) { |
| 7703 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7704 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7705 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7706 | doAnimation = false; |
| 7707 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7708 | // Check for the case where we are currently visible and |
| 7709 | // not animating; we do not want to do animation at such a |
| 7710 | // point to become visible when we already are. |
| 7711 | doAnimation = false; |
| 7712 | } |
| 7713 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7714 | mPolicyVisibility = true; |
| 7715 | mPolicyVisibilityAfterAnim = true; |
| 7716 | if (doAnimation) { |
| 7717 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7718 | } |
| 7719 | if (requestAnim) { |
| 7720 | requestAnimationLocked(0); |
| 7721 | } |
| 7722 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | } |
| 7724 | |
| 7725 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7726 | return hideLw(doAnimation, true); |
| 7727 | } |
| 7728 | |
| 7729 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7730 | if (doAnimation) { |
| 7731 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7732 | doAnimation = false; |
| 7733 | } |
| 7734 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7736 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7737 | if (!current) { |
| 7738 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7739 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7740 | if (doAnimation) { |
| 7741 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7742 | if (mAnimation == null) { |
| 7743 | doAnimation = false; |
| 7744 | } |
| 7745 | } |
| 7746 | if (doAnimation) { |
| 7747 | mPolicyVisibilityAfterAnim = false; |
| 7748 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7749 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7750 | mPolicyVisibilityAfterAnim = false; |
| 7751 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7752 | // Window is no longer visible -- make sure if we were waiting |
| 7753 | // for it to be displayed before enabling the display, that |
| 7754 | // we allow the display to be enabled now. |
| 7755 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7756 | if (mCurrentFocus == this) { |
| 7757 | mFocusMayChange = true; |
| 7758 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7759 | } |
| 7760 | if (requestAnim) { |
| 7761 | requestAnimationLocked(0); |
| 7762 | } |
| 7763 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7767 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7768 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7769 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7770 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7771 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7772 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7773 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7774 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7775 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7776 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7777 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7778 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7779 | } |
| 7780 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7781 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7782 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7783 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7784 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7785 | pw.print("="); pw.print(mAnimLayer); |
| 7786 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7787 | if (mSurface != null) { |
| 7788 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7789 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7790 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7791 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7792 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7793 | pw.print(","); pw.print(mSurfaceY); |
| 7794 | pw.print(") "); pw.print(mSurfaceW); |
| 7795 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7796 | } |
| 7797 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7798 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7799 | if (mAppToken != null) { |
| 7800 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7801 | } |
| 7802 | if (mTargetAppToken != null) { |
| 7803 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7804 | } |
| 7805 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7806 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7807 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7808 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7809 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7810 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7811 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7812 | pw.print(mPolicyVisibility); |
| 7813 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7814 | pw.print(mPolicyVisibilityAfterAnim); |
| 7815 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7816 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7817 | if (!mRelayoutCalled) { |
| 7818 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7819 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7820 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7821 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7822 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7823 | if (mXOffset != 0 || mYOffset != 0) { |
| 7824 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7825 | pw.print(" y="); pw.println(mYOffset); |
| 7826 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7827 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7828 | mGivenContentInsets.printShortString(pw); |
| 7829 | pw.print(" mGivenVisibleInsets="); |
| 7830 | mGivenVisibleInsets.printShortString(pw); |
| 7831 | pw.println(); |
| 7832 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7833 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7834 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7835 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7836 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7837 | pw.print(prefix); pw.print("mShownFrame="); |
| 7838 | mShownFrame.printShortString(pw); |
| 7839 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7840 | pw.println(); |
| 7841 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7842 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7843 | pw.println(); |
| 7844 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7845 | mContainingFrame.printShortString(pw); |
| 7846 | pw.print(" mDisplayFrame="); |
| 7847 | mDisplayFrame.printShortString(pw); |
| 7848 | pw.println(); |
| 7849 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7850 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7851 | pw.println(); |
| 7852 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7853 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7854 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7855 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7856 | pw.println(); |
| 7857 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7858 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7859 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7860 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7861 | } |
| 7862 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7863 | || mAnimation != null) { |
| 7864 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7865 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7866 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7867 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7868 | } |
| 7869 | if (mHasTransformation || mHasLocalTransformation) { |
| 7870 | pw.print(prefix); pw.print("XForm: has="); |
| 7871 | pw.print(mHasTransformation); |
| 7872 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7873 | pw.print(" "); mTransformation.printShortString(pw); |
| 7874 | pw.println(); |
| 7875 | } |
| 7876 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7877 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7878 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7879 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7880 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7881 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7882 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7883 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7884 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7885 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7886 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7887 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7888 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7889 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7890 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7891 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7892 | if (mHScale != 1 || mVScale != 1) { |
| 7893 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7894 | pw.print(" mVScale="); pw.println(mVScale); |
| 7895 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7896 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7897 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7898 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7899 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7900 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7901 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7902 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7903 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7904 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7905 | |
| 7906 | String makeInputChannelName() { |
| 7907 | return Integer.toHexString(System.identityHashCode(this)) |
| 7908 | + " " + mAttrs.getTitle(); |
| 7909 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7910 | |
| 7911 | @Override |
| 7912 | public String toString() { |
| 7913 | return "Window{" |
| 7914 | + Integer.toHexString(System.identityHashCode(this)) |
| 7915 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7916 | } |
| 7917 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7919 | // ------------------------------------------------------------- |
| 7920 | // Window Token State |
| 7921 | // ------------------------------------------------------------- |
| 7922 | |
| 7923 | class WindowToken { |
| 7924 | // The actual token. |
| 7925 | final IBinder token; |
| 7926 | |
| 7927 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7928 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7930 | // Set if this token was explicitly added by a client, so should |
| 7931 | // not be removed when all windows are removed. |
| 7932 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7933 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7934 | // For printing. |
| 7935 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7937 | // If this is an AppWindowToken, this is non-null. |
| 7938 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7940 | // All of the windows associated with this token. |
| 7941 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7942 | |
| 7943 | // Is key dispatching paused for this token? |
| 7944 | boolean paused = false; |
| 7945 | |
| 7946 | // Should this token's windows be hidden? |
| 7947 | boolean hidden; |
| 7948 | |
| 7949 | // Temporary for finding which tokens no longer have visible windows. |
| 7950 | boolean hasVisible; |
| 7951 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7952 | // Set to true when this token is in a pending transaction where it |
| 7953 | // will be shown. |
| 7954 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7955 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7956 | // Set to true when this token is in a pending transaction where it |
| 7957 | // will be hidden. |
| 7958 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7959 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7960 | // Set to true when this token is in a pending transaction where its |
| 7961 | // windows will be put to the bottom of the list. |
| 7962 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7963 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7964 | // Set to true when this token is in a pending transaction where its |
| 7965 | // windows will be put to the top of the list. |
| 7966 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7968 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7969 | token = _token; |
| 7970 | windowType = type; |
| 7971 | explicit = _explicit; |
| 7972 | } |
| 7973 | |
| 7974 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7975 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7976 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7977 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7978 | pw.print(" hidden="); pw.print(hidden); |
| 7979 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7980 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7981 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7982 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7983 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7984 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7985 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7986 | } |
| 7987 | |
| 7988 | @Override |
| 7989 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7990 | if (stringName == null) { |
| 7991 | StringBuilder sb = new StringBuilder(); |
| 7992 | sb.append("WindowToken{"); |
| 7993 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7994 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7995 | stringName = sb.toString(); |
| 7996 | } |
| 7997 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7998 | } |
| 7999 | }; |
| 8000 | |
| 8001 | class AppWindowToken extends WindowToken { |
| 8002 | // Non-null only for application tokens. |
| 8003 | final IApplicationToken appToken; |
| 8004 | |
| 8005 | // All of the windows and child windows that are included in this |
| 8006 | // application token. Note this list is NOT sorted! |
| 8007 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8008 | |
| 8009 | int groupId = -1; |
| 8010 | boolean appFullscreen; |
| 8011 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8012 | |
| 8013 | // The input dispatching timeout for this application token in nanoseconds. |
| 8014 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8016 | // These are used for determining when all windows associated with |
| 8017 | // an activity have been drawn, so they can be made visible together |
| 8018 | // at the same time. |
| 8019 | int lastTransactionSequence = mTransactionSequence-1; |
| 8020 | int numInterestingWindows; |
| 8021 | int numDrawnWindows; |
| 8022 | boolean inPendingTransaction; |
| 8023 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8025 | // Is this token going to be hidden in a little while? If so, it |
| 8026 | // won't be taken into account for setting the screen orientation. |
| 8027 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8029 | // Is this window's surface needed? This is almost like hidden, except |
| 8030 | // it will sometimes be true a little earlier: when the token has |
| 8031 | // been shown, but is still waiting for its app transition to execute |
| 8032 | // before making its windows shown. |
| 8033 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8035 | // Have we told the window clients to hide themselves? |
| 8036 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | // Last visibility state we reported to the app token. |
| 8039 | boolean reportedVisible; |
| 8040 | |
| 8041 | // Set to true when the token has been removed from the window mgr. |
| 8042 | boolean removed; |
| 8043 | |
| 8044 | // Have we been asked to have this token keep the screen frozen? |
| 8045 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8047 | boolean animating; |
| 8048 | Animation animation; |
| 8049 | boolean hasTransformation; |
| 8050 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8052 | // Offset to the window of all layers in the token, for use by |
| 8053 | // AppWindowToken animations. |
| 8054 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8056 | // Information about an application starting window if displayed. |
| 8057 | StartingData startingData; |
| 8058 | WindowState startingWindow; |
| 8059 | View startingView; |
| 8060 | boolean startingDisplayed; |
| 8061 | boolean startingMoved; |
| 8062 | boolean firstWindowDrawn; |
| 8063 | |
| 8064 | AppWindowToken(IApplicationToken _token) { |
| 8065 | super(_token.asBinder(), |
| 8066 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8067 | appWindowToken = this; |
| 8068 | appToken = _token; |
| 8069 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8071 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8072 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8073 | TAG, "Setting animation in " + this + ": " + anim); |
| 8074 | animation = anim; |
| 8075 | animating = false; |
| 8076 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8077 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8078 | int zorder = anim.getZAdjustment(); |
| 8079 | int adj = 0; |
| 8080 | if (zorder == Animation.ZORDER_TOP) { |
| 8081 | adj = TYPE_LAYER_OFFSET; |
| 8082 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8083 | adj = -TYPE_LAYER_OFFSET; |
| 8084 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8086 | if (animLayerAdjustment != adj) { |
| 8087 | animLayerAdjustment = adj; |
| 8088 | updateLayers(); |
| 8089 | } |
| 8090 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8092 | public void setDummyAnimation() { |
| 8093 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8094 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8095 | TAG, "Setting dummy animation in " + this); |
| 8096 | animation = sDummyAnimation; |
| 8097 | } |
| 8098 | } |
| 8099 | |
| 8100 | public void clearAnimation() { |
| 8101 | if (animation != null) { |
| 8102 | animation = null; |
| 8103 | animating = true; |
| 8104 | } |
| 8105 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8107 | void updateLayers() { |
| 8108 | final int N = allAppWindows.size(); |
| 8109 | final int adj = animLayerAdjustment; |
| 8110 | for (int i=0; i<N; i++) { |
| 8111 | WindowState w = allAppWindows.get(i); |
| 8112 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8113 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8114 | + w.mAnimLayer); |
| 8115 | if (w == mInputMethodTarget) { |
| 8116 | setInputMethodAnimLayerAdjustment(adj); |
| 8117 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8118 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8119 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8120 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8121 | } |
| 8122 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8124 | void sendAppVisibilityToClients() { |
| 8125 | final int N = allAppWindows.size(); |
| 8126 | for (int i=0; i<N; i++) { |
| 8127 | WindowState win = allAppWindows.get(i); |
| 8128 | if (win == startingWindow && clientHidden) { |
| 8129 | // Don't hide the starting window. |
| 8130 | continue; |
| 8131 | } |
| 8132 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8133 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8135 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8136 | } catch (RemoteException e) { |
| 8137 | } |
| 8138 | } |
| 8139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8141 | void showAllWindowsLocked() { |
| 8142 | final int NW = allAppWindows.size(); |
| 8143 | for (int i=0; i<NW; i++) { |
| 8144 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8145 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8146 | "performing show on: " + w); |
| 8147 | w.performShowLocked(); |
| 8148 | } |
| 8149 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8151 | // This must be called while inside a transaction. |
| 8152 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8153 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8154 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8156 | if (animation == sDummyAnimation) { |
| 8157 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8158 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8159 | // when it is really time to animate, this will be set to |
| 8160 | // a real animation and the next call will execute normally. |
| 8161 | return false; |
| 8162 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8165 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8166 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8167 | TAG, "Starting animation in " + this + |
| 8168 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8169 | + " scale=" + mTransitionAnimationScale |
| 8170 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8171 | animation.initialize(dw, dh, dw, dh); |
| 8172 | animation.setStartTime(currentTime); |
| 8173 | animating = true; |
| 8174 | } |
| 8175 | transformation.clear(); |
| 8176 | final boolean more = animation.getTransformation( |
| 8177 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8178 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8179 | TAG, "Stepped animation in " + this + |
| 8180 | ": more=" + more + ", xform=" + transformation); |
| 8181 | if (more) { |
| 8182 | // we're done! |
| 8183 | hasTransformation = true; |
| 8184 | return true; |
| 8185 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8186 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8187 | TAG, "Finished animation in " + this + |
| 8188 | " @ " + currentTime); |
| 8189 | animation = null; |
| 8190 | } |
| 8191 | } else if (animation != null) { |
| 8192 | // If the display is frozen, and there is a pending animation, |
| 8193 | // clear it and make sure we run the cleanup code. |
| 8194 | animating = true; |
| 8195 | animation = null; |
| 8196 | } |
| 8197 | |
| 8198 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8200 | if (!animating) { |
| 8201 | return false; |
| 8202 | } |
| 8203 | |
| 8204 | clearAnimation(); |
| 8205 | animating = false; |
| 8206 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8207 | moveInputMethodWindowsIfNeededLocked(true); |
| 8208 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8209 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8210 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8211 | TAG, "Animation done in " + this |
| 8212 | + ": reportedVisible=" + reportedVisible); |
| 8213 | |
| 8214 | transformation.clear(); |
| 8215 | if (animLayerAdjustment != 0) { |
| 8216 | animLayerAdjustment = 0; |
| 8217 | updateLayers(); |
| 8218 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8220 | final int N = windows.size(); |
| 8221 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8222 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8223 | } |
| 8224 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8226 | return false; |
| 8227 | } |
| 8228 | |
| 8229 | void updateReportedVisibilityLocked() { |
| 8230 | if (appToken == null) { |
| 8231 | return; |
| 8232 | } |
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 | int numInteresting = 0; |
| 8235 | int numVisible = 0; |
| 8236 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8237 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8238 | 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] | 8239 | final int N = allAppWindows.size(); |
| 8240 | for (int i=0; i<N; i++) { |
| 8241 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8242 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8243 | || win.mViewVisibility != View.VISIBLE |
Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8244 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8245 | || win.mDestroying) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8246 | continue; |
| 8247 | } |
| 8248 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8249 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8250 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8251 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8252 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8253 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8254 | + " pv=" + win.mPolicyVisibility |
| 8255 | + " dp=" + win.mDrawPending |
| 8256 | + " cdp=" + win.mCommitDrawPending |
| 8257 | + " ah=" + win.mAttachedHidden |
| 8258 | + " th=" |
| 8259 | + (win.mAppToken != null |
| 8260 | ? win.mAppToken.hiddenRequested : false) |
| 8261 | + " a=" + win.mAnimating); |
| 8262 | } |
| 8263 | } |
| 8264 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8265 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8266 | if (!win.isAnimating()) { |
| 8267 | numVisible++; |
| 8268 | } |
| 8269 | nowGone = false; |
| 8270 | } else if (win.isAnimating()) { |
| 8271 | nowGone = false; |
| 8272 | } |
| 8273 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8275 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8276 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8277 | + numInteresting + " visible=" + numVisible); |
| 8278 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8279 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8280 | TAG, "Visibility changed in " + this |
| 8281 | + ": vis=" + nowVisible); |
| 8282 | reportedVisible = nowVisible; |
| 8283 | Message m = mH.obtainMessage( |
| 8284 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8285 | nowVisible ? 1 : 0, |
| 8286 | nowGone ? 1 : 0, |
| 8287 | this); |
| 8288 | mH.sendMessage(m); |
| 8289 | } |
| 8290 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8291 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8292 | WindowState findMainWindow() { |
| 8293 | int j = windows.size(); |
| 8294 | while (j > 0) { |
| 8295 | j--; |
| 8296 | WindowState win = windows.get(j); |
| 8297 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8298 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8299 | return win; |
| 8300 | } |
| 8301 | } |
| 8302 | return null; |
| 8303 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8305 | void dump(PrintWriter pw, String prefix) { |
| 8306 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8307 | if (appToken != null) { |
| 8308 | pw.print(prefix); pw.println("app=true"); |
| 8309 | } |
| 8310 | if (allAppWindows.size() > 0) { |
| 8311 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8312 | } |
| 8313 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8314 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8315 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8316 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8317 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8318 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8319 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8320 | if (paused || freezingScreen) { |
| 8321 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8322 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8323 | } |
| 8324 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8325 | || inPendingTransaction || allDrawn) { |
| 8326 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8327 | pw.print(numInterestingWindows); |
| 8328 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8329 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8330 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8331 | } |
| 8332 | if (animating || animation != null) { |
| 8333 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8334 | pw.print(" animation="); pw.println(animation); |
| 8335 | } |
| 8336 | if (animLayerAdjustment != 0) { |
| 8337 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8338 | } |
| 8339 | if (hasTransformation) { |
| 8340 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8341 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8342 | pw.println(); |
| 8343 | } |
| 8344 | if (startingData != null || removed || firstWindowDrawn) { |
| 8345 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8346 | pw.print(" removed="); pw.print(removed); |
| 8347 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8348 | } |
| 8349 | if (startingWindow != null || startingView != null |
| 8350 | || startingDisplayed || startingMoved) { |
| 8351 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8352 | pw.print(" startingView="); pw.print(startingView); |
| 8353 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8354 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8355 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8356 | } |
| 8357 | |
| 8358 | @Override |
| 8359 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8360 | if (stringName == null) { |
| 8361 | StringBuilder sb = new StringBuilder(); |
| 8362 | sb.append("AppWindowToken{"); |
| 8363 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8364 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8365 | stringName = sb.toString(); |
| 8366 | } |
| 8367 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8368 | } |
| 8369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8371 | // ------------------------------------------------------------- |
| 8372 | // DummyAnimation |
| 8373 | // ------------------------------------------------------------- |
| 8374 | |
| 8375 | // This is an animation that does nothing: it just immediately finishes |
| 8376 | // itself every time it is called. It is used as a stub animation in cases |
| 8377 | // where we want to synchronize multiple things that may be animating. |
| 8378 | static final class DummyAnimation extends Animation { |
| 8379 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8380 | return false; |
| 8381 | } |
| 8382 | } |
| 8383 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8385 | // ------------------------------------------------------------- |
| 8386 | // Async Handler |
| 8387 | // ------------------------------------------------------------- |
| 8388 | |
| 8389 | static final class StartingData { |
| 8390 | final String pkg; |
| 8391 | final int theme; |
| 8392 | final CharSequence nonLocalizedLabel; |
| 8393 | final int labelRes; |
| 8394 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8396 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8397 | int _labelRes, int _icon) { |
| 8398 | pkg = _pkg; |
| 8399 | theme = _theme; |
| 8400 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8401 | labelRes = _labelRes; |
| 8402 | icon = _icon; |
| 8403 | } |
| 8404 | } |
| 8405 | |
| 8406 | private final class H extends Handler { |
| 8407 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8408 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8409 | public static final int ANIMATE = 4; |
| 8410 | public static final int ADD_STARTING = 5; |
| 8411 | public static final int REMOVE_STARTING = 6; |
| 8412 | public static final int FINISHED_STARTING = 7; |
| 8413 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8414 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8415 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8416 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8417 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8418 | public static final int FORCE_GC = 15; |
| 8419 | public static final int ENABLE_SCREEN = 16; |
| 8420 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8421 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8422 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8423 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8424 | public static final int DRAG_END_TIMEOUT = 21; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8426 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8428 | public H() { |
| 8429 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8431 | @Override |
| 8432 | public void handleMessage(Message msg) { |
| 8433 | switch (msg.what) { |
| 8434 | case REPORT_FOCUS_CHANGE: { |
| 8435 | WindowState lastFocus; |
| 8436 | WindowState newFocus; |
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 | synchronized(mWindowMap) { |
| 8439 | lastFocus = mLastFocus; |
| 8440 | newFocus = mCurrentFocus; |
| 8441 | if (lastFocus == newFocus) { |
| 8442 | // Focus is not changing, so nothing to do. |
| 8443 | return; |
| 8444 | } |
| 8445 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8446 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8447 | // + " to " + newFocus); |
| 8448 | if (newFocus != null && lastFocus != null |
| 8449 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8450 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8451 | mLosingFocus.add(lastFocus); |
| 8452 | lastFocus = null; |
| 8453 | } |
| 8454 | } |
| 8455 | |
| 8456 | if (lastFocus != newFocus) { |
| 8457 | //System.out.println("Changing focus from " + lastFocus |
| 8458 | // + " to " + newFocus); |
| 8459 | if (newFocus != null) { |
| 8460 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8461 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8462 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8463 | } catch (RemoteException e) { |
| 8464 | // Ignore if process has died. |
| 8465 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8466 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8467 | } |
| 8468 | |
| 8469 | if (lastFocus != null) { |
| 8470 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8471 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8472 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8473 | } catch (RemoteException e) { |
| 8474 | // Ignore if process has died. |
| 8475 | } |
| 8476 | } |
| 8477 | } |
| 8478 | } break; |
| 8479 | |
| 8480 | case REPORT_LOSING_FOCUS: { |
| 8481 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8483 | synchronized(mWindowMap) { |
| 8484 | losers = mLosingFocus; |
| 8485 | mLosingFocus = new ArrayList<WindowState>(); |
| 8486 | } |
| 8487 | |
| 8488 | final int N = losers.size(); |
| 8489 | for (int i=0; i<N; i++) { |
| 8490 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8491 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8492 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8493 | } catch (RemoteException e) { |
| 8494 | // Ignore if process has died. |
| 8495 | } |
| 8496 | } |
| 8497 | } break; |
| 8498 | |
| 8499 | case ANIMATE: { |
| 8500 | synchronized(mWindowMap) { |
| 8501 | mAnimationPending = false; |
| 8502 | performLayoutAndPlaceSurfacesLocked(); |
| 8503 | } |
| 8504 | } break; |
| 8505 | |
| 8506 | case ADD_STARTING: { |
| 8507 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8508 | final StartingData sd = wtoken.startingData; |
| 8509 | |
| 8510 | if (sd == null) { |
| 8511 | // Animation has been canceled... do nothing. |
| 8512 | return; |
| 8513 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8514 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8515 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8516 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8518 | View view = null; |
| 8519 | try { |
| 8520 | view = mPolicy.addStartingWindow( |
| 8521 | wtoken.token, sd.pkg, |
| 8522 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8523 | sd.icon); |
| 8524 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8525 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8526 | } |
| 8527 | |
| 8528 | if (view != null) { |
| 8529 | boolean abort = false; |
| 8530 | |
| 8531 | synchronized(mWindowMap) { |
| 8532 | if (wtoken.removed || wtoken.startingData == null) { |
| 8533 | // If the window was successfully added, then |
| 8534 | // we need to remove it. |
| 8535 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8536 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8537 | "Aborted starting " + wtoken |
| 8538 | + ": removed=" + wtoken.removed |
| 8539 | + " startingData=" + wtoken.startingData); |
| 8540 | wtoken.startingWindow = null; |
| 8541 | wtoken.startingData = null; |
| 8542 | abort = true; |
| 8543 | } |
| 8544 | } else { |
| 8545 | wtoken.startingView = view; |
| 8546 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8547 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8548 | "Added starting " + wtoken |
| 8549 | + ": startingWindow=" |
| 8550 | + wtoken.startingWindow + " startingView=" |
| 8551 | + wtoken.startingView); |
| 8552 | } |
| 8553 | |
| 8554 | if (abort) { |
| 8555 | try { |
| 8556 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8557 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8558 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8559 | } |
| 8560 | } |
| 8561 | } |
| 8562 | } break; |
| 8563 | |
| 8564 | case REMOVE_STARTING: { |
| 8565 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8566 | IBinder token = null; |
| 8567 | View view = null; |
| 8568 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8569 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8570 | + wtoken + ": startingWindow=" |
| 8571 | + wtoken.startingWindow + " startingView=" |
| 8572 | + wtoken.startingView); |
| 8573 | if (wtoken.startingWindow != null) { |
| 8574 | view = wtoken.startingView; |
| 8575 | token = wtoken.token; |
| 8576 | wtoken.startingData = null; |
| 8577 | wtoken.startingView = null; |
| 8578 | wtoken.startingWindow = null; |
| 8579 | } |
| 8580 | } |
| 8581 | if (view != null) { |
| 8582 | try { |
| 8583 | mPolicy.removeStartingWindow(token, view); |
| 8584 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8585 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8586 | } |
| 8587 | } |
| 8588 | } break; |
| 8589 | |
| 8590 | case FINISHED_STARTING: { |
| 8591 | IBinder token = null; |
| 8592 | View view = null; |
| 8593 | while (true) { |
| 8594 | synchronized (mWindowMap) { |
| 8595 | final int N = mFinishedStarting.size(); |
| 8596 | if (N <= 0) { |
| 8597 | break; |
| 8598 | } |
| 8599 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8600 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8601 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8602 | "Finished starting " + wtoken |
| 8603 | + ": startingWindow=" + wtoken.startingWindow |
| 8604 | + " startingView=" + wtoken.startingView); |
| 8605 | |
| 8606 | if (wtoken.startingWindow == null) { |
| 8607 | continue; |
| 8608 | } |
| 8609 | |
| 8610 | view = wtoken.startingView; |
| 8611 | token = wtoken.token; |
| 8612 | wtoken.startingData = null; |
| 8613 | wtoken.startingView = null; |
| 8614 | wtoken.startingWindow = null; |
| 8615 | } |
| 8616 | |
| 8617 | try { |
| 8618 | mPolicy.removeStartingWindow(token, view); |
| 8619 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8620 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8621 | } |
| 8622 | } |
| 8623 | } break; |
| 8624 | |
| 8625 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8626 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8627 | |
| 8628 | boolean nowVisible = msg.arg1 != 0; |
| 8629 | boolean nowGone = msg.arg2 != 0; |
| 8630 | |
| 8631 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8632 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8633 | TAG, "Reporting visible in " + wtoken |
| 8634 | + " visible=" + nowVisible |
| 8635 | + " gone=" + nowGone); |
| 8636 | if (nowVisible) { |
| 8637 | wtoken.appToken.windowsVisible(); |
| 8638 | } else { |
| 8639 | wtoken.appToken.windowsGone(); |
| 8640 | } |
| 8641 | } catch (RemoteException ex) { |
| 8642 | } |
| 8643 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | case WINDOW_FREEZE_TIMEOUT: { |
| 8646 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8647 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8648 | int i = mWindows.size(); |
| 8649 | while (i > 0) { |
| 8650 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8651 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8652 | if (w.mOrientationChanging) { |
| 8653 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8654 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8655 | } |
| 8656 | } |
| 8657 | performLayoutAndPlaceSurfacesLocked(); |
| 8658 | } |
| 8659 | break; |
| 8660 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8662 | case HOLD_SCREEN_CHANGED: { |
| 8663 | Session oldHold; |
| 8664 | Session newHold; |
| 8665 | synchronized (mWindowMap) { |
| 8666 | oldHold = mLastReportedHold; |
| 8667 | newHold = (Session)msg.obj; |
| 8668 | mLastReportedHold = newHold; |
| 8669 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8671 | if (oldHold != newHold) { |
| 8672 | try { |
| 8673 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8674 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8675 | "window", |
| 8676 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8677 | } |
| 8678 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8679 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8680 | "window", |
| 8681 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8682 | } |
| 8683 | } catch (RemoteException e) { |
| 8684 | } |
| 8685 | } |
| 8686 | break; |
| 8687 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8689 | case APP_TRANSITION_TIMEOUT: { |
| 8690 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8691 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8692 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8693 | "*** APP TRANSITION TIMEOUT"); |
| 8694 | mAppTransitionReady = true; |
| 8695 | mAppTransitionTimeout = true; |
| 8696 | performLayoutAndPlaceSurfacesLocked(); |
| 8697 | } |
| 8698 | } |
| 8699 | break; |
| 8700 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8702 | case PERSIST_ANIMATION_SCALE: { |
| 8703 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8704 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8705 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8706 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8707 | break; |
| 8708 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8710 | case FORCE_GC: { |
| 8711 | synchronized(mWindowMap) { |
| 8712 | if (mAnimationPending) { |
| 8713 | // If we are animating, don't do the gc now but |
| 8714 | // delay a bit so we don't interrupt the animation. |
| 8715 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8716 | 2000); |
| 8717 | return; |
| 8718 | } |
| 8719 | // If we are currently rotating the display, it will |
| 8720 | // schedule a new message when done. |
| 8721 | if (mDisplayFrozen) { |
| 8722 | return; |
| 8723 | } |
| 8724 | mFreezeGcPending = 0; |
| 8725 | } |
| 8726 | Runtime.getRuntime().gc(); |
| 8727 | break; |
| 8728 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8730 | case ENABLE_SCREEN: { |
| 8731 | performEnableScreen(); |
| 8732 | break; |
| 8733 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8735 | case APP_FREEZE_TIMEOUT: { |
| 8736 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8737 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8738 | int i = mAppTokens.size(); |
| 8739 | while (i > 0) { |
| 8740 | i--; |
| 8741 | AppWindowToken tok = mAppTokens.get(i); |
| 8742 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8743 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8744 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8745 | } |
| 8746 | } |
| 8747 | } |
| 8748 | break; |
| 8749 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8750 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8751 | case SEND_NEW_CONFIGURATION: { |
| 8752 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8753 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8754 | break; |
| 8755 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8756 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8757 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8758 | if (mWindowsChanged) { |
| 8759 | synchronized (mWindowMap) { |
| 8760 | mWindowsChanged = false; |
| 8761 | } |
| 8762 | notifyWindowsChanged(); |
| 8763 | } |
| 8764 | break; |
| 8765 | } |
| 8766 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8767 | case DRAG_START_TIMEOUT: { |
| 8768 | IBinder win = (IBinder)msg.obj; |
| 8769 | if (DEBUG_DRAG) { |
| 8770 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 8771 | } |
| 8772 | synchronized (mWindowMap) { |
| 8773 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 8774 | if (mDragState != null) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8775 | mDragState.unregister(); |
| 8776 | mInputMonitor.updateInputWindowsLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8777 | mDragState.reset(); |
| 8778 | mDragState = null; |
| 8779 | } |
| 8780 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8781 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8782 | } |
| 8783 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8784 | case DRAG_END_TIMEOUT: { |
| 8785 | IBinder win = (IBinder)msg.obj; |
| 8786 | if (DEBUG_DRAG) { |
| 8787 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 8788 | } |
| 8789 | synchronized (mWindowMap) { |
| 8790 | // !!! TODO: ANR the drag-receiving app |
| 8791 | mDragState.mDragResult = false; |
| 8792 | mDragState.endDragLw(); |
| 8793 | } |
| 8794 | break; |
| 8795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8796 | } |
| 8797 | } |
| 8798 | } |
| 8799 | |
| 8800 | // ------------------------------------------------------------- |
| 8801 | // IWindowManager API |
| 8802 | // ------------------------------------------------------------- |
| 8803 | |
| 8804 | public IWindowSession openSession(IInputMethodClient client, |
| 8805 | IInputContext inputContext) { |
| 8806 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8807 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8808 | Session session = new Session(client, inputContext); |
| 8809 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8810 | } |
| 8811 | |
| 8812 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8813 | synchronized (mWindowMap) { |
| 8814 | // The focus for the client is the window immediately below |
| 8815 | // where we would place the input method window. |
| 8816 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8817 | WindowState imFocus; |
| 8818 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8819 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8820 | if (imFocus != null) { |
| 8821 | if (imFocus.mSession.mClient != null && |
| 8822 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8823 | return true; |
| 8824 | } |
| 8825 | } |
| 8826 | } |
| 8827 | } |
| 8828 | return false; |
| 8829 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8831 | // ------------------------------------------------------------- |
| 8832 | // Internals |
| 8833 | // ------------------------------------------------------------- |
| 8834 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8835 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8836 | boolean throwOnError) { |
| 8837 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8838 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8839 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8840 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8841 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8842 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8843 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8844 | TAG, "Looking up client " + client + ": " + win); |
| 8845 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8846 | RuntimeException ex = new IllegalArgumentException( |
| 8847 | "Requested window " + client + " does not exist"); |
| 8848 | if (throwOnError) { |
| 8849 | throw ex; |
| 8850 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8851 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8852 | return null; |
| 8853 | } |
| 8854 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8855 | RuntimeException ex = new IllegalArgumentException( |
| 8856 | "Requested window " + client + " is in session " + |
| 8857 | win.mSession + ", not " + session); |
| 8858 | if (throwOnError) { |
| 8859 | throw ex; |
| 8860 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8861 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8862 | return null; |
| 8863 | } |
| 8864 | |
| 8865 | return win; |
| 8866 | } |
| 8867 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8868 | final void rebuildAppWindowListLocked() { |
| 8869 | int NW = mWindows.size(); |
| 8870 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8871 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8872 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8873 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8874 | // First remove all existing app windows. |
| 8875 | i=0; |
| 8876 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8877 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8878 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8879 | WindowState win = mWindows.remove(i); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8880 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8881 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8882 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8883 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8884 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8885 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8886 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8887 | && lastWallpaper == i-1) { |
| 8888 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8889 | } |
| 8890 | i++; |
| 8891 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8892 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8893 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8894 | // so skip them before adding app tokens. |
| 8895 | lastWallpaper++; |
| 8896 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8897 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8898 | // First add all of the exiting app tokens... these are no longer |
| 8899 | // in the main app list, but still have windows shown. We put them |
| 8900 | // in the back because now that the animation is over we no longer |
| 8901 | // will care about them. |
| 8902 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8903 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8904 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8905 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8906 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8907 | // And add in the still active app tokens in Z order. |
| 8908 | NT = mAppTokens.size(); |
| 8909 | for (int j=0; j<NT; j++) { |
| 8910 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8911 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8912 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8913 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8914 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8915 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8916 | + " windows but added " + i); |
| 8917 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8918 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8920 | private final void assignLayersLocked() { |
| 8921 | int N = mWindows.size(); |
| 8922 | int curBaseLayer = 0; |
| 8923 | int curLayer = 0; |
| 8924 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8926 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8927 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8928 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8929 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8930 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8931 | w.mLayer = curLayer; |
| 8932 | } else { |
| 8933 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8934 | w.mLayer = curLayer; |
| 8935 | } |
| 8936 | if (w.mTargetAppToken != null) { |
| 8937 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8938 | } else if (w.mAppToken != null) { |
| 8939 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8940 | } else { |
| 8941 | w.mAnimLayer = w.mLayer; |
| 8942 | } |
| 8943 | if (w.mIsImWindow) { |
| 8944 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8945 | } else if (w.mIsWallpaper) { |
| 8946 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8947 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8948 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8949 | + w.mAnimLayer); |
| 8950 | //System.out.println( |
| 8951 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8952 | } |
| 8953 | } |
| 8954 | |
| 8955 | private boolean mInLayout = false; |
| 8956 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8957 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8958 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8959 | throw new RuntimeException("Recursive call!"); |
| 8960 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8961 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8962 | return; |
| 8963 | } |
| 8964 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8965 | if (mWaitingForConfig) { |
| 8966 | // Our configuration has changed (most likely rotation), but we |
| 8967 | // don't yet have the complete configuration to report to |
| 8968 | // applications. Don't do any window layout until we have it. |
| 8969 | return; |
| 8970 | } |
| 8971 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8972 | if (mDisplay == null) { |
| 8973 | // Not yet initialized, nothing to do. |
| 8974 | return; |
| 8975 | } |
| 8976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8977 | boolean recoveringMemory = false; |
| 8978 | if (mForceRemoves != null) { |
| 8979 | recoveringMemory = true; |
| 8980 | // Wait a little it for things to settle down, and off we go. |
| 8981 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8982 | WindowState ws = mForceRemoves.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8983 | Slog.i(TAG, "Force removing: " + ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8984 | removeWindowInnerLocked(ws.mSession, ws); |
| 8985 | } |
| 8986 | mForceRemoves = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8987 | 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] | 8988 | Object tmp = new Object(); |
| 8989 | synchronized (tmp) { |
| 8990 | try { |
| 8991 | tmp.wait(250); |
| 8992 | } catch (InterruptedException e) { |
| 8993 | } |
| 8994 | } |
| 8995 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8997 | mInLayout = true; |
| 8998 | try { |
| 8999 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9001 | int i = mPendingRemove.size()-1; |
| 9002 | if (i >= 0) { |
| 9003 | while (i >= 0) { |
| 9004 | WindowState w = mPendingRemove.get(i); |
| 9005 | removeWindowInnerLocked(w.mSession, w); |
| 9006 | i--; |
| 9007 | } |
| 9008 | mPendingRemove.clear(); |
| 9009 | |
| 9010 | mInLayout = false; |
| 9011 | assignLayersLocked(); |
| 9012 | mLayoutNeeded = true; |
| 9013 | performLayoutAndPlaceSurfacesLocked(); |
| 9014 | |
| 9015 | } else { |
| 9016 | mInLayout = false; |
| 9017 | if (mLayoutNeeded) { |
| 9018 | requestAnimationLocked(0); |
| 9019 | } |
| 9020 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9021 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9022 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 9023 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9024 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9025 | } catch (RuntimeException e) { |
| 9026 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9027 | 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] | 9028 | } |
| 9029 | } |
| 9030 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9031 | private final int performLayoutLockedInner() { |
| 9032 | if (!mLayoutNeeded) { |
| 9033 | return 0; |
| 9034 | } |
| 9035 | |
| 9036 | mLayoutNeeded = false; |
| 9037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9038 | final int dw = mDisplay.getWidth(); |
| 9039 | final int dh = mDisplay.getHeight(); |
| 9040 | |
| 9041 | final int N = mWindows.size(); |
| 9042 | int i; |
| 9043 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9044 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9045 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9046 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9047 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9048 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9049 | int seq = mLayoutSeq+1; |
| 9050 | if (seq < 0) seq = 0; |
| 9051 | mLayoutSeq = seq; |
| 9052 | |
| 9053 | // First perform layout of any root windows (not attached |
| 9054 | // to another window). |
| 9055 | int topAttached = -1; |
| 9056 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9057 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9058 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9059 | // Don't do layout of a window if it is not visible, or |
| 9060 | // soon won't be visible, to avoid wasting time and funky |
| 9061 | // changes while a window is animating away. |
| 9062 | final AppWindowToken atoken = win.mAppToken; |
| 9063 | final boolean gone = win.mViewVisibility == View.GONE |
| 9064 | || !win.mRelayoutCalled |
| 9065 | || win.mRootToken.hidden |
| 9066 | || (atoken != null && atoken.hiddenRequested) |
| 9067 | || win.mAttachedHidden |
| 9068 | || win.mExiting || win.mDestroying; |
| 9069 | |
| 9070 | if (!win.mLayoutAttached) { |
| 9071 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 9072 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9073 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9074 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 9075 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9076 | + win.mRelayoutCalled + " hidden=" |
| 9077 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9078 | + (atoken != null && atoken.hiddenRequested) |
| 9079 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9080 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9081 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9082 | // If this view is GONE, then skip it -- keep the current |
| 9083 | // frame, and let the caller know so they can ignore it |
| 9084 | // if they want. (We do the normal layout for INVISIBLE |
| 9085 | // windows, since that means "perform layout as normal, |
| 9086 | // just don't display"). |
| 9087 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9088 | if (!win.mLayoutAttached) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9089 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9090 | win.mLayoutSeq = seq; |
| 9091 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9092 | + win.mFrame + " mContainingFrame=" |
| 9093 | + win.mContainingFrame + " mDisplayFrame=" |
| 9094 | + win.mDisplayFrame); |
| 9095 | } else { |
| 9096 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9097 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9098 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9099 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9100 | |
| 9101 | // Now perform layout of attached windows, which usually |
| 9102 | // depend on the position of the window they are attached to. |
| 9103 | // XXX does not deal with windows that are attached to windows |
| 9104 | // that are themselves attached. |
| 9105 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9106 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9107 | |
| 9108 | // If this view is GONE, then skip it -- keep the current |
| 9109 | // frame, and let the caller know so they can ignore it |
| 9110 | // if they want. (We do the normal layout for INVISIBLE |
| 9111 | // windows, since that means "perform layout as normal, |
| 9112 | // just don't display"). |
| 9113 | if (win.mLayoutAttached) { |
| 9114 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9115 | + " mHaveFrame=" + win.mHaveFrame |
| 9116 | + " mViewVisibility=" + win.mViewVisibility |
| 9117 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 9118 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9119 | || !win.mHaveFrame) { |
| 9120 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9121 | win.mLayoutSeq = seq; |
| 9122 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9123 | + win.mFrame + " mContainingFrame=" |
| 9124 | + win.mContainingFrame + " mDisplayFrame=" |
| 9125 | + win.mDisplayFrame); |
| 9126 | } |
| 9127 | } |
| 9128 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9129 | |
| 9130 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9131 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9132 | |
| 9133 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9134 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9136 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9137 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9138 | if (mDisplay == null) { |
| 9139 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9140 | return; |
| 9141 | } |
| 9142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9143 | final long currentTime = SystemClock.uptimeMillis(); |
| 9144 | final int dw = mDisplay.getWidth(); |
| 9145 | final int dh = mDisplay.getHeight(); |
| 9146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9147 | int i; |
| 9148 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9149 | if (mFocusMayChange) { |
| 9150 | mFocusMayChange = false; |
| 9151 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9152 | } |
| 9153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9154 | // Initialize state of exiting tokens. |
| 9155 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9156 | mExitingTokens.get(i).hasVisible = false; |
| 9157 | } |
| 9158 | |
| 9159 | // Initialize state of exiting applications. |
| 9160 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9161 | mExitingAppTokens.get(i).hasVisible = false; |
| 9162 | } |
| 9163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9164 | boolean orientationChangeComplete = true; |
| 9165 | Session holdScreen = null; |
| 9166 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9167 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9168 | boolean focusDisplayed = false; |
| 9169 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9170 | boolean createWatermark = false; |
| 9171 | |
| 9172 | if (mFxSession == null) { |
| 9173 | mFxSession = new SurfaceSession(); |
| 9174 | createWatermark = true; |
| 9175 | } |
| 9176 | |
| 9177 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9178 | |
| 9179 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9180 | |
| 9181 | if (createWatermark) { |
| 9182 | createWatermark(); |
| 9183 | } |
| 9184 | if (mWatermark != null) { |
| 9185 | mWatermark.positionSurface(dw, dh); |
| 9186 | } |
| 9187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9188 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9189 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9190 | int repeats = 0; |
| 9191 | int changes = 0; |
| 9192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9193 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9194 | repeats++; |
| 9195 | if (repeats > 6) { |
| 9196 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9197 | mLayoutNeeded = false; |
| 9198 | break; |
| 9199 | } |
| 9200 | |
| 9201 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9202 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9203 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9204 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9205 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9206 | assignLayersLocked(); |
| 9207 | mLayoutNeeded = true; |
| 9208 | } |
| 9209 | } |
| 9210 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9211 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9212 | if (updateOrientationFromAppTokensLocked()) { |
| 9213 | mLayoutNeeded = true; |
| 9214 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9215 | } |
| 9216 | } |
| 9217 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9218 | mLayoutNeeded = true; |
| 9219 | } |
| 9220 | } |
| 9221 | |
| 9222 | // FIRST LOOP: Perform a layout, if needed. |
| 9223 | if (repeats < 4) { |
| 9224 | changes = performLayoutLockedInner(); |
| 9225 | if (changes != 0) { |
| 9226 | continue; |
| 9227 | } |
| 9228 | } else { |
| 9229 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9230 | changes = 0; |
| 9231 | } |
| 9232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9233 | final int transactionSequence = ++mTransactionSequence; |
| 9234 | |
| 9235 | // Update animations of all applications, including those |
| 9236 | // associated with exiting/removed apps |
| 9237 | boolean tokensAnimating = false; |
| 9238 | final int NAT = mAppTokens.size(); |
| 9239 | for (i=0; i<NAT; i++) { |
| 9240 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9241 | tokensAnimating = true; |
| 9242 | } |
| 9243 | } |
| 9244 | final int NEAT = mExitingAppTokens.size(); |
| 9245 | for (i=0; i<NEAT; i++) { |
| 9246 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9247 | tokensAnimating = true; |
| 9248 | } |
| 9249 | } |
| 9250 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9251 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9252 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9253 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9254 | + transactionSequence + " tokensAnimating=" |
| 9255 | + tokensAnimating); |
| 9256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9257 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9258 | |
| 9259 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9260 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9261 | boolean forceHiding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9262 | |
| 9263 | mPolicy.beginAnimationLw(dw, dh); |
| 9264 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9265 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9267 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9268 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9269 | |
| 9270 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9271 | |
| 9272 | if (w.mSurface != null) { |
| 9273 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9274 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9275 | if ((w.mAttrs.flags |
| 9276 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9277 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9278 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9279 | wallpaperMayChange = true; |
| 9280 | } |
| 9281 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9282 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9283 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9284 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9285 | animating = true; |
| 9286 | //w.dump(" "); |
| 9287 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9288 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9289 | wallpaperMayChange = true; |
| 9290 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9291 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9292 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9293 | if (!wasAnimating && animating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9294 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9295 | "Animation done that could impact force hide: " |
| 9296 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9297 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9298 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9299 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9300 | forceHiding = true; |
| 9301 | } |
| 9302 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9303 | boolean changed; |
| 9304 | if (forceHiding) { |
| 9305 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9306 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9307 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9308 | } else { |
| 9309 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9310 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9311 | "Now policy shown: " + w); |
| 9312 | if (changed) { |
| 9313 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9314 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9315 | // Assume we will need to animate. If |
| 9316 | // we don't (because the wallpaper will |
| 9317 | // stay with the lock screen), then we will |
| 9318 | // clean up later. |
| 9319 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9320 | if (a != null) { |
| 9321 | w.setAnimation(a); |
| 9322 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9323 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9324 | if (mCurrentFocus == null || |
| 9325 | mCurrentFocus.mLayer < w.mLayer) { |
| 9326 | // We are showing on to of the current |
| 9327 | // focus, so re-evaluate focus to make |
| 9328 | // sure it is correct. |
| 9329 | mFocusMayChange = true; |
| 9330 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9331 | } |
| 9332 | } |
| 9333 | if (changed && (attrs.flags |
| 9334 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9335 | wallpaperMayChange = true; |
| 9336 | } |
| 9337 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9339 | mPolicy.animatingWindowLw(w, attrs); |
| 9340 | } |
| 9341 | |
| 9342 | final AppWindowToken atoken = w.mAppToken; |
| 9343 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9344 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9345 | atoken.lastTransactionSequence = transactionSequence; |
| 9346 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9347 | atoken.startingDisplayed = false; |
| 9348 | } |
| 9349 | if ((w.isOnScreen() || w.mAttrs.type |
| 9350 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9351 | && !w.mExiting && !w.mDestroying) { |
| 9352 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9353 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9354 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9355 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9356 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9357 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9358 | + " pv=" + w.mPolicyVisibility |
| 9359 | + " dp=" + w.mDrawPending |
| 9360 | + " cdp=" + w.mCommitDrawPending |
| 9361 | + " ah=" + w.mAttachedHidden |
| 9362 | + " th=" + atoken.hiddenRequested |
| 9363 | + " a=" + w.mAnimating); |
| 9364 | } |
| 9365 | } |
| 9366 | if (w != atoken.startingWindow) { |
| 9367 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9368 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9369 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9370 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9371 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9372 | "tokenMayBeDrawn: " + atoken |
| 9373 | + " freezingScreen=" + atoken.freezingScreen |
| 9374 | + " mAppFreezing=" + w.mAppFreezing); |
| 9375 | tokenMayBeDrawn = true; |
| 9376 | } |
| 9377 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9378 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9379 | atoken.startingDisplayed = true; |
| 9380 | } |
| 9381 | } |
| 9382 | } else if (w.mReadyToShow) { |
| 9383 | w.performShowLocked(); |
| 9384 | } |
| 9385 | } |
| 9386 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9387 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9388 | |
| 9389 | if (tokenMayBeDrawn) { |
| 9390 | // See if any windows have been drawn, so they (and others |
| 9391 | // associated with them) can now be shown. |
| 9392 | final int NT = mTokenList.size(); |
| 9393 | for (i=0; i<NT; i++) { |
| 9394 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9395 | if (wtoken == null) { |
| 9396 | continue; |
| 9397 | } |
| 9398 | if (wtoken.freezingScreen) { |
| 9399 | int numInteresting = wtoken.numInterestingWindows; |
| 9400 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9401 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9402 | "allDrawn: " + wtoken |
| 9403 | + " interesting=" + numInteresting |
| 9404 | + " drawn=" + wtoken.numDrawnWindows); |
| 9405 | wtoken.showAllWindowsLocked(); |
| 9406 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9407 | orientationChangeComplete = true; |
| 9408 | } |
| 9409 | } else if (!wtoken.allDrawn) { |
| 9410 | int numInteresting = wtoken.numInterestingWindows; |
| 9411 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9412 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9413 | "allDrawn: " + wtoken |
| 9414 | + " interesting=" + numInteresting |
| 9415 | + " drawn=" + wtoken.numDrawnWindows); |
| 9416 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9417 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9418 | |
| 9419 | // We can now show all of the drawn windows! |
| 9420 | if (!mOpeningApps.contains(wtoken)) { |
| 9421 | wtoken.showAllWindowsLocked(); |
| 9422 | } |
| 9423 | } |
| 9424 | } |
| 9425 | } |
| 9426 | } |
| 9427 | |
| 9428 | // If we are ready to perform an app transition, check through |
| 9429 | // all of the app tokens to be shown and see if they are ready |
| 9430 | // to go. |
| 9431 | if (mAppTransitionReady) { |
| 9432 | int NN = mOpeningApps.size(); |
| 9433 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9434 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9435 | "Checking " + NN + " opening apps (frozen=" |
| 9436 | + mDisplayFrozen + " timeout=" |
| 9437 | + mAppTransitionTimeout + ")..."); |
| 9438 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9439 | // If the display isn't frozen, wait to do anything until |
| 9440 | // all of the apps are ready. Otherwise just go because |
| 9441 | // we'll unfreeze the display when everyone is ready. |
| 9442 | for (i=0; i<NN && goodToGo; i++) { |
| 9443 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9444 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9445 | "Check opening app" + wtoken + ": allDrawn=" |
| 9446 | + wtoken.allDrawn + " startingDisplayed=" |
| 9447 | + wtoken.startingDisplayed); |
| 9448 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9449 | && !wtoken.startingMoved) { |
| 9450 | goodToGo = false; |
| 9451 | } |
| 9452 | } |
| 9453 | } |
| 9454 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9455 | 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] | 9456 | int transit = mNextAppTransition; |
| 9457 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9458 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9459 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9460 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9461 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9462 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9463 | mAppTransitionTimeout = false; |
| 9464 | mStartingIconInTransition = false; |
| 9465 | mSkipAppTransitionAnimation = false; |
| 9466 | |
| 9467 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9468 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9469 | // If there are applications waiting to come to the |
| 9470 | // top of the stack, now is the time to move their windows. |
| 9471 | // (Note that we don't do apps going to the bottom |
| 9472 | // here -- we want to keep their windows in the old |
| 9473 | // Z-order until the animation completes.) |
| 9474 | if (mToTopApps.size() > 0) { |
| 9475 | NN = mAppTokens.size(); |
| 9476 | for (i=0; i<NN; i++) { |
| 9477 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9478 | if (wtoken.sendingToTop) { |
| 9479 | wtoken.sendingToTop = false; |
| 9480 | moveAppWindowsLocked(wtoken, NN, false); |
| 9481 | } |
| 9482 | } |
| 9483 | mToTopApps.clear(); |
| 9484 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9485 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9486 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9487 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9488 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9489 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9490 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9491 | // The top-most window will supply the layout params, |
| 9492 | // and we will determine it below. |
| 9493 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9494 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9495 | int bestAnimLayer = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9496 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9497 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9498 | "New wallpaper target=" + mWallpaperTarget |
| 9499 | + ", lower target=" + mLowerWallpaperTarget |
| 9500 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9501 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9502 | // Do a first pass through the tokens for two |
| 9503 | // things: |
| 9504 | // (1) Determine if both the closing and opening |
| 9505 | // app token sets are wallpaper targets, in which |
| 9506 | // case special animations are needed |
| 9507 | // (since the wallpaper needs to stay static |
| 9508 | // behind them). |
| 9509 | // (2) Find the layout params of the top-most |
| 9510 | // application window in the tokens, which is |
| 9511 | // what will control the animation theme. |
| 9512 | final int NC = mClosingApps.size(); |
| 9513 | NN = NC + mOpeningApps.size(); |
| 9514 | for (i=0; i<NN; i++) { |
| 9515 | AppWindowToken wtoken; |
| 9516 | int mode; |
| 9517 | if (i < NC) { |
| 9518 | wtoken = mClosingApps.get(i); |
| 9519 | mode = 1; |
| 9520 | } else { |
| 9521 | wtoken = mOpeningApps.get(i-NC); |
| 9522 | mode = 2; |
| 9523 | } |
| 9524 | if (mLowerWallpaperTarget != null) { |
| 9525 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9526 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9527 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9528 | } |
| 9529 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9530 | if (wtoken.appFullscreen) { |
| 9531 | WindowState ws = wtoken.findMainWindow(); |
| 9532 | if (ws != null) { |
| 9533 | // If this is a compatibility mode |
| 9534 | // window, we will always use its anim. |
| 9535 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9536 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9537 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9538 | bestAnimLayer = Integer.MAX_VALUE; |
| 9539 | } else if (ws.mLayer > bestAnimLayer) { |
| 9540 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9541 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9542 | bestAnimLayer = ws.mLayer; |
| 9543 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9544 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9545 | } |
| 9546 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9547 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9548 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9549 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9550 | "Wallpaper animation!"); |
| 9551 | switch (transit) { |
| 9552 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9553 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9554 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9555 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9556 | break; |
| 9557 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9558 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9559 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9560 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9561 | break; |
| 9562 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9563 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9564 | "New transit: " + transit); |
| 9565 | } else if (oldWallpaper != null) { |
| 9566 | // We are transitioning from an activity with |
| 9567 | // a wallpaper to one without. |
| 9568 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9569 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9570 | "New transit away from wallpaper: " + transit); |
| 9571 | } else if (mWallpaperTarget != null) { |
| 9572 | // We are transitioning from an activity without |
| 9573 | // a wallpaper to now showing the wallpaper |
| 9574 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9575 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9576 | "New transit into wallpaper: " + transit); |
| 9577 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9578 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9579 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9580 | mLastEnterAnimToken = animToken; |
| 9581 | mLastEnterAnimParams = animLp; |
| 9582 | } else if (mLastEnterAnimParams != null) { |
| 9583 | animLp = mLastEnterAnimParams; |
| 9584 | mLastEnterAnimToken = null; |
| 9585 | mLastEnterAnimParams = null; |
| 9586 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9587 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9588 | // If all closing windows are obscured, then there is |
| 9589 | // no need to do an animation. This is the case, for |
| 9590 | // example, when this transition is being done behind |
| 9591 | // the lock screen. |
| 9592 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9593 | animLp = null; |
| 9594 | } |
| 9595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9596 | NN = mOpeningApps.size(); |
| 9597 | for (i=0; i<NN; i++) { |
| 9598 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9599 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9600 | "Now opening app" + wtoken); |
| 9601 | wtoken.reportedVisible = false; |
| 9602 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9603 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9604 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9605 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9606 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9607 | wtoken.showAllWindowsLocked(); |
| 9608 | } |
| 9609 | NN = mClosingApps.size(); |
| 9610 | for (i=0; i<NN; i++) { |
| 9611 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9612 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | "Now closing app" + wtoken); |
| 9614 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9615 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9616 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9617 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9618 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9619 | // Force the allDrawn flag, because we want to start |
| 9620 | // this guy's animations regardless of whether it's |
| 9621 | // gotten drawn. |
| 9622 | wtoken.allDrawn = true; |
| 9623 | } |
| 9624 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9625 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9627 | mOpeningApps.clear(); |
| 9628 | mClosingApps.clear(); |
| 9629 | |
| 9630 | // This has changed the visibility of windows, so perform |
| 9631 | // a new layout to get them all up-to-date. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9632 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9633 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9634 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9635 | assignLayersLocked(); |
| 9636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9637 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9638 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9639 | } |
| 9640 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9641 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9642 | int adjResult = 0; |
| 9643 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9644 | if (!animating && mAppTransitionRunning) { |
| 9645 | // We have finished the animation of an app transition. To do |
| 9646 | // this, we have delayed a lot of operations like showing and |
| 9647 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9648 | // reflects the correct Z-order, but the window list may now |
| 9649 | // be out of sync with it. So here we will just rebuild the |
| 9650 | // entire app window list. Fun! |
| 9651 | mAppTransitionRunning = false; |
| 9652 | // Clear information about apps that were moving. |
| 9653 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9654 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9655 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9656 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9657 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9658 | moveInputMethodWindowsIfNeededLocked(false); |
| 9659 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9660 | // Since the window list has been rebuilt, focus might |
| 9661 | // have to be recomputed since the actual order of windows |
| 9662 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9663 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9664 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9665 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9666 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9667 | // At this point, there was a window with a wallpaper that |
| 9668 | // was force hiding other windows behind it, but now it |
| 9669 | // is going away. This may be simple -- just animate |
| 9670 | // away the wallpaper and its window -- or it may be |
| 9671 | // hard -- the wallpaper now needs to be shown behind |
| 9672 | // something that was hidden. |
| 9673 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9674 | if (mLowerWallpaperTarget != null |
| 9675 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9676 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9677 | "wallpaperForceHiding changed with lower=" |
| 9678 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9679 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9680 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9681 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9682 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9683 | // The lower target has become hidden before we |
| 9684 | // actually started the animation... let's completely |
| 9685 | // re-evaluate everything. |
| 9686 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9687 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9688 | } |
| 9689 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9690 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9691 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9692 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9693 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9694 | + " NEW: " + mWallpaperTarget |
| 9695 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9696 | if (mLowerWallpaperTarget == null) { |
| 9697 | // Whoops, we don't need a special wallpaper animation. |
| 9698 | // Clear them out. |
| 9699 | forceHiding = false; |
| 9700 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9701 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9702 | if (w.mSurface != null) { |
| 9703 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9704 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9705 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9706 | forceHiding = true; |
| 9707 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9708 | if (!w.mAnimating) { |
| 9709 | // We set the animation above so it |
| 9710 | // is not yet running. |
| 9711 | w.clearAnimation(); |
| 9712 | } |
| 9713 | } |
| 9714 | } |
| 9715 | } |
| 9716 | } |
| 9717 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9718 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9719 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9720 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9721 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9722 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9723 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9724 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9725 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9726 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9727 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9728 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9729 | assignLayersLocked(); |
| 9730 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9731 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9732 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9733 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9734 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9735 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9736 | if (mFocusMayChange) { |
| 9737 | mFocusMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9738 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9739 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9740 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9741 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9742 | } |
| 9743 | |
| 9744 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9745 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9746 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9747 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9748 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9749 | + Integer.toHexString(changes)); |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9750 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9751 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9752 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9753 | |
| 9754 | // THIRD LOOP: Update the surfaces of all windows. |
| 9755 | |
| 9756 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9757 | |
| 9758 | boolean obscured = false; |
| 9759 | boolean blurring = false; |
| 9760 | boolean dimming = false; |
| 9761 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9762 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9763 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9764 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9765 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9767 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9768 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9769 | |
| 9770 | boolean displayed = false; |
| 9771 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9772 | final int attrFlags = attrs.flags; |
| 9773 | |
| 9774 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9775 | // XXX NOTE: The logic here could be improved. We have |
| 9776 | // the decision about whether to resize a window separated |
| 9777 | // from whether to hide the surface. This can cause us to |
| 9778 | // resize a surface even if we are going to hide it. You |
| 9779 | // can see this by (1) holding device in landscape mode on |
| 9780 | // home screen; (2) tapping browser icon (device will rotate |
| 9781 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9782 | // in step 2 but then immediately hidden, causing us to |
| 9783 | // have to resize and then redraw it again in step 3. It |
| 9784 | // would be nice to figure out how to avoid this, but it is |
| 9785 | // difficult because we do need to resize surfaces in some |
| 9786 | // cases while they are hidden such as when first showing a |
| 9787 | // window. |
| 9788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9789 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9790 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9791 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9792 | + ": new=" + w.mShownFrame + ", old=" |
| 9793 | + w.mLastShownFrame); |
| 9794 | |
| 9795 | boolean resize; |
| 9796 | int width, height; |
| 9797 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9798 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9799 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9800 | // for a scaled surface, we just want to use |
| 9801 | // the requested size. |
| 9802 | width = w.mRequestedWidth; |
| 9803 | height = w.mRequestedHeight; |
| 9804 | w.mLastRequestedWidth = width; |
| 9805 | w.mLastRequestedHeight = height; |
| 9806 | w.mLastShownFrame.set(w.mShownFrame); |
| 9807 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9808 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9809 | "POS " + w.mShownFrame.left |
| 9810 | + ", " + w.mShownFrame.top, null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9811 | w.mSurfaceX = w.mShownFrame.left; |
| 9812 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9813 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9814 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9815 | Slog.w(TAG, "Error positioning surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9816 | if (!recoveringMemory) { |
| 9817 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9818 | } |
| 9819 | } |
| 9820 | } else { |
| 9821 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9822 | width = w.mShownFrame.width(); |
| 9823 | height = w.mShownFrame.height(); |
| 9824 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9825 | } |
| 9826 | |
| 9827 | if (resize) { |
| 9828 | if (width < 1) width = 1; |
| 9829 | if (height < 1) height = 1; |
| 9830 | if (w.mSurface != null) { |
| 9831 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9832 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9833 | "POS " + w.mShownFrame.left + "," |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9834 | + w.mShownFrame.top + " SIZE " |
| 9835 | + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9836 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9837 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9838 | w.mSurfaceW = width; |
| 9839 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9840 | w.mSurface.setSize(width, height); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9841 | w.mSurfaceX = w.mShownFrame.left; |
| 9842 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9843 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9844 | w.mShownFrame.top); |
| 9845 | } catch (RuntimeException e) { |
| 9846 | // If something goes wrong with the surface (such |
| 9847 | // as running out of memory), don't take down the |
| 9848 | // entire system. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9849 | Slog.e(TAG, "Failure updating surface of " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9850 | + "size=(" + width + "x" + height |
| 9851 | + "), pos=(" + w.mShownFrame.left |
| 9852 | + "," + w.mShownFrame.top + ")", e); |
| 9853 | if (!recoveringMemory) { |
| 9854 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9855 | } |
| 9856 | } |
| 9857 | } |
| 9858 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9859 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9860 | w.mContentInsetsChanged = |
| 9861 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9862 | w.mVisibleInsetsChanged = |
| 9863 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9864 | boolean configChanged = |
| 9865 | w.mConfiguration != mCurConfiguration |
| 9866 | && (w.mConfiguration == null |
| 9867 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9868 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9869 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9870 | + mCurConfiguration); |
| 9871 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9872 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9873 | + ": configChanged=" + configChanged |
| 9874 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9875 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9876 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9877 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9878 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9879 | || configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9880 | w.mLastFrame.set(w.mFrame); |
| 9881 | w.mLastContentInsets.set(w.mContentInsets); |
| 9882 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9883 | // If the screen is currently frozen, then keep |
| 9884 | // it frozen until this window draws at its new |
| 9885 | // orientation. |
| 9886 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9887 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9888 | "Resizing while display frozen: " + w); |
| 9889 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9890 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9891 | mWindowsFreezingScreen = true; |
| 9892 | // XXX should probably keep timeout from |
| 9893 | // when we first froze the display. |
| 9894 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9895 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9896 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9897 | } |
| 9898 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9899 | // If the orientation is changing, then we need to |
| 9900 | // hold off on unfreezing the display until this |
| 9901 | // window has been redrawn; to do that, we need |
| 9902 | // to go through the process of getting informed |
| 9903 | // by the application when it has finished drawing. |
| 9904 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9905 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9906 | "Orientation start waiting for draw in " |
| 9907 | + w + ", surface " + w.mSurface); |
| 9908 | w.mDrawPending = true; |
| 9909 | w.mCommitDrawPending = false; |
| 9910 | w.mReadyToShow = false; |
| 9911 | if (w.mAppToken != null) { |
| 9912 | w.mAppToken.allDrawn = false; |
| 9913 | } |
| 9914 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9915 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9916 | "Resizing window " + w + " to " + w.mFrame); |
| 9917 | mResizingWindows.add(w); |
| 9918 | } else if (w.mOrientationChanging) { |
| 9919 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9920 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9921 | "Orientation not waiting for draw in " |
| 9922 | + w + ", surface " + w.mSurface); |
| 9923 | w.mOrientationChanging = false; |
| 9924 | } |
| 9925 | } |
| 9926 | } |
| 9927 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9928 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9929 | if (!w.mLastHidden) { |
| 9930 | //dump(); |
| 9931 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9932 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9933 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9934 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9935 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9936 | try { |
| 9937 | w.mSurface.hide(); |
| 9938 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9939 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9940 | } |
| 9941 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9942 | } |
| 9943 | // If we are waiting for this window to handle an |
| 9944 | // orientation change, well, it is hidden, so |
| 9945 | // doesn't really matter. Note that this does |
| 9946 | // introduce a potential glitch if the window |
| 9947 | // becomes unhidden before it has drawn for the |
| 9948 | // new orientation. |
| 9949 | if (w.mOrientationChanging) { |
| 9950 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9951 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9952 | "Orientation change skips hidden " + w); |
| 9953 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9954 | } else if (w.mLastLayer != w.mAnimLayer |
| 9955 | || w.mLastAlpha != w.mShownAlpha |
| 9956 | || w.mLastDsDx != w.mDsDx |
| 9957 | || w.mLastDtDx != w.mDtDx |
| 9958 | || w.mLastDsDy != w.mDsDy |
| 9959 | || w.mLastDtDy != w.mDtDy |
| 9960 | || w.mLastHScale != w.mHScale |
| 9961 | || w.mLastVScale != w.mVScale |
| 9962 | || w.mLastHidden) { |
| 9963 | displayed = true; |
| 9964 | w.mLastAlpha = w.mShownAlpha; |
| 9965 | w.mLastLayer = w.mAnimLayer; |
| 9966 | w.mLastDsDx = w.mDsDx; |
| 9967 | w.mLastDtDx = w.mDtDx; |
| 9968 | w.mLastDsDy = w.mDsDy; |
| 9969 | w.mLastDtDy = w.mDtDy; |
| 9970 | w.mLastHScale = w.mHScale; |
| 9971 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9972 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9973 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9974 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9975 | + "," + (w.mDtDx*w.mVScale) |
| 9976 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9977 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9978 | if (w.mSurface != null) { |
| 9979 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9980 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9981 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9982 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9983 | w.mSurface.setLayer(w.mAnimLayer); |
| 9984 | w.mSurface.setMatrix( |
| 9985 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9986 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9987 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9988 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9989 | if (!recoveringMemory) { |
| 9990 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9991 | } |
| 9992 | } |
| 9993 | } |
| 9994 | |
| 9995 | if (w.mLastHidden && !w.mDrawPending |
| 9996 | && !w.mCommitDrawPending |
| 9997 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9998 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9999 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10000 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10001 | + " during relayout"); |
| 10002 | if (showSurfaceRobustlyLocked(w)) { |
| 10003 | w.mHasDrawn = true; |
| 10004 | w.mLastHidden = false; |
| 10005 | } else { |
| 10006 | w.mOrientationChanging = false; |
| 10007 | } |
| 10008 | } |
| 10009 | if (w.mSurface != null) { |
| 10010 | w.mToken.hasVisible = true; |
| 10011 | } |
| 10012 | } else { |
| 10013 | displayed = true; |
| 10014 | } |
| 10015 | |
| 10016 | if (displayed) { |
| 10017 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10018 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10019 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10020 | covered = true; |
| 10021 | } |
| 10022 | } |
| 10023 | if (w.mOrientationChanging) { |
| 10024 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10025 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10026 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10027 | "Orientation continue waiting for draw in " + w); |
| 10028 | } else { |
| 10029 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10030 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10031 | "Orientation change complete in " + w); |
| 10032 | } |
| 10033 | } |
| 10034 | w.mToken.hasVisible = true; |
| 10035 | } |
| 10036 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10037 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10038 | "Orientation change skips hidden " + w); |
| 10039 | w.mOrientationChanging = false; |
| 10040 | } |
| 10041 | |
| 10042 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10043 | |
| 10044 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10045 | focusDisplayed = true; |
| 10046 | } |
| 10047 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10048 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10050 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10051 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10052 | if (w.mSurface != null) { |
| 10053 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10054 | holdScreen = w.mSession; |
| 10055 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10056 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10057 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10058 | screenBrightness = w.mAttrs.screenBrightness; |
| 10059 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10060 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10061 | && buttonBrightness < 0) { |
| 10062 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10063 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10064 | if (canBeSeen |
| 10065 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10066 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10067 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10068 | syswin = true; |
| 10069 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10070 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10071 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10072 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10073 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10074 | // This window completely covers everything behind it, |
| 10075 | // so we want to leave all of them as unblurred (for |
| 10076 | // performance reasons). |
| 10077 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10078 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10079 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10080 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10081 | obscured = true; |
| 10082 | if (mBackgroundFillerSurface == null) { |
| 10083 | try { |
| 10084 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10085 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10086 | 0, dw, dh, |
| 10087 | PixelFormat.OPAQUE, |
| 10088 | Surface.FX_SURFACE_NORMAL); |
| 10089 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10090 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10091 | } |
| 10092 | } |
| 10093 | try { |
| 10094 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10095 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10096 | // Using the same layer as Dim because they will never be shown at the |
| 10097 | // same time. |
| 10098 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10099 | mBackgroundFillerSurface.show(); |
| 10100 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10101 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10102 | } |
| 10103 | backgroundFillerShown = true; |
| 10104 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10105 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10106 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10107 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10108 | + ": blurring=" + blurring |
| 10109 | + " obscured=" + obscured |
| 10110 | + " displayed=" + displayed); |
| 10111 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10112 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10113 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10114 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10115 | if (mDimAnimator == null) { |
| 10116 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10117 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10118 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10119 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10120 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10121 | } |
| 10122 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10123 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10124 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10125 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10126 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10127 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10128 | + mBlurSurface + ": CREATE"); |
| 10129 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10130 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10131 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10132 | -1, 16, 16, |
| 10133 | PixelFormat.OPAQUE, |
| 10134 | Surface.FX_SURFACE_BLUR); |
| 10135 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10136 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10137 | } |
| 10138 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10139 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10140 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10141 | + mBlurSurface + ": pos=(0,0) (" + |
| 10142 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10143 | mBlurSurface.setPosition(0, 0); |
| 10144 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10145 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10146 | if (!mBlurShown) { |
| 10147 | try { |
| 10148 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10149 | + mBlurSurface + ": SHOW"); |
| 10150 | mBlurSurface.show(); |
| 10151 | } catch (RuntimeException e) { |
| 10152 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10153 | } |
| 10154 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10155 | } |
| 10156 | } |
| 10157 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10158 | } |
| 10159 | } |
| 10160 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10161 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10162 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10163 | // This is the wallpaper target and its obscured state |
| 10164 | // changed... make sure the current wallaper's visibility |
| 10165 | // has been updated accordingly. |
| 10166 | updateWallpaperVisibilityLocked(); |
| 10167 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10168 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10169 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10170 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10171 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10172 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10173 | try { |
| 10174 | mBackgroundFillerSurface.hide(); |
| 10175 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10176 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10177 | } |
| 10178 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10179 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10180 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10181 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10182 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10185 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10186 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10187 | + ": HIDE"); |
| 10188 | try { |
| 10189 | mBlurSurface.hide(); |
| 10190 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10191 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10192 | } |
| 10193 | mBlurShown = false; |
| 10194 | } |
| 10195 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10196 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10197 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10198 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10199 | } |
| 10200 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10201 | mInputMonitor.updateInputWindowsLw(); |
| 10202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10203 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10204 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10205 | if (mWatermark != null) { |
| 10206 | mWatermark.drawIfNeeded(); |
| 10207 | } |
| 10208 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10209 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10210 | "With display frozen, orientationChangeComplete=" |
| 10211 | + orientationChangeComplete); |
| 10212 | if (orientationChangeComplete) { |
| 10213 | if (mWindowsFreezingScreen) { |
| 10214 | mWindowsFreezingScreen = false; |
| 10215 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10216 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10217 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10218 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10220 | i = mResizingWindows.size(); |
| 10221 | if (i > 0) { |
| 10222 | do { |
| 10223 | i--; |
| 10224 | WindowState win = mResizingWindows.get(i); |
| 10225 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10226 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10227 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10228 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10229 | boolean configChanged = |
| 10230 | win.mConfiguration != mCurConfiguration |
| 10231 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10232 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10233 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10234 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10235 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10236 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10237 | + " / " + mCurConfiguration + " / 0x" |
| 10238 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10239 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10240 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10241 | win.mClient.resized(win.mFrame.width(), |
| 10242 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10243 | win.mLastVisibleInsets, win.mDrawPending, |
| 10244 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10245 | win.mContentInsetsChanged = false; |
| 10246 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10247 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10248 | } catch (RemoteException e) { |
| 10249 | win.mOrientationChanging = false; |
| 10250 | } |
| 10251 | } while (i > 0); |
| 10252 | mResizingWindows.clear(); |
| 10253 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10255 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10256 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10257 | i = mDestroySurface.size(); |
| 10258 | if (i > 0) { |
| 10259 | do { |
| 10260 | i--; |
| 10261 | WindowState win = mDestroySurface.get(i); |
| 10262 | win.mDestroying = false; |
| 10263 | if (mInputMethodWindow == win) { |
| 10264 | mInputMethodWindow = null; |
| 10265 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10266 | if (win == mWallpaperTarget) { |
| 10267 | wallpaperDestroyed = true; |
| 10268 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10269 | win.destroySurfaceLocked(); |
| 10270 | } while (i > 0); |
| 10271 | mDestroySurface.clear(); |
| 10272 | } |
| 10273 | |
| 10274 | // Time to remove any exiting tokens? |
| 10275 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10276 | WindowToken token = mExitingTokens.get(i); |
| 10277 | if (!token.hasVisible) { |
| 10278 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10279 | if (token.windowType == TYPE_WALLPAPER) { |
| 10280 | mWallpaperTokens.remove(token); |
| 10281 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10282 | } |
| 10283 | } |
| 10284 | |
| 10285 | // Time to remove any exiting applications? |
| 10286 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10287 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10288 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10289 | // Make sure there is no animation running on this token, |
| 10290 | // so any windows associated with it will be removed as |
| 10291 | // soon as their animations are complete |
| 10292 | token.animation = null; |
| 10293 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10294 | mAppTokens.remove(token); |
| 10295 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10296 | if (mLastEnterAnimToken == token) { |
| 10297 | mLastEnterAnimToken = null; |
| 10298 | mLastEnterAnimParams = null; |
| 10299 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10300 | } |
| 10301 | } |
| 10302 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10303 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10304 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10305 | if (!animating && mAppTransitionRunning) { |
| 10306 | // We have finished the animation of an app transition. To do |
| 10307 | // this, we have delayed a lot of operations like showing and |
| 10308 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10309 | // reflects the correct Z-order, but the window list may now |
| 10310 | // be out of sync with it. So here we will just rebuild the |
| 10311 | // entire app window list. Fun! |
| 10312 | mAppTransitionRunning = false; |
| 10313 | needRelayout = true; |
| 10314 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10315 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10316 | // Clear information about apps that were moving. |
| 10317 | mToBottomApps.clear(); |
| 10318 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10320 | if (focusDisplayed) { |
| 10321 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10322 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10323 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10324 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10325 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10326 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10327 | requestAnimationLocked(0); |
| 10328 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10329 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10330 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10331 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10332 | mInputMonitor.updateInputWindowsLw(); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10333 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10334 | setHoldScreenLocked(holdScreen != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10335 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10336 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10337 | } else { |
| 10338 | mPowerManager.setScreenBrightnessOverride((int) |
| 10339 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10340 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10341 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10342 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10343 | } else { |
| 10344 | mPowerManager.setButtonBrightnessOverride((int) |
| 10345 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10346 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10347 | if (holdScreen != mHoldingScreenOn) { |
| 10348 | mHoldingScreenOn = holdScreen; |
| 10349 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10350 | mH.sendMessage(m); |
| 10351 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10352 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10353 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10354 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10355 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10356 | LocalPowerManager.BUTTON_EVENT, true); |
| 10357 | mTurnOnScreen = false; |
| 10358 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10359 | |
| 10360 | // Check to see if we are now in a state where the screen should |
| 10361 | // be enabled, because the window obscured flags have changed. |
| 10362 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10363 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10364 | |
| 10365 | /** |
| 10366 | * Must be called with the main window manager lock held. |
| 10367 | */ |
| 10368 | void setHoldScreenLocked(boolean holding) { |
| 10369 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10370 | if (holding != state) { |
| 10371 | if (holding) { |
| 10372 | mHoldingScreenWakeLock.acquire(); |
| 10373 | } else { |
| 10374 | mPolicy.screenOnStoppedLw(); |
| 10375 | mHoldingScreenWakeLock.release(); |
| 10376 | } |
| 10377 | } |
| 10378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10379 | |
| 10380 | void requestAnimationLocked(long delay) { |
| 10381 | if (!mAnimationPending) { |
| 10382 | mAnimationPending = true; |
| 10383 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10384 | } |
| 10385 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10387 | /** |
| 10388 | * Have the surface flinger show a surface, robustly dealing with |
| 10389 | * error conditions. In particular, if there is not enough memory |
| 10390 | * to show the surface, then we will try to get rid of other surfaces |
| 10391 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10392 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10393 | * @return Returns true if the surface was successfully shown. |
| 10394 | */ |
| 10395 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10396 | try { |
| 10397 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10398 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10399 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10400 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10401 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10402 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10403 | win.mTurnOnScreen = false; |
| 10404 | mTurnOnScreen = true; |
| 10405 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10406 | } |
| 10407 | return true; |
| 10408 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10409 | 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] | 10410 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10412 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10414 | return false; |
| 10415 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10417 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10418 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10419 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10420 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10421 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10423 | if (mForceRemoves == null) { |
| 10424 | mForceRemoves = new ArrayList<WindowState>(); |
| 10425 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10427 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10428 | try { |
| 10429 | // There was some problem... first, do a sanity check of the |
| 10430 | // window list to make sure we haven't left any dangling surfaces |
| 10431 | // around. |
| 10432 | int N = mWindows.size(); |
| 10433 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10434 | 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] | 10435 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10436 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10437 | if (ws.mSurface != null) { |
| 10438 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10439 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10440 | + ws + " surface=" + ws.mSurface |
| 10441 | + " token=" + win.mToken |
| 10442 | + " pid=" + ws.mSession.mPid |
| 10443 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10444 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10445 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10446 | ws.mSurface = null; |
| 10447 | mForceRemoves.add(ws); |
| 10448 | i--; |
| 10449 | N--; |
| 10450 | leakedSurface = true; |
| 10451 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10452 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10453 | + ws + " surface=" + ws.mSurface |
| 10454 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10455 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10456 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10457 | ws.mSurface = null; |
| 10458 | leakedSurface = true; |
| 10459 | } |
| 10460 | } |
| 10461 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10463 | boolean killedApps = false; |
| 10464 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10465 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10466 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10467 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10468 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10469 | if (ws.mSurface != null) { |
| 10470 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10471 | } |
| 10472 | } |
| 10473 | if (pidCandidates.size() > 0) { |
| 10474 | int[] pids = new int[pidCandidates.size()]; |
| 10475 | for (int i=0; i<pids.length; i++) { |
| 10476 | pids[i] = pidCandidates.keyAt(i); |
| 10477 | } |
| 10478 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10479 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10480 | killedApps = true; |
| 10481 | } |
| 10482 | } catch (RemoteException e) { |
| 10483 | } |
| 10484 | } |
| 10485 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10487 | if (leakedSurface || killedApps) { |
| 10488 | // We managed to reclaim some memory, so get rid of the trouble |
| 10489 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10490 | 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] | 10491 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10492 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10493 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10494 | win.mSurface = null; |
| 10495 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10497 | try { |
| 10498 | win.mClient.dispatchGetNewSurface(); |
| 10499 | } catch (RemoteException e) { |
| 10500 | } |
| 10501 | } |
| 10502 | } finally { |
| 10503 | Binder.restoreCallingIdentity(callingIdentity); |
| 10504 | } |
| 10505 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10507 | private boolean updateFocusedWindowLocked(int mode) { |
| 10508 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10509 | if (mCurrentFocus != newFocus) { |
| 10510 | // This check makes sure that we don't already have the focus |
| 10511 | // change message pending. |
| 10512 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10513 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10514 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10515 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10516 | final WindowState oldFocus = mCurrentFocus; |
| 10517 | mCurrentFocus = newFocus; |
| 10518 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10520 | final WindowState imWindow = mInputMethodWindow; |
| 10521 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10522 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10523 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10524 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10525 | mLayoutNeeded = true; |
| 10526 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10527 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10528 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10529 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10530 | // Client will do the layout, but we need to assign layers |
| 10531 | // for handleNewWindowLocked() below. |
| 10532 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10533 | } |
| 10534 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10535 | |
| 10536 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10537 | // If we defer assigning layers, then the caller is responsible for |
| 10538 | // doing this part. |
| 10539 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10541 | return true; |
| 10542 | } |
| 10543 | return false; |
| 10544 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10545 | |
| 10546 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10547 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10548 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10549 | |
| 10550 | private WindowState computeFocusedWindowLocked() { |
| 10551 | WindowState result = null; |
| 10552 | WindowState win; |
| 10553 | |
| 10554 | int i = mWindows.size() - 1; |
| 10555 | int nextAppIndex = mAppTokens.size()-1; |
| 10556 | WindowToken nextApp = nextAppIndex >= 0 |
| 10557 | ? mAppTokens.get(nextAppIndex) : null; |
| 10558 | |
| 10559 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10560 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10561 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10562 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10563 | TAG, "Looking for focus: " + i |
| 10564 | + " = " + win |
| 10565 | + ", flags=" + win.mAttrs.flags |
| 10566 | + ", canReceive=" + win.canReceiveKeys()); |
| 10567 | |
| 10568 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10570 | // If this window's application has been removed, just skip it. |
| 10571 | if (thisApp != null && thisApp.removed) { |
| 10572 | i--; |
| 10573 | continue; |
| 10574 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10576 | // If there is a focused app, don't allow focus to go to any |
| 10577 | // windows below it. If this is an application window, step |
| 10578 | // through the app tokens until we find its app. |
| 10579 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10580 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10581 | int origAppIndex = nextAppIndex; |
| 10582 | while (nextAppIndex > 0) { |
| 10583 | if (nextApp == mFocusedApp) { |
| 10584 | // Whoops, we are below the focused app... no focus |
| 10585 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10586 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10587 | TAG, "Reached focused app: " + mFocusedApp); |
| 10588 | return null; |
| 10589 | } |
| 10590 | nextAppIndex--; |
| 10591 | nextApp = mAppTokens.get(nextAppIndex); |
| 10592 | if (nextApp == thisApp) { |
| 10593 | break; |
| 10594 | } |
| 10595 | } |
| 10596 | if (thisApp != nextApp) { |
| 10597 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10598 | // happen, but if it does we can get totally hosed... |
| 10599 | // so restart at the original app. |
| 10600 | nextAppIndex = origAppIndex; |
| 10601 | nextApp = mAppTokens.get(nextAppIndex); |
| 10602 | } |
| 10603 | } |
| 10604 | |
| 10605 | // Dispatch to this window if it is wants key events. |
| 10606 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10607 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10608 | TAG, "Found focus @ " + i + " = " + win); |
| 10609 | result = win; |
| 10610 | break; |
| 10611 | } |
| 10612 | |
| 10613 | i--; |
| 10614 | } |
| 10615 | |
| 10616 | return result; |
| 10617 | } |
| 10618 | |
| 10619 | private void startFreezingDisplayLocked() { |
| 10620 | if (mDisplayFrozen) { |
| 10621 | return; |
| 10622 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10624 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10626 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10627 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10628 | if (mFreezeGcPending != 0) { |
| 10629 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10630 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10631 | mH.removeMessages(H.FORCE_GC); |
| 10632 | Runtime.getRuntime().gc(); |
| 10633 | mFreezeGcPending = now; |
| 10634 | } |
| 10635 | } else { |
| 10636 | mFreezeGcPending = now; |
| 10637 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10639 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10640 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10641 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10642 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10643 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10644 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10645 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | mAppTransitionReady = true; |
| 10647 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10649 | if (PROFILE_ORIENTATION) { |
| 10650 | File file = new File("/data/system/frozen"); |
| 10651 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10652 | } |
| 10653 | Surface.freezeDisplay(0); |
| 10654 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10656 | private void stopFreezingDisplayLocked() { |
| 10657 | if (!mDisplayFrozen) { |
| 10658 | return; |
| 10659 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10660 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10661 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10662 | return; |
| 10663 | } |
| 10664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10665 | mDisplayFrozen = false; |
| 10666 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10667 | if (PROFILE_ORIENTATION) { |
| 10668 | Debug.stopMethodTracing(); |
| 10669 | } |
| 10670 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10671 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10672 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10673 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10674 | // While the display is frozen we don't re-compute the orientation |
| 10675 | // to avoid inconsistent states. However, something interesting |
| 10676 | // could have actually changed during that time so re-evaluate it |
| 10677 | // now to catch that. |
| 10678 | if (updateOrientationFromAppTokensLocked()) { |
| 10679 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10680 | } |
| 10681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10682 | // A little kludge: a lot could have happened while the |
| 10683 | // display was frozen, so now that we are coming back we |
| 10684 | // do a gc so that any remote references the system |
| 10685 | // processes holds on others can be released if they are |
| 10686 | // no longer needed. |
| 10687 | mH.removeMessages(H.FORCE_GC); |
| 10688 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10689 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10691 | mScreenFrozenLock.release(); |
| 10692 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10693 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10694 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10695 | DisplayMetrics dm) { |
| 10696 | if (index < tokens.length) { |
| 10697 | String str = tokens[index]; |
| 10698 | if (str != null && str.length() > 0) { |
| 10699 | try { |
| 10700 | int val = Integer.parseInt(str); |
| 10701 | return val; |
| 10702 | } catch (Exception e) { |
| 10703 | } |
| 10704 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10705 | } |
| 10706 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10707 | return defDps; |
| 10708 | } |
| 10709 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10710 | return val; |
| 10711 | } |
| 10712 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame^] | 10713 | static class Watermark { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10714 | final String[] mTokens; |
| 10715 | final String mText; |
| 10716 | final Paint mTextPaint; |
| 10717 | final int mTextWidth; |
| 10718 | final int mTextHeight; |
| 10719 | final int mTextAscent; |
| 10720 | final int mTextDescent; |
| 10721 | final int mDeltaX; |
| 10722 | final int mDeltaY; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10723 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10724 | Surface mSurface; |
| 10725 | int mLastDW; |
| 10726 | int mLastDH; |
| 10727 | boolean mDrawNeeded; |
| 10728 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame^] | 10729 | Watermark(Display display, SurfaceSession session, String[] tokens) { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10730 | final DisplayMetrics dm = new DisplayMetrics(); |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame^] | 10731 | display.getMetrics(dm); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10732 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10733 | if (false) { |
| 10734 | Log.i(TAG, "*********************** WATERMARK"); |
| 10735 | for (int i=0; i<tokens.length; i++) { |
| 10736 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 10737 | } |
| 10738 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10739 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10740 | mTokens = tokens; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10741 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10742 | StringBuilder builder = new StringBuilder(32); |
| 10743 | int len = mTokens[0].length(); |
| 10744 | len = len & ~1; |
| 10745 | for (int i=0; i<len; i+=2) { |
| 10746 | int c1 = mTokens[0].charAt(i); |
| 10747 | int c2 = mTokens[0].charAt(i+1); |
| 10748 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 10749 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 10750 | else c1 -= '0'; |
| 10751 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 10752 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 10753 | else c2 -= '0'; |
| 10754 | builder.append((char)(255-((c1*16)+c2))); |
| 10755 | } |
| 10756 | mText = builder.toString(); |
| 10757 | if (false) { |
| 10758 | Log.i(TAG, "Final text: " + mText); |
| 10759 | } |
| 10760 | |
| 10761 | int fontSize = getPropertyInt(tokens, 1, |
| 10762 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 10763 | |
| 10764 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 10765 | mTextPaint.setTextSize(fontSize); |
| 10766 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 10767 | |
| 10768 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 10769 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 10770 | mTextAscent = fm.ascent; |
| 10771 | mTextDescent = fm.descent; |
| 10772 | mTextHeight = fm.descent - fm.ascent; |
| 10773 | |
| 10774 | mDeltaX = getPropertyInt(tokens, 2, |
| 10775 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 10776 | mDeltaY = getPropertyInt(tokens, 3, |
| 10777 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 10778 | int shadowColor = getPropertyInt(tokens, 4, |
| 10779 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 10780 | int color = getPropertyInt(tokens, 5, |
| 10781 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 10782 | int shadowRadius = getPropertyInt(tokens, 6, |
| 10783 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 10784 | int shadowDx = getPropertyInt(tokens, 8, |
| 10785 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10786 | int shadowDy = getPropertyInt(tokens, 9, |
| 10787 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10788 | |
| 10789 | mTextPaint.setColor(color); |
| 10790 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10791 | |
| 10792 | try { |
| 10793 | mSurface = new Surface(session, 0, |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10794 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10795 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10796 | mSurface.setPosition(0, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10797 | mSurface.show(); |
| 10798 | } catch (OutOfResourcesException e) { |
| 10799 | } |
| 10800 | } |
| 10801 | |
| 10802 | void positionSurface(int dw, int dh) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10803 | if (mLastDW != dw || mLastDH != dh) { |
| 10804 | mLastDW = dw; |
| 10805 | mLastDH = dh; |
| 10806 | mSurface.setSize(dw, dh); |
| 10807 | mDrawNeeded = true; |
| 10808 | } |
| 10809 | } |
| 10810 | |
| 10811 | void drawIfNeeded() { |
| 10812 | if (mDrawNeeded) { |
| 10813 | final int dw = mLastDW; |
| 10814 | final int dh = mLastDH; |
| 10815 | |
| 10816 | mDrawNeeded = false; |
| 10817 | Rect dirty = new Rect(0, 0, dw, dh); |
| 10818 | Canvas c = null; |
| 10819 | try { |
| 10820 | c = mSurface.lockCanvas(dirty); |
| 10821 | } catch (IllegalArgumentException e) { |
| 10822 | } catch (OutOfResourcesException e) { |
| 10823 | } |
| 10824 | if (c != null) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame^] | 10825 | c.drawColor(0, PorterDuff.Mode.CLEAR); |
| 10826 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10827 | int deltaX = mDeltaX; |
| 10828 | int deltaY = mDeltaY; |
| 10829 | |
| 10830 | // deltaX shouldn't be close to a round fraction of our |
| 10831 | // x step, or else things will line up too much. |
| 10832 | int div = (dw+mTextWidth)/deltaX; |
| 10833 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 10834 | int qdelta = deltaX/4; |
| 10835 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 10836 | deltaX += deltaX/3; |
| 10837 | } |
| 10838 | |
| 10839 | int y = -mTextHeight; |
| 10840 | int x = -mTextWidth; |
| 10841 | while (y < (dh+mTextHeight)) { |
| 10842 | c.drawText(mText, x, y, mTextPaint); |
| 10843 | x += deltaX; |
| 10844 | if (x >= dw) { |
| 10845 | x -= (dw+mTextWidth); |
| 10846 | y += deltaY; |
| 10847 | } |
| 10848 | } |
| 10849 | mSurface.unlockCanvasAndPost(c); |
| 10850 | } |
| 10851 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10852 | } |
| 10853 | } |
| 10854 | |
| 10855 | void createWatermark() { |
| 10856 | if (mWatermark != null) { |
| 10857 | return; |
| 10858 | } |
| 10859 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10860 | File file = new File("/system/etc/setup.conf"); |
| 10861 | FileInputStream in = null; |
| 10862 | try { |
| 10863 | in = new FileInputStream(file); |
| 10864 | DataInputStream ind = new DataInputStream(in); |
| 10865 | String line = ind.readLine(); |
| 10866 | if (line != null) { |
| 10867 | String[] toks = line.split("%"); |
| 10868 | if (toks != null && toks.length > 0) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame^] | 10869 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10870 | } |
| 10871 | } |
| 10872 | } catch (FileNotFoundException e) { |
| 10873 | } catch (IOException e) { |
| 10874 | } finally { |
| 10875 | if (in != null) { |
| 10876 | try { |
| 10877 | in.close(); |
| 10878 | } catch (IOException e) { |
| 10879 | } |
| 10880 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10881 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10882 | } |
| 10883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10884 | @Override |
| 10885 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10886 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10887 | != PackageManager.PERMISSION_GRANTED) { |
| 10888 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10889 | + Binder.getCallingPid() |
| 10890 | + ", uid=" + Binder.getCallingUid()); |
| 10891 | return; |
| 10892 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10893 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10894 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10895 | pw.println(" "); |
| 10896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10897 | synchronized(mWindowMap) { |
| 10898 | pw.println("Current Window Manager state:"); |
| 10899 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10900 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10901 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10902 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10903 | w.dump(pw, " "); |
| 10904 | } |
| 10905 | if (mInputMethodDialogs.size() > 0) { |
| 10906 | pw.println(" "); |
| 10907 | pw.println(" Input method dialogs:"); |
| 10908 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10909 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10910 | 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] | 10911 | } |
| 10912 | } |
| 10913 | if (mPendingRemove.size() > 0) { |
| 10914 | pw.println(" "); |
| 10915 | pw.println(" Remove pending for:"); |
| 10916 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10917 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10918 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10919 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10920 | w.dump(pw, " "); |
| 10921 | } |
| 10922 | } |
| 10923 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10924 | pw.println(" "); |
| 10925 | pw.println(" Windows force removing:"); |
| 10926 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10927 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10928 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10929 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10930 | w.dump(pw, " "); |
| 10931 | } |
| 10932 | } |
| 10933 | if (mDestroySurface.size() > 0) { |
| 10934 | pw.println(" "); |
| 10935 | pw.println(" Windows waiting to destroy their surface:"); |
| 10936 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10937 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10938 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10939 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10940 | w.dump(pw, " "); |
| 10941 | } |
| 10942 | } |
| 10943 | if (mLosingFocus.size() > 0) { |
| 10944 | pw.println(" "); |
| 10945 | pw.println(" Windows losing focus:"); |
| 10946 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10947 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10948 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10949 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10950 | w.dump(pw, " "); |
| 10951 | } |
| 10952 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10953 | if (mResizingWindows.size() > 0) { |
| 10954 | pw.println(" "); |
| 10955 | pw.println(" Windows waiting to resize:"); |
| 10956 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10957 | WindowState w = mResizingWindows.get(i); |
| 10958 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10959 | pw.print(w); pw.println(":"); |
| 10960 | w.dump(pw, " "); |
| 10961 | } |
| 10962 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10963 | if (mSessions.size() > 0) { |
| 10964 | pw.println(" "); |
| 10965 | pw.println(" All active sessions:"); |
| 10966 | Iterator<Session> it = mSessions.iterator(); |
| 10967 | while (it.hasNext()) { |
| 10968 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10969 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10970 | s.dump(pw, " "); |
| 10971 | } |
| 10972 | } |
| 10973 | if (mTokenMap.size() > 0) { |
| 10974 | pw.println(" "); |
| 10975 | pw.println(" All tokens:"); |
| 10976 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10977 | while (it.hasNext()) { |
| 10978 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10979 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10980 | token.dump(pw, " "); |
| 10981 | } |
| 10982 | } |
| 10983 | if (mTokenList.size() > 0) { |
| 10984 | pw.println(" "); |
| 10985 | pw.println(" Window token list:"); |
| 10986 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10987 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10988 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10989 | } |
| 10990 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10991 | if (mWallpaperTokens.size() > 0) { |
| 10992 | pw.println(" "); |
| 10993 | pw.println(" Wallpaper tokens:"); |
| 10994 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10995 | WindowToken token = mWallpaperTokens.get(i); |
| 10996 | pw.print(" Wallpaper #"); pw.print(i); |
| 10997 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10998 | token.dump(pw, " "); |
| 10999 | } |
| 11000 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11001 | if (mAppTokens.size() > 0) { |
| 11002 | pw.println(" "); |
| 11003 | pw.println(" Application tokens in Z order:"); |
| 11004 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11005 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11006 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11007 | } |
| 11008 | } |
| 11009 | if (mFinishedStarting.size() > 0) { |
| 11010 | pw.println(" "); |
| 11011 | pw.println(" Finishing start of application tokens:"); |
| 11012 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11013 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11014 | pw.print(" Finished Starting #"); pw.print(i); |
| 11015 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11016 | token.dump(pw, " "); |
| 11017 | } |
| 11018 | } |
| 11019 | if (mExitingTokens.size() > 0) { |
| 11020 | pw.println(" "); |
| 11021 | pw.println(" Exiting tokens:"); |
| 11022 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11023 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11024 | pw.print(" Exiting #"); pw.print(i); |
| 11025 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11026 | token.dump(pw, " "); |
| 11027 | } |
| 11028 | } |
| 11029 | if (mExitingAppTokens.size() > 0) { |
| 11030 | pw.println(" "); |
| 11031 | pw.println(" Exiting application tokens:"); |
| 11032 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11033 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11034 | pw.print(" Exiting App #"); pw.print(i); |
| 11035 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11036 | token.dump(pw, " "); |
| 11037 | } |
| 11038 | } |
| 11039 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11040 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11041 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11042 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11043 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11044 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11045 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11046 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11047 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11048 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11049 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11050 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11051 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11052 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11053 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11054 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11055 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11056 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11057 | if (mDimAnimator != null) { |
| 11058 | mDimAnimator.printTo(pw); |
| 11059 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11060 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11061 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11062 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11063 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11064 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11065 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11066 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11067 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11068 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11069 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11070 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11071 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11072 | pw.print(" mRotation="); pw.print(mRotation); |
| 11073 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11074 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11075 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11076 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11077 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11078 | pw.print(" mNextAppTransition=0x"); |
| 11079 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11080 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11081 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11082 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11083 | if (mNextAppTransitionPackage != null) { |
| 11084 | pw.print(" mNextAppTransitionPackage="); |
| 11085 | pw.print(mNextAppTransitionPackage); |
| 11086 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11087 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11088 | pw.print(", mNextAppTransitionExit=0x"); |
| 11089 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11090 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11091 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11092 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11093 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11094 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11095 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11096 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11097 | if (mOpeningApps.size() > 0) { |
| 11098 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11099 | } |
| 11100 | if (mClosingApps.size() > 0) { |
| 11101 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11102 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11103 | if (mToTopApps.size() > 0) { |
| 11104 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11105 | } |
| 11106 | if (mToBottomApps.size() > 0) { |
| 11107 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11108 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11109 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11110 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11111 | } |
| 11112 | } |
| 11113 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11114 | // 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] | 11115 | public void monitor() { |
| 11116 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11117 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11118 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11119 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11120 | /** |
| 11121 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11122 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11123 | */ |
| 11124 | private static class DimAnimator { |
| 11125 | Surface mDimSurface; |
| 11126 | boolean mDimShown = false; |
| 11127 | float mDimCurrentAlpha; |
| 11128 | float mDimTargetAlpha; |
| 11129 | float mDimDeltaPerMs; |
| 11130 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11131 | |
| 11132 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11133 | |
| 11134 | DimAnimator (SurfaceSession session) { |
| 11135 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11136 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11137 | + mDimSurface + ": CREATE"); |
| 11138 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11139 | mDimSurface = new Surface(session, 0, |
| 11140 | "DimSurface", |
| 11141 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11142 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11143 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11144 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11145 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11146 | } |
| 11147 | } |
| 11148 | } |
| 11149 | |
| 11150 | /** |
| 11151 | * Show the dim surface. |
| 11152 | */ |
| 11153 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11154 | if (!mDimShown) { |
| 11155 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11156 | dw + "x" + dh + ")"); |
| 11157 | mDimShown = true; |
| 11158 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11159 | mLastDimWidth = dw; |
| 11160 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11161 | mDimSurface.setPosition(0, 0); |
| 11162 | mDimSurface.setSize(dw, dh); |
| 11163 | mDimSurface.show(); |
| 11164 | } catch (RuntimeException e) { |
| 11165 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11166 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11167 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11168 | mLastDimWidth = dw; |
| 11169 | mLastDimHeight = dh; |
| 11170 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11171 | } |
| 11172 | } |
| 11173 | |
| 11174 | /** |
| 11175 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11176 | * {@link updateSurface} after all windows are examined. |
| 11177 | */ |
| 11178 | void updateParameters(WindowState w, long currentTime) { |
| 11179 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11180 | |
| 11181 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11182 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11183 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11184 | if (mDimTargetAlpha != target) { |
| 11185 | // If the desired dim level has changed, then |
| 11186 | // start an animation to it. |
| 11187 | mLastDimAnimTime = currentTime; |
| 11188 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11189 | ? w.mAnimation.computeDurationHint() |
| 11190 | : DEFAULT_DIM_DURATION; |
| 11191 | if (target > mDimTargetAlpha) { |
| 11192 | // This is happening behind the activity UI, |
| 11193 | // so we can make it run a little longer to |
| 11194 | // give a stronger impression without disrupting |
| 11195 | // the user. |
| 11196 | duration *= DIM_DURATION_MULTIPLIER; |
| 11197 | } |
| 11198 | if (duration < 1) { |
| 11199 | // Don't divide by zero |
| 11200 | duration = 1; |
| 11201 | } |
| 11202 | mDimTargetAlpha = target; |
| 11203 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11204 | } |
| 11205 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11206 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11207 | /** |
| 11208 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11209 | * false when the animation is finished and the dim surface is hidden. |
| 11210 | */ |
| 11211 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11212 | if (!dimming) { |
| 11213 | if (mDimTargetAlpha != 0) { |
| 11214 | mLastDimAnimTime = currentTime; |
| 11215 | mDimTargetAlpha = 0; |
| 11216 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11217 | } |
| 11218 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11219 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11220 | boolean animating = false; |
| 11221 | if (mLastDimAnimTime != 0) { |
| 11222 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11223 | * (currentTime-mLastDimAnimTime); |
| 11224 | boolean more = true; |
| 11225 | if (displayFrozen) { |
| 11226 | // If the display is frozen, there is no reason to animate. |
| 11227 | more = false; |
| 11228 | } else if (mDimDeltaPerMs > 0) { |
| 11229 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11230 | more = false; |
| 11231 | } |
| 11232 | } else if (mDimDeltaPerMs < 0) { |
| 11233 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11234 | more = false; |
| 11235 | } |
| 11236 | } else { |
| 11237 | more = false; |
| 11238 | } |
| 11239 | |
| 11240 | // Do we need to continue animating? |
| 11241 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11242 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11243 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11244 | mLastDimAnimTime = currentTime; |
| 11245 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11246 | animating = true; |
| 11247 | } else { |
| 11248 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11249 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11250 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11251 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11252 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11253 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11254 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11255 | + ": HIDE"); |
| 11256 | try { |
| 11257 | mDimSurface.hide(); |
| 11258 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11259 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11260 | } |
| 11261 | mDimShown = false; |
| 11262 | } |
| 11263 | } |
| 11264 | } |
| 11265 | return animating; |
| 11266 | } |
| 11267 | |
| 11268 | public void printTo(PrintWriter pw) { |
| 11269 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11270 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11271 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11272 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11273 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11274 | } |
| 11275 | } |
| 11276 | |
| 11277 | /** |
| 11278 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11279 | * This is used for opening/closing transition for apps in compatible mode. |
| 11280 | */ |
| 11281 | private static class FadeInOutAnimation extends Animation { |
| 11282 | int mWidth; |
| 11283 | boolean mFadeIn; |
| 11284 | |
| 11285 | public FadeInOutAnimation(boolean fadeIn) { |
| 11286 | setInterpolator(new AccelerateInterpolator()); |
| 11287 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11288 | mFadeIn = fadeIn; |
| 11289 | } |
| 11290 | |
| 11291 | @Override |
| 11292 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11293 | float x = interpolatedTime; |
| 11294 | if (!mFadeIn) { |
| 11295 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11296 | } |
| 11297 | if (x < 0.5) { |
| 11298 | // move the window out of the screen. |
| 11299 | t.getMatrix().setTranslate(mWidth, 0); |
| 11300 | } else { |
| 11301 | t.getMatrix().setTranslate(0, 0);// show |
| 11302 | t.setAlpha((x - 0.5f) * 2); |
| 11303 | } |
| 11304 | } |
| 11305 | |
| 11306 | @Override |
| 11307 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11308 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11309 | mWidth = width; |
| 11310 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11311 | |
| 11312 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11313 | public int getZAdjustment() { |
| 11314 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11315 | } |
| 11316 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11317 | } |