| 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; |
| 68 | import android.graphics.Rect; |
| 69 | import android.graphics.Region; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 70 | import android.graphics.Typeface; |
| 71 | import android.graphics.Paint.FontMetricsInt; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.BatteryStats; |
| 73 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 74 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.Debug; |
| 76 | import android.os.Handler; |
| 77 | import android.os.IBinder; |
| 78 | import android.os.LocalPowerManager; |
| 79 | import android.os.Looper; |
| 80 | import android.os.Message; |
| 81 | import android.os.Parcel; |
| 82 | import android.os.ParcelFileDescriptor; |
| 83 | import android.os.Power; |
| 84 | import android.os.PowerManager; |
| 85 | import android.os.Process; |
| 86 | import android.os.RemoteException; |
| 87 | import android.os.ServiceManager; |
| 88 | import android.os.SystemClock; |
| 89 | import android.os.SystemProperties; |
| 90 | import android.os.TokenWatcher; |
| 91 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 92 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import android.util.EventLog; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 94 | import android.util.Log; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 95 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.util.SparseIntArray; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 97 | import android.util.TypedValue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.view.Display; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 99 | import android.view.DragEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import android.view.Gravity; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 101 | import android.view.HapticFeedbackConstants; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | import android.view.IApplicationToken; |
| 103 | import android.view.IOnKeyguardExitResult; |
| 104 | import android.view.IRotationWatcher; |
| 105 | import android.view.IWindow; |
| 106 | import android.view.IWindowManager; |
| 107 | import android.view.IWindowSession; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | import android.view.InputChannel; |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 109 | import android.view.InputDevice; |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 110 | import android.view.InputEvent; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 111 | import android.view.InputHandler; |
| 112 | import android.view.InputQueue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.KeyEvent; |
| 114 | import android.view.MotionEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.Surface; |
| 116 | import android.view.SurfaceSession; |
| 117 | import android.view.View; |
| 118 | import android.view.ViewTreeObserver; |
| 119 | import android.view.WindowManager; |
| 120 | import android.view.WindowManagerImpl; |
| 121 | import android.view.WindowManagerPolicy; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 122 | import android.view.Surface.OutOfResourcesException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 124 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.animation.Animation; |
| 126 | import android.view.animation.AnimationUtils; |
| 127 | import android.view.animation.Transformation; |
| 128 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 129 | import java.io.BufferedReader; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import java.io.BufferedWriter; |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 131 | import java.io.DataInputStream; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | import java.io.File; |
| 133 | import java.io.FileDescriptor; |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 134 | import java.io.FileInputStream; |
| 135 | import java.io.FileNotFoundException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | import java.io.IOException; |
| 137 | import java.io.OutputStream; |
| 138 | import java.io.OutputStreamWriter; |
| 139 | import java.io.PrintWriter; |
| 140 | import java.io.StringWriter; |
| 141 | import java.net.Socket; |
| 142 | import java.util.ArrayList; |
| 143 | import java.util.HashMap; |
| 144 | import java.util.HashSet; |
| 145 | import java.util.Iterator; |
| 146 | import java.util.List; |
| 147 | |
| 148 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 149 | public class WindowManagerService extends IWindowManager.Stub |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 150 | implements Watchdog.Monitor { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static final String TAG = "WindowManager"; |
| 152 | static final boolean DEBUG = false; |
| 153 | static final boolean DEBUG_FOCUS = false; |
| 154 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_LAYERS = false; |
| 158 | static final boolean DEBUG_INPUT = false; |
| 159 | static final boolean DEBUG_INPUT_METHOD = false; |
| 160 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 161 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 163 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 165 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 166 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 167 | static final boolean DEBUG_WALLPAPER = false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 168 | static final boolean DEBUG_DRAG = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 170 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | static final boolean PROFILE_ORIENTATION = false; |
| 173 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 174 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 175 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | /** How much to multiply the policy's type layer, to reserve room |
| 177 | * for multiple windows of the same type and Z-ordering adjustment |
| 178 | * with TYPE_LAYER_OFFSET. */ |
| 179 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 182 | * or below others in the same layer. */ |
| 183 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 184 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | /** How much to increment the layer for each window, to reserve room |
| 186 | * for effect surfaces between them. |
| 187 | */ |
| 188 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | /** The maximum length we will accept for a loaded animation duration: |
| 191 | * this is 10 seconds. |
| 192 | */ |
| 193 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 194 | |
| 195 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 196 | * value to another, when no window animation is driving it. |
| 197 | */ |
| 198 | static final int DEFAULT_DIM_DURATION = 200; |
| 199 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 200 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 201 | * compatible windows. |
| 202 | */ |
| 203 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 206 | */ |
| 207 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 208 | |
| 209 | // Maximum number of milliseconds to wait for input event injection. |
| 210 | // FIXME is this value reasonable? |
| 211 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 212 | |
| 213 | // Default input dispatching timeout in nanoseconds. |
| 214 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 215 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 217 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 218 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 219 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 220 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 222 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 226 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 227 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 228 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 230 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 232 | private static final int ALLOW_DISABLE_YES = 1; |
| 233 | private static final int ALLOW_DISABLE_NO = 0; |
| 234 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 235 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 236 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 237 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 238 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | public void acquired() { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 240 | if (shouldAllowDisableKeyguard()) { |
| 241 | mPolicy.enableKeyguard(false); |
| 242 | mKeyguardDisabled = true; |
| 243 | } else { |
| 244 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 245 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | } |
| 247 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 248 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 249 | synchronized (mKeyguardTokenWatcher) { |
| 250 | mKeyguardDisabled = false; |
| 251 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | }; |
| 255 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 256 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 257 | @Override |
| 258 | public void onReceive(Context context, Intent intent) { |
| 259 | mPolicy.enableKeyguard(true); |
| 260 | synchronized(mKeyguardTokenWatcher) { |
| 261 | // lazily evaluate this next time we're asked to disable keyguard |
| 262 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 263 | mKeyguardDisabled = false; |
| 264 | } |
| 265 | } |
| 266 | }; |
| 267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | final Context mContext; |
| 269 | |
| 270 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 271 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 273 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 275 | |
| 276 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | /** |
| 281 | * All currently active sessions with clients. |
| 282 | */ |
| 283 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | /** |
| 286 | * Mapping from an IWindow IBinder to the server's Window object. |
| 287 | * This is also used as the lock for all of our state. |
| 288 | */ |
| 289 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 290 | |
| 291 | /** |
| 292 | * Mapping from a token IBinder to a WindowToken object. |
| 293 | */ |
| 294 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 295 | new HashMap<IBinder, WindowToken>(); |
| 296 | |
| 297 | /** |
| 298 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 299 | * over them. |
| 300 | */ |
| 301 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | /** |
| 304 | * Window tokens that are in the process of exiting, but still |
| 305 | * on screen for animations. |
| 306 | */ |
| 307 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 308 | |
| 309 | /** |
| 310 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 311 | * controlling the ordering of windows in different applications. This |
| 312 | * contains WindowToken objects. |
| 313 | */ |
| 314 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 315 | |
| 316 | /** |
| 317 | * Application tokens that are in the process of exiting, but still |
| 318 | * on screen for animations. |
| 319 | */ |
| 320 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 321 | |
| 322 | /** |
| 323 | * List of window tokens that have finished starting their application, |
| 324 | * and now need to have the policy remove their windows. |
| 325 | */ |
| 326 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 327 | |
| 328 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 329 | * This was the app token that was used to retrieve the last enter |
| 330 | * animation. It will be used for the next exit animation. |
| 331 | */ |
| 332 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 333 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 334 | /** |
| 335 | * These were the layout params used to retrieve the last enter animation. |
| 336 | * They will be used for the next exit animation. |
| 337 | */ |
| 338 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 339 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 340 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | * Z-ordered (bottom-most first) list of all Window objects. |
| 342 | */ |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 343 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * Windows that are being resized. Used so we can tell the client about |
| 347 | * the resize after closing the transaction in which we resized the |
| 348 | * underlying surface. |
| 349 | */ |
| 350 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 351 | |
| 352 | /** |
| 353 | * Windows whose animations have ended and now must be removed. |
| 354 | */ |
| 355 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 356 | |
| 357 | /** |
| 358 | * Windows whose surface should be destroyed. |
| 359 | */ |
| 360 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 361 | |
| 362 | /** |
| 363 | * Windows that have lost input focus and are waiting for the new |
| 364 | * focus window to be displayed before they are told about this. |
| 365 | */ |
| 366 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 367 | |
| 368 | /** |
| 369 | * This is set when we have run out of memory, and will either be an empty |
| 370 | * list or contain windows that need to be force removed. |
| 371 | */ |
| 372 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 377 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | Surface mBlurSurface; |
| 379 | boolean mBlurShown; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 380 | Watermark mWatermark; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 381 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | final float[] mTmpFloats = new float[9]; |
| 385 | |
| 386 | boolean mSafeMode; |
| 387 | boolean mDisplayEnabled = false; |
| 388 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 389 | int mInitialDisplayWidth = 0; |
| 390 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | int mRotation = 0; |
| 392 | int mRequestedRotation = 0; |
| 393 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 394 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | ArrayList<IRotationWatcher> mRotationWatchers |
| 396 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 397 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | boolean mLayoutNeeded = true; |
| 399 | boolean mAnimationPending = false; |
| 400 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 401 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | boolean mWindowsFreezingScreen = false; |
| 403 | long mFreezeGcPending = 0; |
| 404 | int mAppsFreezingScreen = 0; |
| 405 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 406 | int mLayoutSeq = 0; |
| 407 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 408 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 409 | boolean mFocusMayChange; |
| 410 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 411 | Configuration mCurConfiguration = new Configuration(); |
| 412 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | // This is held as long as we have the screen frozen, to give us time to |
| 414 | // perform a rotation animation when turning off shows the lock screen which |
| 415 | // changes the orientation. |
| 416 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | // State management of app transitions. When we are preparing for a |
| 419 | // transition, mNextAppTransition will be the kind of transition to |
| 420 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 421 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 422 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 423 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 424 | String mNextAppTransitionPackage; |
| 425 | int mNextAppTransitionEnter; |
| 426 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 428 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | boolean mAppTransitionTimeout = false; |
| 430 | boolean mStartingIconInTransition = false; |
| 431 | boolean mSkipAppTransitionAnimation = false; |
| 432 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 433 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 434 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 435 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 438 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | H mH = new H(); |
| 440 | |
| 441 | WindowState mCurrentFocus = null; |
| 442 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 443 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | // This just indicates the window the input method is on top of, not |
| 445 | // necessarily the window its input is going to. |
| 446 | WindowState mInputMethodTarget = null; |
| 447 | WindowState mUpcomingInputMethodTarget = null; |
| 448 | boolean mInputMethodTargetWaitingAnim; |
| 449 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | WindowState mInputMethodWindow = null; |
| 452 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 453 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 454 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 455 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 456 | // If non-null, this is the currently visible window that is associated |
| 457 | // with the wallpaper. |
| 458 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 459 | // If non-null, we are in the middle of animating from one wallpaper target |
| 460 | // to another, and this is the lower one in Z-order. |
| 461 | WindowState mLowerWallpaperTarget = null; |
| 462 | // If non-null, we are in the middle of animating from one wallpaper target |
| 463 | // to another, and this is the higher one in Z-order. |
| 464 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 465 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 466 | float mLastWallpaperX = -1; |
| 467 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 468 | float mLastWallpaperXStep = -1; |
| 469 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 470 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 471 | // changing its scroll position. |
| 472 | WindowState mWaitingOnWallpaper; |
| 473 | // The last time we had a timeout when waiting for a wallpaper. |
| 474 | long mLastWallpaperTimeoutTime; |
| 475 | // We give a wallpaper up to 150ms to finish scrolling. |
| 476 | static final long WALLPAPER_TIMEOUT = 150; |
| 477 | // Time we wait after a timeout before trying to wait again. |
| 478 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | AppWindowToken mFocusedApp = null; |
| 481 | |
| 482 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | float mWindowAnimationScale = 1.0f; |
| 485 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 486 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 487 | final InputManager mInputManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | |
| 489 | // Who is holding the screen on. |
| 490 | Session mHoldingScreenOn; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 491 | PowerManager.WakeLock mHoldingScreenWakeLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 492 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 493 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 496 | * Drag/drop state |
| 497 | */ |
| 498 | class DragState { |
| 499 | IBinder mToken; |
| 500 | Surface mSurface; |
| 501 | boolean mLocalOnly; |
| 502 | ClipData mData; |
| 503 | ClipDescription mDataDescription; |
| 504 | float mThumbOffsetX, mThumbOffsetY; |
| 505 | InputChannel mServerChannel, mClientChannel; |
| 506 | WindowState mTargetWindow; |
| 507 | ArrayList<WindowState> mNotifiedWindows; |
| 508 | boolean mDragEnded; |
| 509 | |
| 510 | private final Rect tmpRect = new Rect(); |
| 511 | |
| 512 | DragState(IBinder token, Surface surface, boolean localOnly) { |
| 513 | mToken = token; |
| 514 | mSurface = surface; |
| 515 | mLocalOnly = localOnly; |
| 516 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 517 | } |
| 518 | |
| 519 | void reset() { |
| 520 | if (mSurface != null) { |
| 521 | mSurface.destroy(); |
| 522 | } |
| 523 | mSurface = null; |
| 524 | mLocalOnly = false; |
| 525 | mToken = null; |
| 526 | mData = null; |
| 527 | mThumbOffsetX = mThumbOffsetY = 0; |
| 528 | mNotifiedWindows = null; |
| 529 | } |
| 530 | |
| 531 | void register() { |
| 532 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 533 | if (mClientChannel != null) { |
| 534 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 535 | } else { |
| 536 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 537 | mServerChannel = channels[0]; |
| 538 | mClientChannel = channels[1]; |
| 539 | mInputManager.registerInputChannel(mServerChannel); |
| 540 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 541 | mH.getLooper().getQueue()); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | void unregister() { |
| 546 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 547 | if (mClientChannel == null) { |
| 548 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 549 | } else { |
| 550 | mInputManager.unregisterInputChannel(mServerChannel); |
| 551 | InputQueue.unregisterInputChannel(mClientChannel); |
| 552 | mClientChannel.dispose(); |
| 553 | mClientChannel = null; |
| 554 | mServerChannel = null; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | /* call out to each visible window/session informing it about the drag |
| 559 | */ |
| 560 | void broadcastDragStartedLw() { |
| 561 | // Cache a base-class instance of the clip metadata so that parceling |
| 562 | // works correctly in calling out to the apps. |
| 563 | mDataDescription = new ClipDescription(mData); |
| 564 | mNotifiedWindows.clear(); |
| 565 | |
| 566 | if (DEBUG_DRAG) { |
| 567 | Slog.d(TAG, "broadcasting DRAG_STARTED of " + mDataDescription); |
| 568 | } |
| 569 | |
| 570 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0, |
| 571 | mDataDescription, null); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 572 | final int N = mWindows.size(); |
| 573 | for (int i = 0; i < N; i++) { |
| 574 | // sendDragStartedLw() clones evt for local-process dispatch |
| 575 | sendDragStartedLw(mWindows.get(i), evt); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 576 | } |
| 577 | evt.recycle(); |
| 578 | } |
| 579 | |
| 580 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 581 | * designated window is potentially a drop recipient. There are race situations |
| 582 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 583 | * 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] | 584 | * |
| 585 | * This method clones the 'event' parameter if it's being delivered to the same |
| 586 | * 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] | 587 | */ |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 588 | private void sendDragStartedLw(WindowState newWin, DragEvent event) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 589 | if (!mDragEnded && newWin.isPotentialDragTarget()) { |
| 590 | try { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 591 | // clone for local callees since dispatch will recycle the event |
| 592 | if (Process.myPid() == newWin.mSession.mPid) { |
| 593 | event = DragEvent.obtain(event); |
| 594 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 595 | newWin.mClient.dispatchDragEvent(event); |
| 596 | // track each window that we've notified that the drag is starting |
| 597 | mNotifiedWindows.add(newWin); |
| 598 | } catch (RemoteException e) { |
| 599 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 605 | * previously been notified, i.e. it became visible after the drag operation |
| 606 | * was begun. This is a rare case. |
| 607 | */ |
| 608 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
| 609 | // If we have sent the drag-started, we needn't do so again |
| 610 | for (WindowState ws : mNotifiedWindows) { |
| 611 | if (ws == newWin) { |
| 612 | return; |
| 613 | } |
| 614 | } |
| 615 | if (DEBUG_DRAG) { |
| 616 | Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin); |
| 617 | } |
| 618 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0, |
| 619 | mDataDescription, null); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 620 | // sendDragStartedLw() clones 'event' if the window is process-local |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 621 | sendDragStartedLw(newWin, event); |
| 622 | event.recycle(); |
| 623 | } |
| 624 | |
| 625 | void broadcastDragEnded() { |
| 626 | if (DEBUG_DRAG) { |
| 627 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 628 | } |
| 629 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, 0, 0, null, null); |
| 630 | synchronized (mWindowMap) { |
| 631 | for (WindowState ws: mNotifiedWindows) { |
| 632 | try { |
| 633 | ws.mClient.dispatchDragEvent(evt); |
| 634 | } catch (RemoteException e) { |
| 635 | Slog.w(TAG, "Unable to drag-end window " + ws); |
| 636 | } |
| 637 | } |
| 638 | mNotifiedWindows.clear(); |
| 639 | mDragEnded = true; |
| 640 | } |
| 641 | evt.recycle(); |
| 642 | } |
| 643 | |
| 644 | void notifyMoveLw(float x, float y) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 645 | final int myPid = Process.myPid(); |
| 646 | |
| 647 | // Move the surface to the given touch |
| 648 | mSurface.openTransaction(); |
| 649 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 650 | mSurface.closeTransaction(); |
| 651 | |
| 652 | // Tell the affected window |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 653 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| 654 | try { |
| 655 | // have we dragged over a new window? |
| 656 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 657 | if (DEBUG_DRAG) { |
| 658 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 659 | } |
| 660 | // force DRAG_EXITED_EVENT if appropriate |
| 661 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
| 662 | 0, 0, null, null); |
| 663 | mTargetWindow.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 664 | if (myPid != mTargetWindow.mSession.mPid) { |
| 665 | evt.recycle(); |
| 666 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 667 | } |
| 668 | if (touchedWin != null) { |
| 669 | if (DEBUG_DRAG) { |
| 670 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 671 | } |
| 672 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
| 673 | x, y, null, null); |
| 674 | touchedWin.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 675 | if (myPid != touchedWin.mSession.mPid) { |
| 676 | evt.recycle(); |
| 677 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 678 | } |
| 679 | } catch (RemoteException e) { |
| 680 | Slog.w(TAG, "can't send drag notification to windows"); |
| 681 | } |
| 682 | mTargetWindow = touchedWin; |
| 683 | } |
| 684 | |
| 685 | // Tell the drop target about the data, and then broadcast the drag-ended notification |
| 686 | void notifyDropLw(float x, float y) { |
| 687 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| 688 | if (touchedWin != null) { |
| 689 | if (DEBUG_DRAG) { |
| 690 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 691 | } |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 692 | final int myPid = Process.myPid(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 693 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, x, y, null, mData); |
| 694 | try { |
| 695 | touchedWin.mClient.dispatchDragEvent(evt); |
| 696 | } catch (RemoteException e) { |
| 697 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 698 | } |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 699 | if (myPid != touchedWin.mSession.mPid) { |
| 700 | evt.recycle(); |
| 701 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
| 705 | // Find the visible, touch-deliverable window under the given point |
| 706 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 707 | WindowState touchedWin = null; |
| 708 | final int x = (int) xf; |
| 709 | final int y = (int) yf; |
| 710 | final ArrayList<WindowState> windows = mWindows; |
| 711 | final int N = windows.size(); |
| 712 | for (int i = N - 1; i >= 0; i--) { |
| 713 | WindowState child = windows.get(i); |
| 714 | final int flags = child.mAttrs.flags; |
| 715 | if (!child.isVisibleLw()) { |
| 716 | // not visible == don't tell about drags |
| 717 | continue; |
| 718 | } |
| 719 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 720 | // not touchable == don't tell about drags |
| 721 | continue; |
| 722 | } |
| 723 | // account for the window's decor etc |
| 724 | tmpRect.set(child.mFrame); |
| 725 | if (child.mTouchableInsets == ViewTreeObserver |
| 726 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 727 | // The point is inside of the window if it is |
| 728 | // inside the frame, AND the content part of that |
| 729 | // frame that was given by the application. |
| 730 | tmpRect.left += child.mGivenContentInsets.left; |
| 731 | tmpRect.top += child.mGivenContentInsets.top; |
| 732 | tmpRect.right -= child.mGivenContentInsets.right; |
| 733 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 734 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 735 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 736 | // The point is inside of the window if it is |
| 737 | // inside the frame, AND the visible part of that |
| 738 | // frame that was given by the application. |
| 739 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 740 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 741 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 742 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 743 | } |
| 744 | final int touchFlags = flags & |
| 745 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 746 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 747 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 748 | // Found it |
| 749 | touchedWin = child; |
| 750 | break; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | return touchedWin; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | DragState mDragState = null; |
| 759 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 760 | @Override |
| 761 | public void handleMotion(MotionEvent event, Runnable finishedCallback) { |
| 762 | boolean endDrag = false; |
| 763 | final float newX = event.getRawX(); |
| 764 | final float newY = event.getRawY(); |
| 765 | |
| 766 | try { |
| 767 | if (mDragState != null) { |
| 768 | switch (event.getAction()) { |
| 769 | case MotionEvent.ACTION_DOWN: { |
| 770 | if (DEBUG_DRAG) { |
| 771 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 772 | } |
| 773 | } break; |
| 774 | |
| 775 | case MotionEvent.ACTION_MOVE: { |
| 776 | synchronized (mWindowMap) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 777 | // move the surface and tell the involved window(s) where we are |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 778 | mDragState.notifyMoveLw(newX, newY); |
| 779 | } |
| 780 | } break; |
| 781 | |
| 782 | case MotionEvent.ACTION_UP: { |
| 783 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 784 | + newX + "," + newY); |
| 785 | synchronized (mWindowMap) { |
| 786 | mDragState.notifyDropLw(newX, newY); |
| 787 | } |
| 788 | endDrag = true; |
| 789 | } break; |
| 790 | |
| 791 | case MotionEvent.ACTION_CANCEL: { |
| 792 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 793 | endDrag = true; |
| 794 | } break; |
| 795 | } |
| 796 | |
| 797 | if (endDrag) { |
| 798 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 799 | // tell all the windows that the drag has ended |
| 800 | mDragState.broadcastDragEnded(); |
| 801 | |
| 802 | // stop intercepting input |
| 803 | mDragState.unregister(); |
| 804 | mInputMonitor.updateInputWindowsLw(); |
| 805 | |
| 806 | // free our resources and drop all the object references |
| 807 | mDragState.reset(); |
| 808 | mDragState = null; |
| 809 | } |
| 810 | } |
| 811 | } catch (Exception e) { |
| 812 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 813 | } finally { |
| 814 | finishedCallback.run(); |
| 815 | } |
| 816 | } |
| 817 | }; |
| 818 | |
| 819 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | * Whether the UI is currently running in touch mode (not showing |
| 821 | * navigational focus because the user is directly pressing the screen). |
| 822 | */ |
| 823 | boolean mInTouchMode = false; |
| 824 | |
| 825 | private ViewServer mViewServer; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 826 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 827 | new ArrayList<WindowChangeListener>(); |
| 828 | private boolean mWindowsChanged = false; |
| 829 | |
| 830 | public interface WindowChangeListener { |
| 831 | public void windowsChanged(); |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 832 | public void focusChanged(); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 833 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 835 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 836 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 837 | |
| 838 | // The frame use to limit the size of the app running in compatibility mode. |
| 839 | Rect mCompatibleScreenFrame = new Rect(); |
| 840 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 841 | Surface mBackgroundFillerSurface = null; |
| 842 | boolean mBackgroundFillerShown = false; |
| 843 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | public static WindowManagerService main(Context context, |
| 845 | PowerManagerService pm, boolean haveInputMethods) { |
| 846 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 847 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 848 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | synchronized (thr) { |
| 850 | while (thr.mService == null) { |
| 851 | try { |
| 852 | thr.wait(); |
| 853 | } catch (InterruptedException e) { |
| 854 | } |
| 855 | } |
| 856 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 857 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | return thr.mService; |
| 859 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 860 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | static class WMThread extends Thread { |
| 862 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | private final Context mContext; |
| 865 | private final PowerManagerService mPM; |
| 866 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 867 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | public WMThread(Context context, PowerManagerService pm, |
| 869 | boolean haveInputMethods) { |
| 870 | super("WindowManager"); |
| 871 | mContext = context; |
| 872 | mPM = pm; |
| 873 | mHaveInputMethods = haveInputMethods; |
| 874 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 875 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | public void run() { |
| 877 | Looper.prepare(); |
| 878 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 879 | mHaveInputMethods); |
| 880 | android.os.Process.setThreadPriority( |
| 881 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 882 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 883 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | synchronized (this) { |
| 885 | mService = s; |
| 886 | notifyAll(); |
| 887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | Looper.loop(); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | static class PolicyThread extends Thread { |
| 894 | private final WindowManagerPolicy mPolicy; |
| 895 | private final WindowManagerService mService; |
| 896 | private final Context mContext; |
| 897 | private final PowerManagerService mPM; |
| 898 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | public PolicyThread(WindowManagerPolicy policy, |
| 901 | WindowManagerService service, Context context, |
| 902 | PowerManagerService pm) { |
| 903 | super("WindowManagerPolicy"); |
| 904 | mPolicy = policy; |
| 905 | mService = service; |
| 906 | mContext = context; |
| 907 | mPM = pm; |
| 908 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 909 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | public void run() { |
| 911 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 912 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 913 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 915 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | android.os.Process.setThreadPriority( |
| 917 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 918 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 920 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | synchronized (this) { |
| 922 | mRunning = true; |
| 923 | notifyAll(); |
| 924 | } |
| 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 | Looper.loop(); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | private WindowManagerService(Context context, PowerManagerService pm, |
| 931 | boolean haveInputMethods) { |
| 932 | mContext = context; |
| 933 | mHaveInputMethods = haveInputMethods; |
| 934 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 935 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 936 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | mPowerManager = pm; |
| 938 | mPowerManager.setPolicy(mPolicy); |
| 939 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 940 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 941 | "SCREEN_FROZEN"); |
| 942 | mScreenFrozenLock.setReferenceCounted(false); |
| 943 | |
| 944 | mActivityManager = ActivityManagerNative.getDefault(); |
| 945 | mBatteryStats = BatteryStatsService.getService(); |
| 946 | |
| 947 | // Get persisted window scale setting |
| 948 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 949 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 950 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 951 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 952 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 953 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 954 | IntentFilter filter = new IntentFilter(); |
| 955 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 956 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 957 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 958 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 959 | "KEEP_SCREEN_ON_FLAG"); |
| 960 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 962 | mInputManager = new InputManager(context, this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 963 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 965 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 966 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | synchronized (thr) { |
| 968 | while (!thr.mRunning) { |
| 969 | try { |
| 970 | thr.wait(); |
| 971 | } catch (InterruptedException e) { |
| 972 | } |
| 973 | } |
| 974 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 975 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 976 | mInputManager.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | // Add ourself to the Watchdog monitors. |
| 979 | Watchdog.getInstance().addMonitor(this); |
| 980 | } |
| 981 | |
| 982 | @Override |
| 983 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 984 | throws RemoteException { |
| 985 | try { |
| 986 | return super.onTransact(code, data, reply, flags); |
| 987 | } catch (RuntimeException e) { |
| 988 | // The window manager only throws security exceptions, so let's |
| 989 | // log all others. |
| 990 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 991 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | } |
| 993 | throw e; |
| 994 | } |
| 995 | } |
| 996 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 997 | private void placeWindowAfter(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 999 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | TAG, "Adding window " + window + " at " |
| 1001 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1002 | mWindows.add(i+1, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1003 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1006 | private void placeWindowBefore(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1008 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | TAG, "Adding window " + window + " at " |
| 1010 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1011 | mWindows.add(i, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1012 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | //This method finds out the index of a window that has the same app token as |
| 1016 | //win. used for z ordering the windows in mWindows |
| 1017 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1018 | //use a local variable to cache mWindows |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1019 | ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | int jmax = localmWindows.size(); |
| 1021 | if(jmax == 0) { |
| 1022 | return -1; |
| 1023 | } |
| 1024 | for(int j = (jmax-1); j >= 0; j--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1025 | WindowState wentry = localmWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1026 | if(wentry.mAppToken == win.mAppToken) { |
| 1027 | return j; |
| 1028 | } |
| 1029 | } |
| 1030 | return -1; |
| 1031 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1032 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1034 | final IWindow client = win.mClient; |
| 1035 | final WindowToken token = win.mToken; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1036 | final ArrayList<WindowState> localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1037 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | final int N = localmWindows.size(); |
| 1039 | final WindowState attached = win.mAttachedWindow; |
| 1040 | int i; |
| 1041 | if (attached == null) { |
| 1042 | int tokenWindowsPos = token.windows.size(); |
| 1043 | if (token.appWindowToken != null) { |
| 1044 | int index = tokenWindowsPos-1; |
| 1045 | if (index >= 0) { |
| 1046 | // If this application has existing windows, we |
| 1047 | // simply place the new window on top of them... but |
| 1048 | // keep the starting window on top. |
| 1049 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1050 | // Base windows go behind everything else. |
| 1051 | placeWindowBefore(token.windows.get(0), win); |
| 1052 | tokenWindowsPos = 0; |
| 1053 | } else { |
| 1054 | AppWindowToken atoken = win.mAppToken; |
| 1055 | if (atoken != null && |
| 1056 | token.windows.get(index) == atoken.startingWindow) { |
| 1057 | placeWindowBefore(token.windows.get(index), win); |
| 1058 | tokenWindowsPos--; |
| 1059 | } else { |
| 1060 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1061 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1062 | //there is a window above this one associated with the same |
| 1063 | //apptoken note that the window could be a floating window |
| 1064 | //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] | 1065 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1066 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1067 | TAG, "Adding window " + win + " at " |
| 1068 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | localmWindows.add(newIdx+1, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1070 | mWindowsChanged = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1071 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1075 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | TAG, "Figuring out where to add app window " |
| 1077 | + client.asBinder() + " (token=" + token + ")"); |
| 1078 | // Figure out where the window should go, based on the |
| 1079 | // order of applications. |
| 1080 | final int NA = mAppTokens.size(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1081 | WindowState pos = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | for (i=NA-1; i>=0; i--) { |
| 1083 | AppWindowToken t = mAppTokens.get(i); |
| 1084 | if (t == token) { |
| 1085 | i--; |
| 1086 | break; |
| 1087 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1088 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1089 | // We haven't reached the token yet; if this token |
| 1090 | // is not going to the bottom and has windows, we can |
| 1091 | // use it as an anchor for when we do reach the token. |
| 1092 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | pos = t.windows.get(0); |
| 1094 | } |
| 1095 | } |
| 1096 | // We now know the index into the apps. If we found |
| 1097 | // an app window above, that gives us the position; else |
| 1098 | // we need to look some more. |
| 1099 | if (pos != null) { |
| 1100 | // Move behind any windows attached to this one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1101 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | if (atoken != null) { |
| 1103 | final int NC = atoken.windows.size(); |
| 1104 | if (NC > 0) { |
| 1105 | WindowState bottom = atoken.windows.get(0); |
| 1106 | if (bottom.mSubLayer < 0) { |
| 1107 | pos = bottom; |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | placeWindowBefore(pos, win); |
| 1112 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1113 | // Continue looking down until we find the first |
| 1114 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | while (i >= 0) { |
| 1116 | AppWindowToken t = mAppTokens.get(i); |
| 1117 | final int NW = t.windows.size(); |
| 1118 | if (NW > 0) { |
| 1119 | pos = t.windows.get(NW-1); |
| 1120 | break; |
| 1121 | } |
| 1122 | i--; |
| 1123 | } |
| 1124 | if (pos != null) { |
| 1125 | // Move in front of any windows attached to this |
| 1126 | // one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1127 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | if (atoken != null) { |
| 1129 | final int NC = atoken.windows.size(); |
| 1130 | if (NC > 0) { |
| 1131 | WindowState top = atoken.windows.get(NC-1); |
| 1132 | if (top.mSubLayer >= 0) { |
| 1133 | pos = top; |
| 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | placeWindowAfter(pos, win); |
| 1138 | } else { |
| 1139 | // Just search for the start of this layer. |
| 1140 | final int myLayer = win.mBaseLayer; |
| 1141 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1142 | WindowState w = localmWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | if (w.mBaseLayer > myLayer) { |
| 1144 | break; |
| 1145 | } |
| 1146 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1147 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1148 | TAG, "Adding window " + win + " at " |
| 1149 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1151 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | } else { |
| 1156 | // Figure out where window should go, based on layer. |
| 1157 | final int myLayer = win.mBaseLayer; |
| 1158 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1159 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | i++; |
| 1161 | break; |
| 1162 | } |
| 1163 | } |
| 1164 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1165 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1166 | TAG, "Adding window " + win + " at " |
| 1167 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1169 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | } |
| 1171 | if (addToToken) { |
| 1172 | token.windows.add(tokenWindowsPos, win); |
| 1173 | } |
| 1174 | |
| 1175 | } else { |
| 1176 | // Figure out this window's ordering relative to the window |
| 1177 | // it is attached to. |
| 1178 | final int NA = token.windows.size(); |
| 1179 | final int sublayer = win.mSubLayer; |
| 1180 | int largestSublayer = Integer.MIN_VALUE; |
| 1181 | WindowState windowWithLargestSublayer = null; |
| 1182 | for (i=0; i<NA; i++) { |
| 1183 | WindowState w = token.windows.get(i); |
| 1184 | final int wSublayer = w.mSubLayer; |
| 1185 | if (wSublayer >= largestSublayer) { |
| 1186 | largestSublayer = wSublayer; |
| 1187 | windowWithLargestSublayer = w; |
| 1188 | } |
| 1189 | if (sublayer < 0) { |
| 1190 | // For negative sublayers, we go below all windows |
| 1191 | // in the same sublayer. |
| 1192 | if (wSublayer >= sublayer) { |
| 1193 | if (addToToken) { |
| 1194 | token.windows.add(i, win); |
| 1195 | } |
| 1196 | placeWindowBefore( |
| 1197 | wSublayer >= 0 ? attached : w, win); |
| 1198 | break; |
| 1199 | } |
| 1200 | } else { |
| 1201 | // For positive sublayers, we go above all windows |
| 1202 | // in the same sublayer. |
| 1203 | if (wSublayer > sublayer) { |
| 1204 | if (addToToken) { |
| 1205 | token.windows.add(i, win); |
| 1206 | } |
| 1207 | placeWindowBefore(w, win); |
| 1208 | break; |
| 1209 | } |
| 1210 | } |
| 1211 | } |
| 1212 | if (i >= NA) { |
| 1213 | if (addToToken) { |
| 1214 | token.windows.add(win); |
| 1215 | } |
| 1216 | if (sublayer < 0) { |
| 1217 | placeWindowBefore(attached, win); |
| 1218 | } else { |
| 1219 | placeWindowAfter(largestSublayer >= 0 |
| 1220 | ? windowWithLargestSublayer |
| 1221 | : attached, |
| 1222 | win); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1226 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | if (win.mAppToken != null && addToToken) { |
| 1228 | win.mAppToken.allAppWindows.add(win); |
| 1229 | } |
| 1230 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1231 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | static boolean canBeImeTarget(WindowState w) { |
| 1233 | final int fl = w.mAttrs.flags |
| 1234 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1235 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1236 | return w.isVisibleOrAdding(); |
| 1237 | } |
| 1238 | return false; |
| 1239 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1242 | final ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | final int N = localmWindows.size(); |
| 1244 | WindowState w = null; |
| 1245 | int i = N; |
| 1246 | while (i > 0) { |
| 1247 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1248 | w = localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1249 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1250 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1252 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1253 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1254 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | // Yet more tricksyness! If this window is a "starting" |
| 1256 | // window, we do actually want to be on top of it, but |
| 1257 | // it is not -really- where input will go. So if the caller |
| 1258 | // is not actually looking to move the IME, look down below |
| 1259 | // for a real window to target... |
| 1260 | if (!willMove |
| 1261 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1262 | && i > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1263 | WindowState wb = localmWindows.get(i-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1265 | i--; |
| 1266 | w = wb; |
| 1267 | } |
| 1268 | } |
| 1269 | break; |
| 1270 | } |
| 1271 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1274 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1275 | 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] | 1276 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | if (willMove && w != null) { |
| 1279 | final WindowState curTarget = mInputMethodTarget; |
| 1280 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | // Now some fun for dealing with window animations that |
| 1283 | // modify the Z order. We need to look at all windows below |
| 1284 | // the current target that are in this app, finding the highest |
| 1285 | // visible one in layering. |
| 1286 | AppWindowToken token = curTarget.mAppToken; |
| 1287 | WindowState highestTarget = null; |
| 1288 | int highestPos = 0; |
| 1289 | if (token.animating || token.animation != null) { |
| 1290 | int pos = 0; |
| 1291 | pos = localmWindows.indexOf(curTarget); |
| 1292 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1293 | WindowState win = localmWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | if (win.mAppToken != token) { |
| 1295 | break; |
| 1296 | } |
| 1297 | if (!win.mRemoved) { |
| 1298 | if (highestTarget == null || win.mAnimLayer > |
| 1299 | highestTarget.mAnimLayer) { |
| 1300 | highestTarget = win; |
| 1301 | highestPos = pos; |
| 1302 | } |
| 1303 | } |
| 1304 | pos--; |
| 1305 | } |
| 1306 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1309 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | + mNextAppTransition + " " + highestTarget |
| 1311 | + " animating=" + highestTarget.isAnimating() |
| 1312 | + " layer=" + highestTarget.mAnimLayer |
| 1313 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1314 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1315 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | // If we are currently setting up for an animation, |
| 1317 | // hold everything until we can find out what will happen. |
| 1318 | mInputMethodTargetWaitingAnim = true; |
| 1319 | mInputMethodTarget = highestTarget; |
| 1320 | return highestPos + 1; |
| 1321 | } else if (highestTarget.isAnimating() && |
| 1322 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1323 | // If the window we are currently targeting is involved |
| 1324 | // with an animation, and it is on top of the next target |
| 1325 | // we will be over, then hold off on moving until |
| 1326 | // that is done. |
| 1327 | mInputMethodTarget = highestTarget; |
| 1328 | return highestPos + 1; |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1333 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1334 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1335 | if (w != null) { |
| 1336 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1337 | if (DEBUG_INPUT_METHOD) { |
| 1338 | RuntimeException e = null; |
| 1339 | if (!HIDE_STACK_CRAWLS) { |
| 1340 | e = new RuntimeException(); |
| 1341 | e.fillInStackTrace(); |
| 1342 | } |
| 1343 | Slog.w(TAG, "Moving IM target from " |
| 1344 | + mInputMethodTarget + " to " + w, e); |
| 1345 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1346 | mInputMethodTarget = w; |
| 1347 | if (w.mAppToken != null) { |
| 1348 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1349 | } else { |
| 1350 | setInputMethodAnimLayerAdjustment(0); |
| 1351 | } |
| 1352 | } |
| 1353 | return i+1; |
| 1354 | } |
| 1355 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1356 | if (DEBUG_INPUT_METHOD) { |
| 1357 | RuntimeException e = null; |
| 1358 | if (!HIDE_STACK_CRAWLS) { |
| 1359 | e = new RuntimeException(); |
| 1360 | e.fillInStackTrace(); |
| 1361 | } |
| 1362 | Slog.w(TAG, "Moving IM target from " |
| 1363 | + mInputMethodTarget + " to null", e); |
| 1364 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1365 | mInputMethodTarget = null; |
| 1366 | setInputMethodAnimLayerAdjustment(0); |
| 1367 | } |
| 1368 | return -1; |
| 1369 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1370 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1372 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1373 | if (pos >= 0) { |
| 1374 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1375 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1376 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | mWindows.add(pos, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1378 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | moveInputMethodDialogsLocked(pos+1); |
| 1380 | return; |
| 1381 | } |
| 1382 | win.mTargetAppToken = null; |
| 1383 | addWindowToListInOrderLocked(win, true); |
| 1384 | moveInputMethodDialogsLocked(pos); |
| 1385 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1386 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1387 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1388 | 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] | 1389 | mInputMethodAnimLayerAdjustment = adj; |
| 1390 | WindowState imw = mInputMethodWindow; |
| 1391 | if (imw != null) { |
| 1392 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1393 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | + " anim layer: " + imw.mAnimLayer); |
| 1395 | int wi = imw.mChildWindows.size(); |
| 1396 | while (wi > 0) { |
| 1397 | wi--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1398 | WindowState cw = imw.mChildWindows.get(wi); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1400 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1401 | + " anim layer: " + cw.mAnimLayer); |
| 1402 | } |
| 1403 | } |
| 1404 | int di = mInputMethodDialogs.size(); |
| 1405 | while (di > 0) { |
| 1406 | di --; |
| 1407 | imw = mInputMethodDialogs.get(di); |
| 1408 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1409 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | + " anim layer: " + imw.mAnimLayer); |
| 1411 | } |
| 1412 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1413 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1414 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1415 | int wpos = mWindows.indexOf(win); |
| 1416 | if (wpos >= 0) { |
| 1417 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1418 | 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] | 1419 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1420 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1421 | int NC = win.mChildWindows.size(); |
| 1422 | while (NC > 0) { |
| 1423 | NC--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1424 | WindowState cw = win.mChildWindows.get(NC); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | int cpos = mWindows.indexOf(cw); |
| 1426 | if (cpos >= 0) { |
| 1427 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1428 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1429 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1430 | mWindows.remove(cpos); |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | return interestingPos; |
| 1435 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1437 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1438 | addWindowToListInOrderLocked(win, false); |
| 1439 | // This is a hack to get all of the child windows added as well |
| 1440 | // at the right position. Child windows should be rare and |
| 1441 | // this case should be rare, so it shouldn't be that big a deal. |
| 1442 | int wpos = mWindows.indexOf(win); |
| 1443 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1444 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1445 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1447 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1448 | reAddWindowLocked(wpos, win); |
| 1449 | } |
| 1450 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | void logWindowList(String prefix) { |
| 1453 | int N = mWindows.size(); |
| 1454 | while (N > 0) { |
| 1455 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1456 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1457 | } |
| 1458 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | void moveInputMethodDialogsLocked(int pos) { |
| 1461 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1464 | 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] | 1465 | for (int i=0; i<N; i++) { |
| 1466 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1467 | } |
| 1468 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1469 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | logWindowList(" "); |
| 1471 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | if (pos >= 0) { |
| 1474 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1475 | if (pos < mWindows.size()) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1476 | WindowState wp = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | if (wp == mInputMethodWindow) { |
| 1478 | pos++; |
| 1479 | } |
| 1480 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1481 | 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] | 1482 | for (int i=0; i<N; i++) { |
| 1483 | WindowState win = dialogs.get(i); |
| 1484 | win.mTargetAppToken = targetAppToken; |
| 1485 | pos = reAddWindowLocked(pos, win); |
| 1486 | } |
| 1487 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1488 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | logWindowList(" "); |
| 1490 | } |
| 1491 | return; |
| 1492 | } |
| 1493 | for (int i=0; i<N; i++) { |
| 1494 | WindowState win = dialogs.get(i); |
| 1495 | win.mTargetAppToken = null; |
| 1496 | reAddWindowToListInOrderLocked(win); |
| 1497 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1498 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | logWindowList(" "); |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1504 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1505 | final WindowState imWin = mInputMethodWindow; |
| 1506 | final int DN = mInputMethodDialogs.size(); |
| 1507 | if (imWin == null && DN == 0) { |
| 1508 | return false; |
| 1509 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1510 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1512 | if (imPos >= 0) { |
| 1513 | // In this case, the input method windows are to be placed |
| 1514 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | // First check to see if the input method windows are already |
| 1517 | // located here, and contiguous. |
| 1518 | final int N = mWindows.size(); |
| 1519 | WindowState firstImWin = imPos < N |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1520 | ? mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | // Figure out the actual input method window that should be |
| 1523 | // at the bottom of their stack. |
| 1524 | WindowState baseImWin = imWin != null |
| 1525 | ? imWin : mInputMethodDialogs.get(0); |
| 1526 | if (baseImWin.mChildWindows.size() > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1527 | WindowState cw = baseImWin.mChildWindows.get(0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 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 (firstImWin == baseImWin) { |
| 1532 | // The windows haven't moved... but are they still contiguous? |
| 1533 | // First find the top IM window. |
| 1534 | int pos = imPos+1; |
| 1535 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1536 | if (!(mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | break; |
| 1538 | } |
| 1539 | pos++; |
| 1540 | } |
| 1541 | pos++; |
| 1542 | // Now there should be no more input method windows above. |
| 1543 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1544 | if ((mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | break; |
| 1546 | } |
| 1547 | pos++; |
| 1548 | } |
| 1549 | if (pos >= N) { |
| 1550 | // All is good! |
| 1551 | return false; |
| 1552 | } |
| 1553 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | if (imWin != null) { |
| 1556 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1557 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | logWindowList(" "); |
| 1559 | } |
| 1560 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1561 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1562 | 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] | 1563 | logWindowList(" "); |
| 1564 | } |
| 1565 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1566 | reAddWindowLocked(imPos, imWin); |
| 1567 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1568 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | logWindowList(" "); |
| 1570 | } |
| 1571 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1572 | } else { |
| 1573 | moveInputMethodDialogsLocked(imPos); |
| 1574 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1575 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | } else { |
| 1577 | // In this case, the input method windows go in a fixed layer, |
| 1578 | // because they aren't currently associated with a focus window. |
| 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 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1581 | 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] | 1582 | tmpRemoveWindowLocked(0, imWin); |
| 1583 | imWin.mTargetAppToken = null; |
| 1584 | reAddWindowToListInOrderLocked(imWin); |
| 1585 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1586 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | logWindowList(" "); |
| 1588 | } |
| 1589 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1590 | } else { |
| 1591 | moveInputMethodDialogsLocked(-1);; |
| 1592 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1594 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1595 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | if (needAssignLayers) { |
| 1597 | assignLayersLocked(); |
| 1598 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1599 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | return true; |
| 1601 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1602 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | void adjustInputMethodDialogsLocked() { |
| 1604 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1605 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1606 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1607 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1608 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1609 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1610 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1611 | ? wallpaperTarget.mAppToken.animation : null) |
| 1612 | + " upper=" + mUpperWallpaperTarget |
| 1613 | + " lower=" + mLowerWallpaperTarget); |
| 1614 | return (wallpaperTarget != null |
| 1615 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1616 | && wallpaperTarget.mAppToken.animation != null))) |
| 1617 | || mUpperWallpaperTarget != null |
| 1618 | || mLowerWallpaperTarget != null; |
| 1619 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1620 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1621 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1622 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1623 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1624 | int adjustWallpaperWindowsLocked() { |
| 1625 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1626 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1627 | final int dw = mDisplay.getWidth(); |
| 1628 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1629 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1630 | // First find top-most window that has asked to be on top of the |
| 1631 | // wallpaper; all wallpapers go behind it. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1632 | final ArrayList<WindowState> localmWindows = mWindows; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1633 | int N = localmWindows.size(); |
| 1634 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1635 | WindowState foundW = null; |
| 1636 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1637 | WindowState topCurW = null; |
| 1638 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1639 | int i = N; |
| 1640 | while (i > 0) { |
| 1641 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1642 | w = localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1643 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1644 | if (topCurW == null) { |
| 1645 | topCurW = w; |
| 1646 | topCurI = i; |
| 1647 | } |
| 1648 | continue; |
| 1649 | } |
| 1650 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1651 | if (w.mAppToken != null) { |
| 1652 | // If this window's app token is hidden and not animating, |
| 1653 | // it is of no interest to us. |
| 1654 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1655 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1656 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1657 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1658 | continue; |
| 1659 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1660 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1661 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1662 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1663 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1664 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1665 | && (mWallpaperTarget == w |
| 1666 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1667 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1668 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1669 | foundW = w; |
| 1670 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1671 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1672 | && w.mAppToken.animation != null) |
| 1673 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1674 | // The current wallpaper target is animating, so we'll |
| 1675 | // look behind it for another possible target and figure |
| 1676 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1677 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1678 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1679 | continue; |
| 1680 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1681 | break; |
| 1682 | } |
| 1683 | } |
| 1684 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1685 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1686 | // If we are currently waiting for an app transition, and either |
| 1687 | // the current target or the next target are involved with it, |
| 1688 | // then hold off on doing anything with the wallpaper. |
| 1689 | // Note that we are checking here for just whether the target |
| 1690 | // is part of an app token... which is potentially overly aggressive |
| 1691 | // (the app token may not be involved in the transition), but good |
| 1692 | // enough (we'll just wait until whatever transition is pending |
| 1693 | // executes). |
| 1694 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1695 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1696 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1697 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1698 | } |
| 1699 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1700 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1701 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1702 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1703 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1704 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1705 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1706 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1707 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1708 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1709 | + " oldTarget: " + mWallpaperTarget); |
| 1710 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1711 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1712 | mLowerWallpaperTarget = null; |
| 1713 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1714 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1715 | WindowState oldW = mWallpaperTarget; |
| 1716 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1717 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1718 | // Now what is happening... if the current and new targets are |
| 1719 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1720 | if (foundW != null && oldW != null) { |
| 1721 | boolean oldAnim = oldW.mAnimation != null |
| 1722 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1723 | boolean foundAnim = foundW.mAnimation != null |
| 1724 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1725 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1726 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1727 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1728 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1729 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1730 | int oldI = localmWindows.indexOf(oldW); |
| 1731 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1732 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1733 | } |
| 1734 | if (oldI >= 0) { |
| 1735 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1736 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1737 | + "=" + oldW + "; new#" + foundI |
| 1738 | + "=" + foundW); |
| 1739 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1740 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1741 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1742 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1743 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1744 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1745 | } |
| 1746 | mWallpaperTarget = oldW; |
| 1747 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1748 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1749 | // Now set the upper and lower wallpaper targets |
| 1750 | // correctly, and make sure that we are positioning |
| 1751 | // the wallpaper below the lower. |
| 1752 | if (foundI > oldI) { |
| 1753 | // The new target is on top of the old one. |
| 1754 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1755 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1756 | } |
| 1757 | mUpperWallpaperTarget = foundW; |
| 1758 | mLowerWallpaperTarget = oldW; |
| 1759 | foundW = oldW; |
| 1760 | foundI = oldI; |
| 1761 | } else { |
| 1762 | // The new target is below the old one. |
| 1763 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1764 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1765 | } |
| 1766 | mUpperWallpaperTarget = oldW; |
| 1767 | mLowerWallpaperTarget = foundW; |
| 1768 | } |
| 1769 | } |
| 1770 | } |
| 1771 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1772 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1773 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1774 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1775 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1776 | || (mLowerWallpaperTarget.mAppToken != null |
| 1777 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1778 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1779 | || (mUpperWallpaperTarget.mAppToken != null |
| 1780 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1781 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1782 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1783 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1784 | } |
| 1785 | mLowerWallpaperTarget = null; |
| 1786 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1787 | } |
| 1788 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1789 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1790 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1791 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1792 | // The window is visible to the compositor... but is it visible |
| 1793 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1794 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1795 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1796 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1797 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1798 | // its layer adjustment. Only do this if we are not transfering |
| 1799 | // between two wallpaper targets. |
| 1800 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1801 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1802 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1803 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1804 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1805 | * TYPE_LAYER_MULTIPLIER |
| 1806 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1807 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1808 | // Now w is the window we are supposed to be behind... but we |
| 1809 | // 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] | 1810 | // AND any starting window associated with it, AND below the |
| 1811 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1812 | while (foundI > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1813 | WindowState wb = localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1814 | if (wb.mBaseLayer < maxLayer && |
| 1815 | wb.mAttachedWindow != foundW && |
| Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1816 | wb.mAttachedWindow != foundW.mAttachedWindow && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1817 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1818 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1819 | // This window is not related to the previous one in any |
| 1820 | // interesting way, so stop here. |
| 1821 | break; |
| 1822 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1823 | foundW = wb; |
| 1824 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1825 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1826 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1827 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1828 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1829 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1830 | if (foundW == null && topCurW != null) { |
| 1831 | // There is no wallpaper target, so it goes at the bottom. |
| 1832 | // We will assume it is the same place as last time, if known. |
| 1833 | foundW = topCurW; |
| 1834 | foundI = topCurI+1; |
| 1835 | } else { |
| 1836 | // Okay i is the position immediately above the wallpaper. Look at |
| 1837 | // what is below it for later. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1838 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1839 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1840 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1841 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1842 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1843 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1844 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1845 | } |
| 1846 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1847 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1848 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1849 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1850 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1851 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1852 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1853 | // are correctly placed. |
| 1854 | int curTokenIndex = mWallpaperTokens.size(); |
| 1855 | while (curTokenIndex > 0) { |
| 1856 | curTokenIndex--; |
| 1857 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1858 | if (token.hidden == visible) { |
| 1859 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1860 | token.hidden = !visible; |
| 1861 | // Need to do a layout to ensure the wallpaper now has the |
| 1862 | // correct size. |
| 1863 | mLayoutNeeded = true; |
| 1864 | } |
| 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 | int curWallpaperIndex = token.windows.size(); |
| 1867 | while (curWallpaperIndex > 0) { |
| 1868 | curWallpaperIndex--; |
| 1869 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1870 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1871 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1872 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1873 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1874 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1875 | // First, make sure the client has the current visibility |
| 1876 | // state. |
| 1877 | if (wallpaper.mWallpaperVisible != visible) { |
| 1878 | wallpaper.mWallpaperVisible = visible; |
| 1879 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1880 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1881 | "Setting visibility of wallpaper " + wallpaper |
| 1882 | + ": " + visible); |
| 1883 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1884 | } catch (RemoteException e) { |
| 1885 | } |
| 1886 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1887 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1888 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1889 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1890 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1891 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1892 | // First, if this window is at the current index, then all |
| 1893 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1894 | if (wallpaper == foundW) { |
| 1895 | foundI--; |
| 1896 | foundW = foundI > 0 |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1897 | ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1898 | continue; |
| 1899 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1900 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1901 | // The window didn't match... the current wallpaper window, |
| 1902 | // wherever it is, is in the wrong place, so make sure it is |
| 1903 | // not in the list. |
| 1904 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1905 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1906 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1907 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1908 | localmWindows.remove(oldIndex); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1909 | mWindowsChanged = true; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1910 | if (oldIndex < foundI) { |
| 1911 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1912 | } |
| 1913 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1914 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1915 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1916 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1917 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1918 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1919 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1920 | localmWindows.add(foundI, wallpaper); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1921 | mWindowsChanged = true; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1922 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1923 | } |
| 1924 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1925 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1926 | return changed; |
| 1927 | } |
| 1928 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1929 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1930 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1931 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1932 | mWallpaperAnimLayerAdjustment = adj; |
| 1933 | int curTokenIndex = mWallpaperTokens.size(); |
| 1934 | while (curTokenIndex > 0) { |
| 1935 | curTokenIndex--; |
| 1936 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1937 | int curWallpaperIndex = token.windows.size(); |
| 1938 | while (curWallpaperIndex > 0) { |
| 1939 | curWallpaperIndex--; |
| 1940 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1941 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1942 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1943 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1944 | } |
| 1945 | } |
| 1946 | } |
| 1947 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1948 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1949 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1950 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1951 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1952 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1953 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1954 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1955 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1956 | changed = wallpaperWin.mXOffset != offset; |
| 1957 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1958 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1959 | + wallpaperWin + " x: " + offset); |
| 1960 | wallpaperWin.mXOffset = offset; |
| 1961 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1962 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1963 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1964 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1965 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1966 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1967 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1968 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1969 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1970 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1971 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1972 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1973 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1974 | + wallpaperWin + " y: " + offset); |
| 1975 | changed = true; |
| 1976 | wallpaperWin.mYOffset = offset; |
| 1977 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1978 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1979 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1980 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1981 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1982 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1983 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1984 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1985 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1986 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1987 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1988 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1989 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1990 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1991 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1992 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1993 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1994 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1995 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1996 | if (mWaitingOnWallpaper != null) { |
| 1997 | long start = SystemClock.uptimeMillis(); |
| 1998 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1999 | < start) { |
| 2000 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2001 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2002 | "Waiting for offset complete..."); |
| 2003 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2004 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2005 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2006 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2007 | if ((start+WALLPAPER_TIMEOUT) |
| 2008 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2009 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2010 | + wallpaperWin); |
| 2011 | mLastWallpaperTimeoutTime = start; |
| 2012 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2013 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2014 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2015 | } |
| 2016 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2017 | } catch (RemoteException e) { |
| 2018 | } |
| 2019 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2020 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2021 | return changed; |
| 2022 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2023 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2024 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2025 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2026 | if (mWaitingOnWallpaper != null && |
| 2027 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2028 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2029 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2033 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2034 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2035 | final int dw = mDisplay.getWidth(); |
| 2036 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2037 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2038 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2039 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2040 | WindowState target = mWallpaperTarget; |
| 2041 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2042 | if (target.mWallpaperX >= 0) { |
| 2043 | mLastWallpaperX = target.mWallpaperX; |
| 2044 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2045 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2046 | } |
| 2047 | if (target.mWallpaperY >= 0) { |
| 2048 | mLastWallpaperY = target.mWallpaperY; |
| 2049 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2050 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2051 | } |
| 2052 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2053 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2054 | int curTokenIndex = mWallpaperTokens.size(); |
| 2055 | while (curTokenIndex > 0) { |
| 2056 | curTokenIndex--; |
| 2057 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2058 | int curWallpaperIndex = token.windows.size(); |
| 2059 | while (curWallpaperIndex > 0) { |
| 2060 | curWallpaperIndex--; |
| 2061 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2062 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2063 | wallpaper.computeShownFrameLocked(); |
| 2064 | changed = true; |
| 2065 | // We only want to be synchronous with one wallpaper. |
| 2066 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2067 | } |
| 2068 | } |
| 2069 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2070 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2071 | return changed; |
| 2072 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2073 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2074 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2075 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2076 | final int dw = mDisplay.getWidth(); |
| 2077 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2078 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2079 | int curTokenIndex = mWallpaperTokens.size(); |
| 2080 | while (curTokenIndex > 0) { |
| 2081 | curTokenIndex--; |
| 2082 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2083 | if (token.hidden == visible) { |
| 2084 | token.hidden = !visible; |
| 2085 | // Need to do a layout to ensure the wallpaper now has the |
| 2086 | // correct size. |
| 2087 | mLayoutNeeded = true; |
| 2088 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2089 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2090 | int curWallpaperIndex = token.windows.size(); |
| 2091 | while (curWallpaperIndex > 0) { |
| 2092 | curWallpaperIndex--; |
| 2093 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2094 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2095 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2096 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2097 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2098 | if (wallpaper.mWallpaperVisible != visible) { |
| 2099 | wallpaper.mWallpaperVisible = visible; |
| 2100 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2101 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2102 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2103 | + ": " + visible); |
| 2104 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2105 | } catch (RemoteException e) { |
| 2106 | } |
| 2107 | } |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | public int addWindow(Session session, IWindow client, |
| 2113 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2114 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | int res = mPolicy.checkAddPermission(attrs); |
| 2116 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2117 | return res; |
| 2118 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2119 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | boolean reportNewConfig = false; |
| 2121 | WindowState attachedWindow = null; |
| 2122 | WindowState win = null; |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2123 | long origId; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2124 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2125 | synchronized(mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | if (mDisplay == null) { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2127 | throw new IllegalStateException("Display has not been initialialized"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2130 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2131 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2132 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2133 | } |
| 2134 | |
| 2135 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2136 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2137 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2138 | 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] | 2139 | + attrs.token + ". Aborting."); |
| 2140 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2141 | } |
| 2142 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2143 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2144 | 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] | 2145 | + attrs.token + ". Aborting."); |
| 2146 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | boolean addToken = false; |
| 2151 | WindowToken token = mTokenMap.get(attrs.token); |
| 2152 | if (token == null) { |
| 2153 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2154 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2155 | 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] | 2156 | + attrs.token + ". Aborting."); |
| 2157 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2158 | } |
| 2159 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2160 | 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] | 2161 | + attrs.token + ". Aborting."); |
| 2162 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2163 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2164 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2165 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2166 | + attrs.token + ". Aborting."); |
| 2167 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2168 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | token = new WindowToken(attrs.token, -1, false); |
| 2170 | addToken = true; |
| 2171 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2172 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2173 | AppWindowToken atoken = token.appWindowToken; |
| 2174 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2175 | 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] | 2176 | + token + ". Aborting."); |
| 2177 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2178 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2179 | 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] | 2180 | + token + ". Aborting."); |
| 2181 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2182 | } |
| 2183 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2184 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2185 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2186 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2187 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2188 | } |
| 2189 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2190 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2191 | 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] | 2192 | + attrs.token + ". Aborting."); |
| 2193 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2194 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2195 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2196 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2197 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2198 | + attrs.token + ". Aborting."); |
| 2199 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2200 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | win = new WindowState(session, client, token, |
| 2204 | attachedWindow, attrs, viewVisibility); |
| 2205 | if (win.mDeathRecipient == null) { |
| 2206 | // Client has apparently died, so there is no reason to |
| 2207 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2208 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | + " that is dead, aborting."); |
| 2210 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2211 | } |
| 2212 | |
| 2213 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2214 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2216 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2217 | return res; |
| 2218 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2219 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2220 | if (outInputChannel != null) { |
| 2221 | String name = win.makeInputChannelName(); |
| 2222 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2223 | win.mInputChannel = inputChannels[0]; |
| 2224 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2225 | |
| 2226 | mInputManager.registerInputChannel(win.mInputChannel); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2227 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | |
| 2229 | // From now on, no exceptions or errors allowed! |
| 2230 | |
| 2231 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2232 | |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2233 | origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2234 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | if (addToken) { |
| 2236 | mTokenMap.put(attrs.token, token); |
| 2237 | mTokenList.add(token); |
| 2238 | } |
| 2239 | win.attach(); |
| 2240 | mWindowMap.put(client.asBinder(), win); |
| 2241 | |
| 2242 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2243 | token.appWindowToken != null) { |
| 2244 | token.appWindowToken.startingWindow = win; |
| 2245 | } |
| 2246 | |
| 2247 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2249 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2250 | mInputMethodWindow = win; |
| 2251 | addInputMethodWindowToListLocked(win); |
| 2252 | imMayMove = false; |
| 2253 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2254 | mInputMethodDialogs.add(win); |
| 2255 | addWindowToListInOrderLocked(win, true); |
| 2256 | adjustInputMethodDialogsLocked(); |
| 2257 | imMayMove = false; |
| 2258 | } else { |
| 2259 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2260 | if (attrs.type == TYPE_WALLPAPER) { |
| 2261 | mLastWallpaperTimeoutTime = 0; |
| 2262 | adjustWallpaperWindowsLocked(); |
| 2263 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2264 | adjustWallpaperWindowsLocked(); |
| 2265 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2266 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2268 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2269 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2270 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2271 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2272 | if (mInTouchMode) { |
| 2273 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2274 | } |
| 2275 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2276 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2277 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2278 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2279 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | if (win.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2281 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2282 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | imMayMove = false; |
| 2284 | } |
| 2285 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2286 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2287 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2288 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2289 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2290 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | assignLayersLocked(); |
| 2292 | // Don't do layout here, the window must call |
| 2293 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2294 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2295 | //dump(); |
| 2296 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2297 | if (focusChanged) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2298 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2299 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2300 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2301 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2302 | TAG, "New client " + client.asBinder() |
| 2303 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2304 | |
| 2305 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2306 | reportNewConfig = true; |
| 2307 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2308 | } |
| 2309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2310 | if (reportNewConfig) { |
| 2311 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2312 | } |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2313 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2314 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2315 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | return res; |
| 2317 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | public void removeWindow(Session session, IWindow client) { |
| 2320 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2321 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | if (win == null) { |
| 2323 | return; |
| 2324 | } |
| 2325 | removeWindowLocked(session, win); |
| 2326 | } |
| 2327 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | public void removeWindowLocked(Session session, WindowState win) { |
| 2330 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2331 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | TAG, "Remove " + win + " client=" |
| 2333 | + Integer.toHexString(System.identityHashCode( |
| 2334 | win.mClient.asBinder())) |
| 2335 | + ", surface=" + win.mSurface); |
| 2336 | |
| 2337 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2338 | |
| 2339 | win.disposeInputChannel(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2340 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2341 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2343 | + " mExiting=" + win.mExiting |
| 2344 | + " isAnimating=" + win.isAnimating() |
| 2345 | + " app-animation=" |
| 2346 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2347 | + " inPendingTransaction=" |
| 2348 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2349 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2350 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2351 | boolean wasVisible = false; |
| 2352 | // First, see if we need to run an animation. If we do, we have |
| 2353 | // to hold off on removing the window until the animation is done. |
| 2354 | // If the display is frozen, just remove immediately, since the |
| 2355 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2356 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | // If we are not currently running the exit animation, we |
| 2358 | // need to see about starting one. |
| 2359 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2360 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2362 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2363 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2364 | } |
| 2365 | // Try starting an animation. |
| 2366 | if (applyAnimationLocked(win, transit, false)) { |
| 2367 | win.mExiting = true; |
| 2368 | } |
| 2369 | } |
| 2370 | if (win.mExiting || win.isAnimating()) { |
| 2371 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2372 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2373 | win.mExiting = true; |
| 2374 | win.mRemoveOnExit = true; |
| 2375 | mLayoutNeeded = true; |
| 2376 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2377 | performLayoutAndPlaceSurfacesLocked(); |
| 2378 | if (win.mAppToken != null) { |
| 2379 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2380 | } |
| 2381 | //dump(); |
| 2382 | Binder.restoreCallingIdentity(origId); |
| 2383 | return; |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | removeWindowInnerLocked(session, win); |
| 2388 | // Removing a visible window will effect the computed orientation |
| 2389 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2390 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2391 | != mForcedAppOrientation |
| 2392 | && updateOrientationFromAppTokensLocked()) { |
| 2393 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2394 | } |
| 2395 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2396 | Binder.restoreCallingIdentity(origId); |
| 2397 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2398 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | if (mInputMethodTarget == win) { |
| 2403 | moveInputMethodWindowsIfNeededLocked(false); |
| 2404 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2405 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2406 | if (false) { |
| 2407 | RuntimeException e = new RuntimeException("here"); |
| 2408 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2409 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2410 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2411 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | mPolicy.removeWindowLw(win); |
| 2413 | win.removeLocked(); |
| 2414 | |
| 2415 | mWindowMap.remove(win.mClient.asBinder()); |
| 2416 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2417 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2418 | 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] | 2419 | |
| 2420 | if (mInputMethodWindow == win) { |
| 2421 | mInputMethodWindow = null; |
| 2422 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2423 | mInputMethodDialogs.remove(win); |
| 2424 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | final WindowToken token = win.mToken; |
| 2427 | final AppWindowToken atoken = win.mAppToken; |
| 2428 | token.windows.remove(win); |
| 2429 | if (atoken != null) { |
| 2430 | atoken.allAppWindows.remove(win); |
| 2431 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2432 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | TAG, "**** Removing window " + win + ": count=" |
| 2434 | + token.windows.size()); |
| 2435 | if (token.windows.size() == 0) { |
| 2436 | if (!token.explicit) { |
| 2437 | mTokenMap.remove(token.token); |
| 2438 | mTokenList.remove(token); |
| 2439 | } else if (atoken != null) { |
| 2440 | atoken.firstWindowDrawn = false; |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | if (atoken != null) { |
| 2445 | if (atoken.startingWindow == win) { |
| 2446 | atoken.startingWindow = null; |
| 2447 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2448 | // If this is the last window and we had requested a starting |
| 2449 | // transition window, well there is no point now. |
| 2450 | atoken.startingData = null; |
| 2451 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2452 | // If this is the last window except for a starting transition |
| 2453 | // window, we need to get rid of the starting transition. |
| 2454 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2455 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2456 | + ": no more real windows"); |
| 2457 | } |
| 2458 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2459 | mH.sendMessage(m); |
| 2460 | } |
| 2461 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2462 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2463 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2464 | mLastWallpaperTimeoutTime = 0; |
| 2465 | adjustWallpaperWindowsLocked(); |
| 2466 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2467 | adjustWallpaperWindowsLocked(); |
| 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 | if (!mInLayout) { |
| 2471 | assignLayersLocked(); |
| 2472 | mLayoutNeeded = true; |
| 2473 | performLayoutAndPlaceSurfacesLocked(); |
| 2474 | if (win.mAppToken != null) { |
| 2475 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2476 | } |
| 2477 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2478 | |
| 2479 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2480 | } |
| 2481 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2482 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2483 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2484 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2485 | if (where != null) { |
| 2486 | Slog.i(TAG, str, where); |
| 2487 | } else { |
| 2488 | Slog.i(TAG, str); |
| 2489 | } |
| 2490 | } |
| 2491 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2493 | long origId = Binder.clearCallingIdentity(); |
| 2494 | try { |
| 2495 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2496 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2498 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | Surface.openTransaction(); |
| 2500 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2501 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2502 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2503 | w.mSurface.setTransparentRegionHint(region); |
| 2504 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2505 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | Surface.closeTransaction(); |
| 2507 | } |
| 2508 | } |
| 2509 | } |
| 2510 | } finally { |
| 2511 | Binder.restoreCallingIdentity(origId); |
| 2512 | } |
| 2513 | } |
| 2514 | |
| 2515 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2516 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2517 | Rect visibleInsets) { |
| 2518 | long origId = Binder.clearCallingIdentity(); |
| 2519 | try { |
| 2520 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2521 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | if (w != null) { |
| 2523 | w.mGivenInsetsPending = false; |
| 2524 | w.mGivenContentInsets.set(contentInsets); |
| 2525 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2526 | w.mTouchableInsets = touchableInsets; |
| 2527 | mLayoutNeeded = true; |
| 2528 | performLayoutAndPlaceSurfacesLocked(); |
| 2529 | } |
| 2530 | } |
| 2531 | } finally { |
| 2532 | Binder.restoreCallingIdentity(origId); |
| 2533 | } |
| 2534 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2537 | Rect outDisplayFrame) { |
| 2538 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2539 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | if (win == null) { |
| 2541 | outDisplayFrame.setEmpty(); |
| 2542 | return; |
| 2543 | } |
| 2544 | outDisplayFrame.set(win.mDisplayFrame); |
| 2545 | } |
| 2546 | } |
| 2547 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2548 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2549 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2550 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2551 | window.mWallpaperX = x; |
| 2552 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2553 | window.mWallpaperXStep = xStep; |
| 2554 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2555 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2556 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2557 | } |
| 2558 | } |
| 2559 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2560 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2561 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2562 | synchronized (mWindowMap) { |
| 2563 | if (mWaitingOnWallpaper != null && |
| 2564 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2565 | mWaitingOnWallpaper = null; |
| 2566 | mWindowMap.notifyAll(); |
| 2567 | } |
| 2568 | } |
| 2569 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2570 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2571 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2572 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2573 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2574 | || window == mUpperWallpaperTarget) { |
| 2575 | boolean doWait = sync; |
| 2576 | int curTokenIndex = mWallpaperTokens.size(); |
| 2577 | while (curTokenIndex > 0) { |
| 2578 | curTokenIndex--; |
| 2579 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2580 | int curWallpaperIndex = token.windows.size(); |
| 2581 | while (curWallpaperIndex > 0) { |
| 2582 | curWallpaperIndex--; |
| 2583 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2584 | try { |
| 2585 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2586 | x, y, z, extras, sync); |
| 2587 | // We only want to be synchronous with one wallpaper. |
| 2588 | sync = false; |
| 2589 | } catch (RemoteException e) { |
| 2590 | } |
| 2591 | } |
| 2592 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2593 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2594 | if (doWait) { |
| 2595 | // XXX Need to wait for result. |
| 2596 | } |
| 2597 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2598 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2599 | return null; |
| 2600 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2602 | public int relayoutWindow(Session session, IWindow client, |
| 2603 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2604 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2605 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2606 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2607 | boolean displayed = false; |
| 2608 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2609 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2613 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2614 | if (win == null) { |
| 2615 | return 0; |
| 2616 | } |
| 2617 | win.mRequestedWidth = requestedWidth; |
| 2618 | win.mRequestedHeight = requestedHeight; |
| 2619 | |
| 2620 | if (attrs != null) { |
| 2621 | mPolicy.adjustWindowParamsLw(attrs); |
| 2622 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2624 | int attrChanges = 0; |
| 2625 | int flagChanges = 0; |
| 2626 | if (attrs != null) { |
| 2627 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2628 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2629 | } |
| 2630 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2631 | 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] | 2632 | |
| 2633 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2634 | win.mAlpha = attrs.alpha; |
| 2635 | } |
| 2636 | |
| 2637 | final boolean scaledWindow = |
| 2638 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2639 | |
| 2640 | if (scaledWindow) { |
| 2641 | // requested{Width|Height} Surface's physical size |
| 2642 | // attrs.{width|height} Size on screen |
| 2643 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2644 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2645 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2646 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2647 | } else { |
| 2648 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | boolean imMayMove = (flagChanges&( |
| 2652 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2653 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2656 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2657 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2658 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2659 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2660 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2662 | win.mRelayoutCalled = true; |
| 2663 | final int oldVisibility = win.mViewVisibility; |
| 2664 | win.mViewVisibility = viewVisibility; |
| 2665 | if (viewVisibility == View.VISIBLE && |
| 2666 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2667 | displayed = !win.isVisibleLw(); |
| 2668 | if (win.mExiting) { |
| 2669 | win.mExiting = false; |
| 2670 | win.mAnimation = null; |
| 2671 | } |
| 2672 | if (win.mDestroying) { |
| 2673 | win.mDestroying = false; |
| 2674 | mDestroySurface.remove(win); |
| 2675 | } |
| 2676 | if (oldVisibility == View.GONE) { |
| 2677 | win.mEnterAnimationPending = true; |
| 2678 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2679 | if (displayed) { |
| 2680 | if (win.mSurface != null && !win.mDrawPending |
| 2681 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2682 | && mPolicy.isScreenOn()) { |
| 2683 | applyEnterAnimationLocked(win); |
| 2684 | } |
| 2685 | if ((win.mAttrs.flags |
| 2686 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2687 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2688 | "Relayout window turning screen on: " + win); |
| 2689 | win.mTurnOnScreen = true; |
| 2690 | } |
| 2691 | int diff = 0; |
| 2692 | if (win.mConfiguration != mCurConfiguration |
| 2693 | && (win.mConfiguration == null |
| 2694 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2695 | win.mConfiguration = mCurConfiguration; |
| 2696 | if (DEBUG_CONFIGURATION) { |
| 2697 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2698 | + win.mConfiguration + " / 0x" |
| 2699 | + Integer.toHexString(diff)); |
| 2700 | } |
| 2701 | outConfig.setTo(mCurConfiguration); |
| 2702 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2703 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2704 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2705 | // To change the format, we need to re-build the surface. |
| 2706 | win.destroySurfaceLocked(); |
| 2707 | displayed = true; |
| 2708 | } |
| 2709 | try { |
| 2710 | Surface surface = win.createSurfaceLocked(); |
| 2711 | if (surface != null) { |
| 2712 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2713 | win.mReportDestroySurface = false; |
| 2714 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2715 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2716 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2717 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2718 | // For some reason there isn't a surface. Clear the |
| 2719 | // caller's object so they see the same state. |
| 2720 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2721 | } |
| 2722 | } catch (Exception e) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2723 | mInputMonitor.updateInputWindowsLw(); |
| 2724 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2725 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2726 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2727 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2728 | Binder.restoreCallingIdentity(origId); |
| 2729 | return 0; |
| 2730 | } |
| 2731 | if (displayed) { |
| 2732 | focusMayChange = true; |
| 2733 | } |
| 2734 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2735 | && mInputMethodWindow == null) { |
| 2736 | mInputMethodWindow = win; |
| 2737 | imMayMove = true; |
| 2738 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2739 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2740 | && win.mAppToken != null |
| 2741 | && win.mAppToken.startingWindow != null) { |
| 2742 | // Special handling of starting window over the base |
| 2743 | // window of the app: propagate lock screen flags to it, |
| 2744 | // to provide the correct semantics while starting. |
| 2745 | final int mask = |
| 2746 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2747 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2748 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2749 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2750 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2751 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2752 | } else { |
| 2753 | win.mEnterAnimationPending = false; |
| 2754 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2755 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2756 | + ": mExiting=" + win.mExiting |
| 2757 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | // If we are not currently running the exit animation, we |
| 2759 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2760 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | // Try starting an animation; if there isn't one, we |
| 2762 | // can destroy the surface right away. |
| 2763 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2764 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2765 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2766 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2767 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2769 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | win.mExiting = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2771 | } else if (win.isAnimating()) { |
| 2772 | // Currently in a hide animation... turn this into |
| 2773 | // an exit. |
| 2774 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2775 | } else if (win == mWallpaperTarget) { |
| 2776 | // If the wallpaper is currently behind this |
| 2777 | // window, we need to change both of them inside |
| 2778 | // of a transaction to avoid artifacts. |
| 2779 | win.mExiting = true; |
| 2780 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2781 | } else { |
| 2782 | if (mInputMethodWindow == win) { |
| 2783 | mInputMethodWindow = null; |
| 2784 | } |
| 2785 | win.destroySurfaceLocked(); |
| 2786 | } |
| 2787 | } |
| 2788 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2789 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2790 | if (win.mSurface == null || (win.getAttrs().flags |
| 2791 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2792 | || win.mSurfacePendingDestroy) { |
| 2793 | // We are being called from a local process, which |
| 2794 | // means outSurface holds its current surface. Ensure the |
| 2795 | // surface object is cleared, but we don't want it actually |
| 2796 | // destroyed at this point. |
| 2797 | win.mSurfacePendingDestroy = false; |
| 2798 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2799 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2800 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2801 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2802 | "Keeping surface, will report destroy: " + win); |
| 2803 | win.mReportDestroySurface = true; |
| 2804 | outSurface.copyFrom(win.mSurface); |
| 2805 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | } |
| 2807 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2808 | if (focusMayChange) { |
| 2809 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2810 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | imMayMove = false; |
| 2812 | } |
| 2813 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2814 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2815 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2816 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2817 | // reassign them at this point if the IM window state gets shuffled |
| 2818 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2819 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2820 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2821 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2822 | // Little hack here -- we -should- be able to rely on the |
| 2823 | // function to return true if the IME has moved and needs |
| 2824 | // its layer recomputed. However, if the IME was hidden |
| 2825 | // and isn't actually moved in the list, its layer may be |
| 2826 | // 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] | 2827 | assignLayers = true; |
| 2828 | } |
| 2829 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2830 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2831 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2832 | assignLayers = true; |
| 2833 | } |
| 2834 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2835 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2836 | mLayoutNeeded = true; |
| 2837 | win.mGivenInsetsPending = insetsPending; |
| 2838 | if (assignLayers) { |
| 2839 | assignLayersLocked(); |
| 2840 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2841 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2843 | if (displayed && win.mIsWallpaper) { |
| 2844 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2845 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2846 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2847 | if (win.mAppToken != null) { |
| 2848 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2849 | } |
| 2850 | outFrame.set(win.mFrame); |
| 2851 | outContentInsets.set(win.mContentInsets); |
| 2852 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2853 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2854 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2855 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2856 | + ", requestedHeight=" + requestedHeight |
| 2857 | + ", viewVisibility=" + viewVisibility |
| 2858 | + "\nRelayout returning frame=" + outFrame |
| 2859 | + ", surface=" + outSurface); |
| 2860 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2861 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2862 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2863 | |
| 2864 | inTouchMode = mInTouchMode; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2865 | |
| 2866 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | } |
| 2868 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2869 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | sendNewConfiguration(); |
| 2871 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2872 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2873 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2874 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2876 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2877 | } |
| 2878 | |
| 2879 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2880 | final long origId = Binder.clearCallingIdentity(); |
| 2881 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2882 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2884 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2885 | adjustWallpaperWindowsLocked(); |
| 2886 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | mLayoutNeeded = true; |
| 2888 | performLayoutAndPlaceSurfacesLocked(); |
| 2889 | } |
| 2890 | } |
| 2891 | Binder.restoreCallingIdentity(origId); |
| 2892 | } |
| 2893 | |
| 2894 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2895 | 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] | 2896 | + (lp != null ? lp.packageName : null) |
| 2897 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2898 | if (lp != null && lp.windowAnimations != 0) { |
| 2899 | // If this is a system resource, don't try to load it from the |
| 2900 | // application resources. It is nice to avoid loading application |
| 2901 | // resources if we can. |
| 2902 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2903 | int resId = lp.windowAnimations; |
| 2904 | if ((resId&0xFF000000) == 0x01000000) { |
| 2905 | packageName = "android"; |
| 2906 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2907 | 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] | 2908 | + packageName); |
| 2909 | return AttributeCache.instance().get(packageName, resId, |
| 2910 | com.android.internal.R.styleable.WindowAnimation); |
| 2911 | } |
| 2912 | return null; |
| 2913 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2914 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2915 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2916 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2917 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2918 | if (packageName != null) { |
| 2919 | if ((resId&0xFF000000) == 0x01000000) { |
| 2920 | packageName = "android"; |
| 2921 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2922 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2923 | + packageName); |
| 2924 | return AttributeCache.instance().get(packageName, resId, |
| 2925 | com.android.internal.R.styleable.WindowAnimation); |
| 2926 | } |
| 2927 | return null; |
| 2928 | } |
| 2929 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2930 | private void applyEnterAnimationLocked(WindowState win) { |
| 2931 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2932 | if (win.mEnterAnimationPending) { |
| 2933 | win.mEnterAnimationPending = false; |
| 2934 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2935 | } |
| 2936 | |
| 2937 | applyAnimationLocked(win, transit, true); |
| 2938 | } |
| 2939 | |
| 2940 | private boolean applyAnimationLocked(WindowState win, |
| 2941 | int transit, boolean isEntrance) { |
| 2942 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2943 | // If we are trying to apply an animation, but already running |
| 2944 | // an animation of the same type, then just leave that one alone. |
| 2945 | return true; |
| 2946 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2948 | // Only apply an animation if the display isn't frozen. If it is |
| 2949 | // frozen, there is no reason to animate and it can cause strange |
| 2950 | // artifacts when we unfreeze the display if some different animation |
| 2951 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2952 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2954 | int attr = -1; |
| 2955 | Animation a = null; |
| 2956 | if (anim != 0) { |
| 2957 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2958 | } else { |
| 2959 | switch (transit) { |
| 2960 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2961 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2962 | break; |
| 2963 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2964 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2965 | break; |
| 2966 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2967 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2968 | break; |
| 2969 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2970 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2971 | break; |
| 2972 | } |
| 2973 | if (attr >= 0) { |
| 2974 | a = loadAnimation(win.mAttrs, attr); |
| 2975 | } |
| 2976 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2977 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2979 | + " mAnimation=" + win.mAnimation |
| 2980 | + " isEntrance=" + isEntrance); |
| 2981 | if (a != null) { |
| 2982 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2983 | RuntimeException e = null; |
| 2984 | if (!HIDE_STACK_CRAWLS) { |
| 2985 | e = new RuntimeException(); |
| 2986 | e.fillInStackTrace(); |
| 2987 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2988 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | } |
| 2990 | win.setAnimation(a); |
| 2991 | win.mAnimationIsEntrance = isEntrance; |
| 2992 | } |
| 2993 | } else { |
| 2994 | win.clearAnimation(); |
| 2995 | } |
| 2996 | |
| 2997 | return win.mAnimation != null; |
| 2998 | } |
| 2999 | |
| 3000 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3001 | int anim = 0; |
| 3002 | Context context = mContext; |
| 3003 | if (animAttr >= 0) { |
| 3004 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3005 | if (ent != null) { |
| 3006 | context = ent.context; |
| 3007 | anim = ent.array.getResourceId(animAttr, 0); |
| 3008 | } |
| 3009 | } |
| 3010 | if (anim != 0) { |
| 3011 | return AnimationUtils.loadAnimation(context, anim); |
| 3012 | } |
| 3013 | return null; |
| 3014 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3015 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3016 | private Animation loadAnimation(String packageName, int resId) { |
| 3017 | int anim = 0; |
| 3018 | Context context = mContext; |
| 3019 | if (resId >= 0) { |
| 3020 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3021 | if (ent != null) { |
| 3022 | context = ent.context; |
| 3023 | anim = resId; |
| 3024 | } |
| 3025 | } |
| 3026 | if (anim != 0) { |
| 3027 | return AnimationUtils.loadAnimation(context, anim); |
| 3028 | } |
| 3029 | return null; |
| 3030 | } |
| 3031 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3032 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3033 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3034 | // Only apply an animation if the display isn't frozen. If it is |
| 3035 | // frozen, there is no reason to animate and it can cause strange |
| 3036 | // artifacts when we unfreeze the display if some different animation |
| 3037 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3038 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3039 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3040 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3041 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3042 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3043 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3044 | } else if (mNextAppTransitionPackage != null) { |
| 3045 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3046 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3047 | } else { |
| 3048 | int animAttr = 0; |
| 3049 | switch (transit) { |
| 3050 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3051 | animAttr = enter |
| 3052 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3053 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3054 | break; |
| 3055 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3056 | animAttr = enter |
| 3057 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3058 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3059 | break; |
| 3060 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3061 | animAttr = enter |
| 3062 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3063 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3064 | break; |
| 3065 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3066 | animAttr = enter |
| 3067 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3068 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3069 | break; |
| 3070 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3071 | animAttr = enter |
| 3072 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3073 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3074 | break; |
| 3075 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3076 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3077 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3078 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3079 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3080 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3081 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3082 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3083 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3084 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3085 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3086 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3087 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3088 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3089 | break; |
| 3090 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3091 | animAttr = enter |
| 3092 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3093 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3094 | break; |
| 3095 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3096 | animAttr = enter |
| 3097 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3098 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3099 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3100 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3101 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3102 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3103 | + " anim=" + a |
| 3104 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3105 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3106 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3107 | if (a != null) { |
| 3108 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3109 | RuntimeException e = null; |
| 3110 | if (!HIDE_STACK_CRAWLS) { |
| 3111 | e = new RuntimeException(); |
| 3112 | e.fillInStackTrace(); |
| 3113 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3114 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | } |
| 3116 | wtoken.setAnimation(a); |
| 3117 | } |
| 3118 | } else { |
| 3119 | wtoken.clearAnimation(); |
| 3120 | } |
| 3121 | |
| 3122 | return wtoken.animation != null; |
| 3123 | } |
| 3124 | |
| 3125 | // ------------------------------------------------------------- |
| 3126 | // Application Window Tokens |
| 3127 | // ------------------------------------------------------------- |
| 3128 | |
| 3129 | public void validateAppTokens(List tokens) { |
| 3130 | int v = tokens.size()-1; |
| 3131 | int m = mAppTokens.size()-1; |
| 3132 | while (v >= 0 && m >= 0) { |
| 3133 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3134 | if (wtoken.removed) { |
| 3135 | m--; |
| 3136 | continue; |
| 3137 | } |
| 3138 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3139 | 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] | 3140 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3141 | } |
| 3142 | v--; |
| 3143 | m--; |
| 3144 | } |
| 3145 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3146 | 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] | 3147 | v--; |
| 3148 | } |
| 3149 | while (m >= 0) { |
| 3150 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3151 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3152 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3153 | } |
| 3154 | m--; |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | boolean checkCallingPermission(String permission, String func) { |
| 3159 | // Quick check: if the calling permission is me, it's all okay. |
| 3160 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3161 | return true; |
| 3162 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | if (mContext.checkCallingPermission(permission) |
| 3165 | == PackageManager.PERMISSION_GRANTED) { |
| 3166 | return true; |
| 3167 | } |
| 3168 | String msg = "Permission Denial: " + func + " from pid=" |
| 3169 | + Binder.getCallingPid() |
| 3170 | + ", uid=" + Binder.getCallingUid() |
| 3171 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3172 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3173 | return false; |
| 3174 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3175 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3176 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3177 | WindowToken wtoken = mTokenMap.get(token); |
| 3178 | if (wtoken == null) { |
| 3179 | return null; |
| 3180 | } |
| 3181 | return wtoken.appWindowToken; |
| 3182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | public void addWindowToken(IBinder token, int type) { |
| 3185 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3186 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3187 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3188 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | synchronized(mWindowMap) { |
| 3191 | WindowToken wtoken = mTokenMap.get(token); |
| 3192 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3193 | 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] | 3194 | return; |
| 3195 | } |
| 3196 | wtoken = new WindowToken(token, type, true); |
| 3197 | mTokenMap.put(token, wtoken); |
| 3198 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3199 | if (type == TYPE_WALLPAPER) { |
| 3200 | mWallpaperTokens.add(wtoken); |
| 3201 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | } |
| 3203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3205 | public void removeWindowToken(IBinder token) { |
| 3206 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3207 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3208 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | final long origId = Binder.clearCallingIdentity(); |
| 3212 | synchronized(mWindowMap) { |
| 3213 | WindowToken wtoken = mTokenMap.remove(token); |
| 3214 | mTokenList.remove(wtoken); |
| 3215 | if (wtoken != null) { |
| 3216 | boolean delayed = false; |
| 3217 | if (!wtoken.hidden) { |
| 3218 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3219 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | final int N = wtoken.windows.size(); |
| 3221 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3222 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | for (int i=0; i<N; i++) { |
| 3224 | WindowState win = wtoken.windows.get(i); |
| 3225 | |
| 3226 | if (win.isAnimating()) { |
| 3227 | delayed = true; |
| 3228 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3229 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3230 | if (win.isVisibleNow()) { |
| 3231 | applyAnimationLocked(win, |
| 3232 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | changed = true; |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | if (changed) { |
| 3238 | mLayoutNeeded = true; |
| 3239 | performLayoutAndPlaceSurfacesLocked(); |
| 3240 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3241 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3242 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | if (delayed) { |
| 3244 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3245 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3246 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3247 | } |
| 3248 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3249 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3250 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3252 | 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] | 3253 | } |
| 3254 | } |
| 3255 | Binder.restoreCallingIdentity(origId); |
| 3256 | } |
| 3257 | |
| 3258 | public void addAppToken(int addPos, IApplicationToken token, |
| 3259 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3260 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3261 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3262 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3264 | |
| 3265 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3266 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3267 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3268 | // here we would run the chance of introducing a deadlock between the window manager |
| 3269 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3270 | // (which holds locks while querying the application token). |
| 3271 | long inputDispatchingTimeoutNanos; |
| 3272 | try { |
| 3273 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3274 | } catch (RemoteException ex) { |
| 3275 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3276 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3277 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3278 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | synchronized(mWindowMap) { |
| 3280 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3281 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3282 | 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] | 3283 | return; |
| 3284 | } |
| 3285 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3286 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | wtoken.groupId = groupId; |
| 3288 | wtoken.appFullscreen = fullscreen; |
| 3289 | wtoken.requestedOrientation = requestedOrientation; |
| 3290 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3291 | 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] | 3292 | mTokenMap.put(token.asBinder(), wtoken); |
| 3293 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3294 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3295 | // Application tokens start out hidden. |
| 3296 | wtoken.hidden = true; |
| 3297 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3299 | //dump(); |
| 3300 | } |
| 3301 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3303 | public void setAppGroupId(IBinder token, int groupId) { |
| 3304 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3305 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3306 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | synchronized(mWindowMap) { |
| 3310 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3311 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3312 | 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] | 3313 | return; |
| 3314 | } |
| 3315 | wtoken.groupId = groupId; |
| 3316 | } |
| 3317 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3319 | public int getOrientationFromWindowsLocked() { |
| 3320 | int pos = mWindows.size() - 1; |
| 3321 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3322 | WindowState wtoken = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3323 | pos--; |
| 3324 | if (wtoken.mAppToken != null) { |
| 3325 | // We hit an application window. so the orientation will be determined by the |
| 3326 | // app window. No point in continuing further. |
| 3327 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3328 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3329 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3330 | continue; |
| 3331 | } |
| 3332 | int req = wtoken.mAttrs.screenOrientation; |
| 3333 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3334 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3335 | continue; |
| 3336 | } else { |
| 3337 | return req; |
| 3338 | } |
| 3339 | } |
| 3340 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3341 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3342 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3344 | int pos = mAppTokens.size() - 1; |
| 3345 | int curGroup = 0; |
| 3346 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3347 | boolean findingBehind = false; |
| 3348 | boolean haveGroup = false; |
| 3349 | boolean lastFullscreen = false; |
| 3350 | while (pos >= 0) { |
| 3351 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3352 | pos--; |
| 3353 | // if we're about to tear down this window and not seek for |
| 3354 | // the behind activity, don't use it for orientation |
| 3355 | if (!findingBehind |
| 3356 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3357 | continue; |
| 3358 | } |
| 3359 | |
| 3360 | if (!haveGroup) { |
| 3361 | // We ignore any hidden applications on the top. |
| 3362 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3363 | continue; |
| 3364 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3365 | haveGroup = true; |
| 3366 | curGroup = wtoken.groupId; |
| 3367 | lastOrientation = wtoken.requestedOrientation; |
| 3368 | } else if (curGroup != wtoken.groupId) { |
| 3369 | // If we have hit a new application group, and the bottom |
| 3370 | // of the previous group didn't explicitly say to use |
| 3371 | // the orientation behind it, and the last app was |
| 3372 | // full screen, then we'll stick with the |
| 3373 | // user's orientation. |
| 3374 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3375 | && lastFullscreen) { |
| 3376 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3379 | int or = wtoken.requestedOrientation; |
| 3380 | // If this application is fullscreen, and didn't explicitly say |
| 3381 | // to use the orientation behind it, then just take whatever |
| 3382 | // orientation it has and ignores whatever is under it. |
| 3383 | lastFullscreen = wtoken.appFullscreen; |
| 3384 | if (lastFullscreen |
| 3385 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3386 | return or; |
| 3387 | } |
| 3388 | // If this application has requested an explicit orientation, |
| 3389 | // then use it. |
| Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3390 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3391 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3392 | return or; |
| 3393 | } |
| 3394 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3395 | } |
| 3396 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3398 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3399 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3400 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3401 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3402 | "updateOrientationFromAppTokens()")) { |
| 3403 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3404 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3405 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3406 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3407 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3408 | |
| 3409 | synchronized(mWindowMap) { |
| 3410 | if (updateOrientationFromAppTokensLocked()) { |
| 3411 | if (freezeThisOneIfNeeded != null) { |
| 3412 | AppWindowToken wtoken = findAppWindowToken( |
| 3413 | freezeThisOneIfNeeded); |
| 3414 | if (wtoken != null) { |
| 3415 | startAppFreezingScreenLocked(wtoken, |
| 3416 | ActivityInfo.CONFIG_ORIENTATION); |
| 3417 | } |
| 3418 | } |
| 3419 | config = computeNewConfigurationLocked(); |
| 3420 | |
| 3421 | } else if (currentConfig != null) { |
| 3422 | // No obvious action we need to take, but if our current |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3423 | // state mismatches the activity manager's, update it, |
| 3424 | // disregarding font scale, which should remain set to |
| 3425 | // the value of the previous configuration. |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3426 | mTempConfiguration.setToDefaults(); |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3427 | mTempConfiguration.fontScale = currentConfig.fontScale; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3428 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3429 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3430 | mWaitingForConfig = true; |
| 3431 | mLayoutNeeded = true; |
| 3432 | startFreezingDisplayLocked(); |
| 3433 | config = new Configuration(mTempConfiguration); |
| 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | } |
| 3438 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3439 | Binder.restoreCallingIdentity(ident); |
| 3440 | return config; |
| 3441 | } |
| 3442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3443 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3444 | * Determine the new desired orientation of the display, returning |
| 3445 | * a non-null new Configuration if it has changed from the current |
| 3446 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3447 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3448 | * SCREEN. This will typically be done for you if you call |
| 3449 | * sendNewConfiguration(). |
| 3450 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3451 | * The orientation is computed from non-application windows first. If none of |
| 3452 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3453 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3455 | * android.os.IBinder) |
| 3456 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3457 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3458 | if (mDisplayFrozen) { |
| 3459 | // If the display is frozen, some activities may be in the middle |
| 3460 | // of restarting, and thus have removed their old window. If the |
| 3461 | // window has the flag to hide the lock screen, then the lock screen |
| 3462 | // can re-appear and inflict its own orientation on us. Keep the |
| 3463 | // orientation stable until this all settles down. |
| 3464 | return false; |
| 3465 | } |
| 3466 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3468 | long ident = Binder.clearCallingIdentity(); |
| 3469 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3470 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3472 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | mForcedAppOrientation = req; |
| 3474 | //send a message to Policy indicating orientation change to take |
| 3475 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3476 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3477 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3478 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3479 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3480 | } |
| 3481 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3482 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3483 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | } finally { |
| 3485 | Binder.restoreCallingIdentity(ident); |
| 3486 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3488 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3489 | int computeForcedAppOrientationLocked() { |
| 3490 | int req = getOrientationFromWindowsLocked(); |
| 3491 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3492 | req = getOrientationFromAppTokensLocked(); |
| 3493 | } |
| 3494 | return req; |
| 3495 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3496 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3497 | public void setNewConfiguration(Configuration config) { |
| 3498 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3499 | "setNewConfiguration()")) { |
| 3500 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3501 | } |
| 3502 | |
| 3503 | synchronized(mWindowMap) { |
| 3504 | mCurConfiguration = new Configuration(config); |
| 3505 | mWaitingForConfig = false; |
| 3506 | performLayoutAndPlaceSurfacesLocked(); |
| 3507 | } |
| 3508 | } |
| 3509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3510 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3511 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3512 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3513 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3516 | synchronized(mWindowMap) { |
| 3517 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3518 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3519 | 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] | 3520 | return; |
| 3521 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3523 | wtoken.requestedOrientation = requestedOrientation; |
| 3524 | } |
| 3525 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3527 | public int getAppOrientation(IApplicationToken token) { |
| 3528 | synchronized(mWindowMap) { |
| 3529 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3530 | if (wtoken == null) { |
| 3531 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3532 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3533 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3534 | return wtoken.requestedOrientation; |
| 3535 | } |
| 3536 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3537 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3539 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3540 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3541 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | synchronized(mWindowMap) { |
| 3545 | boolean changed = false; |
| 3546 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3547 | 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] | 3548 | changed = mFocusedApp != null; |
| 3549 | mFocusedApp = null; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3550 | if (changed) { |
| 3551 | mInputMonitor.setFocusedAppLw(null); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3552 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3553 | } else { |
| 3554 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3555 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3556 | 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] | 3557 | return; |
| 3558 | } |
| 3559 | changed = mFocusedApp != newFocus; |
| 3560 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3561 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3562 | if (changed) { |
| 3563 | mInputMonitor.setFocusedAppLw(newFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3564 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | if (moveFocusNow && changed) { |
| 3568 | final long origId = Binder.clearCallingIdentity(); |
| 3569 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3570 | Binder.restoreCallingIdentity(origId); |
| 3571 | } |
| 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | public void prepareAppTransition(int transit) { |
| 3576 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3577 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3578 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3582 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | TAG, "Prepare app transition: transit=" + transit |
| 3584 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3585 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3586 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3587 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3588 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3589 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3590 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3591 | // Opening a new task always supersedes a close for the anim. |
| 3592 | mNextAppTransition = transit; |
| 3593 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3594 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3595 | // Opening a new activity always supersedes a close for the anim. |
| 3596 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | } |
| 3598 | mAppTransitionReady = false; |
| 3599 | mAppTransitionTimeout = false; |
| 3600 | mStartingIconInTransition = false; |
| 3601 | mSkipAppTransitionAnimation = false; |
| 3602 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3603 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3604 | 5000); |
| 3605 | } |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | public int getPendingAppTransition() { |
| 3610 | return mNextAppTransition; |
| 3611 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3612 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3613 | public void overridePendingAppTransition(String packageName, |
| 3614 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3615 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3616 | mNextAppTransitionPackage = packageName; |
| 3617 | mNextAppTransitionEnter = enterAnim; |
| 3618 | mNextAppTransitionExit = exitAnim; |
| 3619 | } |
| 3620 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3621 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | public void executeAppTransition() { |
| 3623 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3624 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3625 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3627 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3628 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3629 | if (DEBUG_APP_TRANSITIONS) { |
| 3630 | RuntimeException e = new RuntimeException("here"); |
| 3631 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3632 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3633 | + mNextAppTransition, e); |
| 3634 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3635 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3636 | mAppTransitionReady = true; |
| 3637 | final long origId = Binder.clearCallingIdentity(); |
| 3638 | performLayoutAndPlaceSurfacesLocked(); |
| 3639 | Binder.restoreCallingIdentity(origId); |
| 3640 | } |
| 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3645 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3646 | IBinder transferFrom, boolean createIfNeeded) { |
| 3647 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3648 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3649 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3653 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3655 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3656 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3658 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3659 | 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] | 3660 | return; |
| 3661 | } |
| 3662 | |
| 3663 | // If the display is frozen, we won't do anything until the |
| 3664 | // actual window is displayed so there is no reason to put in |
| 3665 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3666 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | return; |
| 3668 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3669 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | if (wtoken.startingData != null) { |
| 3671 | return; |
| 3672 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | if (transferFrom != null) { |
| 3675 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3676 | if (ttoken != null) { |
| 3677 | WindowState startingWindow = ttoken.startingWindow; |
| 3678 | if (startingWindow != null) { |
| 3679 | if (mStartingIconInTransition) { |
| 3680 | // In this case, the starting icon has already |
| 3681 | // been displayed, so start letting windows get |
| 3682 | // shown immediately without any more transitions. |
| 3683 | mSkipAppTransitionAnimation = true; |
| 3684 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3685 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | "Moving existing starting from " + ttoken |
| 3687 | + " to " + wtoken); |
| 3688 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | // Transfer the starting window over to the new |
| 3691 | // token. |
| 3692 | wtoken.startingData = ttoken.startingData; |
| 3693 | wtoken.startingView = ttoken.startingView; |
| 3694 | wtoken.startingWindow = startingWindow; |
| 3695 | ttoken.startingData = null; |
| 3696 | ttoken.startingView = null; |
| 3697 | ttoken.startingWindow = null; |
| 3698 | ttoken.startingMoved = true; |
| 3699 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3700 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3702 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3703 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | mWindows.remove(startingWindow); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3705 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | ttoken.windows.remove(startingWindow); |
| 3707 | ttoken.allAppWindows.remove(startingWindow); |
| 3708 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3709 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | // Propagate other interesting state between the |
| 3711 | // tokens. If the old token is displayed, we should |
| 3712 | // immediately force the new one to be displayed. If |
| 3713 | // it is animating, we need to move that animation to |
| 3714 | // the new one. |
| 3715 | if (ttoken.allDrawn) { |
| 3716 | wtoken.allDrawn = true; |
| 3717 | } |
| 3718 | if (ttoken.firstWindowDrawn) { |
| 3719 | wtoken.firstWindowDrawn = true; |
| 3720 | } |
| 3721 | if (!ttoken.hidden) { |
| 3722 | wtoken.hidden = false; |
| 3723 | wtoken.hiddenRequested = false; |
| 3724 | wtoken.willBeHidden = false; |
| 3725 | } |
| 3726 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3727 | wtoken.clientHidden = ttoken.clientHidden; |
| 3728 | wtoken.sendAppVisibilityToClients(); |
| 3729 | } |
| 3730 | if (ttoken.animation != null) { |
| 3731 | wtoken.animation = ttoken.animation; |
| 3732 | wtoken.animating = ttoken.animating; |
| 3733 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3734 | ttoken.animation = null; |
| 3735 | ttoken.animLayerAdjustment = 0; |
| 3736 | wtoken.updateLayers(); |
| 3737 | ttoken.updateLayers(); |
| 3738 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3741 | mLayoutNeeded = true; |
| 3742 | performLayoutAndPlaceSurfacesLocked(); |
| 3743 | Binder.restoreCallingIdentity(origId); |
| 3744 | return; |
| 3745 | } else if (ttoken.startingData != null) { |
| 3746 | // The previous app was getting ready to show a |
| 3747 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3748 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | "Moving pending starting from " + ttoken |
| 3750 | + " to " + wtoken); |
| 3751 | wtoken.startingData = ttoken.startingData; |
| 3752 | ttoken.startingData = null; |
| 3753 | ttoken.startingMoved = true; |
| 3754 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3755 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3756 | // want to process the message ASAP, before any other queued |
| 3757 | // messages. |
| 3758 | mH.sendMessageAtFrontOfQueue(m); |
| 3759 | return; |
| 3760 | } |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | // There is no existing starting window, and the caller doesn't |
| 3765 | // want us to create one, so that's it! |
| 3766 | if (!createIfNeeded) { |
| 3767 | return; |
| 3768 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3769 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3770 | // If this is a translucent or wallpaper window, then don't |
| 3771 | // show a starting window -- the current effect (a full-screen |
| 3772 | // opaque starting window that fades away to the real contents |
| 3773 | // when it is ready) does not work for this. |
| 3774 | if (theme != 0) { |
| 3775 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3776 | com.android.internal.R.styleable.Window); |
| 3777 | if (ent.array.getBoolean( |
| 3778 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3779 | return; |
| 3780 | } |
| 3781 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3782 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3783 | return; |
| 3784 | } |
| 3785 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3786 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3787 | return; |
| 3788 | } |
| 3789 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3790 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3791 | mStartingIconInTransition = true; |
| 3792 | wtoken.startingData = new StartingData( |
| 3793 | pkg, theme, nonLocalizedLabel, |
| 3794 | labelRes, icon); |
| 3795 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3796 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3797 | // want to process the message ASAP, before any other queued |
| 3798 | // messages. |
| 3799 | mH.sendMessageAtFrontOfQueue(m); |
| 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | public void setAppWillBeHidden(IBinder token) { |
| 3804 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3805 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3806 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | AppWindowToken wtoken; |
| 3810 | |
| 3811 | synchronized(mWindowMap) { |
| 3812 | wtoken = findAppWindowToken(token); |
| 3813 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3814 | 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] | 3815 | return; |
| 3816 | } |
| 3817 | wtoken.willBeHidden = true; |
| 3818 | } |
| 3819 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3820 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3822 | boolean visible, int transit, boolean performLayout) { |
| 3823 | boolean delayed = false; |
| 3824 | |
| 3825 | if (wtoken.clientHidden == visible) { |
| 3826 | wtoken.clientHidden = !visible; |
| 3827 | wtoken.sendAppVisibilityToClients(); |
| 3828 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3829 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | wtoken.willBeHidden = false; |
| 3831 | if (wtoken.hidden == visible) { |
| 3832 | final int N = wtoken.allAppWindows.size(); |
| 3833 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3834 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3836 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3838 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3839 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3840 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | if (wtoken.animation == sDummyAnimation) { |
| 3842 | wtoken.animation = null; |
| 3843 | } |
| 3844 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3845 | changed = true; |
| 3846 | if (wtoken.animation != null) { |
| 3847 | delayed = runningAppAnimation = true; |
| 3848 | } |
| 3849 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3850 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | for (int i=0; i<N; i++) { |
| 3852 | WindowState win = wtoken.allAppWindows.get(i); |
| 3853 | if (win == wtoken.startingWindow) { |
| 3854 | continue; |
| 3855 | } |
| 3856 | |
| 3857 | if (win.isAnimating()) { |
| 3858 | delayed = true; |
| 3859 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3860 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3861 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | //win.dump(" "); |
| 3863 | if (visible) { |
| 3864 | if (!win.isVisibleNow()) { |
| 3865 | if (!runningAppAnimation) { |
| 3866 | applyAnimationLocked(win, |
| 3867 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3868 | } |
| 3869 | changed = true; |
| 3870 | } |
| 3871 | } else if (win.isVisibleNow()) { |
| 3872 | if (!runningAppAnimation) { |
| 3873 | applyAnimationLocked(win, |
| 3874 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3875 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3876 | changed = true; |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3881 | if (!visible) { |
| 3882 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3883 | } else { |
| 3884 | // If we are being set visible, and the starting window is |
| 3885 | // not yet displayed, then make sure it doesn't get displayed. |
| 3886 | WindowState swin = wtoken.startingWindow; |
| 3887 | if (swin != null && (swin.mDrawPending |
| 3888 | || swin.mCommitDrawPending)) { |
| 3889 | swin.mPolicyVisibility = false; |
| 3890 | swin.mPolicyVisibilityAfterAnim = false; |
| 3891 | } |
| 3892 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3893 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3894 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3895 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3896 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3897 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3898 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3900 | if (performLayout) { |
| 3901 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3902 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3903 | } else { |
| 3904 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3905 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | if (wtoken.animation != null) { |
| 3910 | delayed = true; |
| 3911 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3913 | return delayed; |
| 3914 | } |
| 3915 | |
| 3916 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3917 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3918 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3919 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | AppWindowToken wtoken; |
| 3923 | |
| 3924 | synchronized(mWindowMap) { |
| 3925 | wtoken = findAppWindowToken(token); |
| 3926 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3927 | 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] | 3928 | return; |
| 3929 | } |
| 3930 | |
| 3931 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3932 | RuntimeException e = null; |
| 3933 | if (!HIDE_STACK_CRAWLS) { |
| 3934 | e = new RuntimeException(); |
| 3935 | e.fillInStackTrace(); |
| 3936 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3937 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3938 | + "): mNextAppTransition=" + mNextAppTransition |
| 3939 | + " hidden=" + wtoken.hidden |
| 3940 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3941 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3943 | // If we are preparing an app transition, then delay changing |
| 3944 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3945 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3946 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3947 | // Already in requested state, don't do anything more. |
| 3948 | if (wtoken.hiddenRequested != visible) { |
| 3949 | return; |
| 3950 | } |
| 3951 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3952 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3953 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | TAG, "Setting dummy animation on: " + wtoken); |
| 3955 | wtoken.setDummyAnimation(); |
| 3956 | mOpeningApps.remove(wtoken); |
| 3957 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3958 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3959 | wtoken.inPendingTransaction = true; |
| 3960 | if (visible) { |
| 3961 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3962 | wtoken.startingDisplayed = false; |
| 3963 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3964 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3965 | // If the token is currently hidden (should be the |
| 3966 | // common case), then we need to set up to wait for |
| 3967 | // its windows to be ready. |
| 3968 | if (wtoken.hidden) { |
| 3969 | wtoken.allDrawn = false; |
| 3970 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3971 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3972 | if (wtoken.clientHidden) { |
| 3973 | // In the case where we are making an app visible |
| 3974 | // but holding off for a transition, we still need |
| 3975 | // to tell the client to make its windows visible so |
| 3976 | // they get drawn. Otherwise, we will wait on |
| 3977 | // performing the transition until all windows have |
| 3978 | // been drawn, they never will be, and we are sad. |
| 3979 | wtoken.clientHidden = false; |
| 3980 | wtoken.sendAppVisibilityToClients(); |
| 3981 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | } |
| 3983 | } else { |
| 3984 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3985 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3986 | // If the token is currently visible (should be the |
| 3987 | // common case), then set up to wait for it to be hidden. |
| 3988 | if (!wtoken.hidden) { |
| 3989 | wtoken.waitingToHide = true; |
| 3990 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3991 | } |
| 3992 | return; |
| 3993 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3994 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3995 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3996 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | wtoken.updateReportedVisibilityLocked(); |
| 3998 | Binder.restoreCallingIdentity(origId); |
| 3999 | } |
| 4000 | } |
| 4001 | |
| 4002 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4003 | boolean unfreezeSurfaceNow, boolean force) { |
| 4004 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4005 | 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] | 4006 | + " force=" + force); |
| 4007 | final int N = wtoken.allAppWindows.size(); |
| 4008 | boolean unfrozeWindows = false; |
| 4009 | for (int i=0; i<N; i++) { |
| 4010 | WindowState w = wtoken.allAppWindows.get(i); |
| 4011 | if (w.mAppFreezing) { |
| 4012 | w.mAppFreezing = false; |
| 4013 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4014 | w.mOrientationChanging = true; |
| 4015 | } |
| 4016 | unfrozeWindows = true; |
| 4017 | } |
| 4018 | } |
| 4019 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4020 | 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] | 4021 | wtoken.freezingScreen = false; |
| 4022 | mAppsFreezingScreen--; |
| 4023 | } |
| 4024 | if (unfreezeSurfaceNow) { |
| 4025 | if (unfrozeWindows) { |
| 4026 | mLayoutNeeded = true; |
| 4027 | performLayoutAndPlaceSurfacesLocked(); |
| 4028 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4029 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | } |
| 4031 | } |
| 4032 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4033 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4035 | int configChanges) { |
| 4036 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4037 | RuntimeException e = null; |
| 4038 | if (!HIDE_STACK_CRAWLS) { |
| 4039 | e = new RuntimeException(); |
| 4040 | e.fillInStackTrace(); |
| 4041 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4042 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4044 | + wtoken.freezingScreen, e); |
| 4045 | } |
| 4046 | if (!wtoken.hiddenRequested) { |
| 4047 | if (!wtoken.freezingScreen) { |
| 4048 | wtoken.freezingScreen = true; |
| 4049 | mAppsFreezingScreen++; |
| 4050 | if (mAppsFreezingScreen == 1) { |
| 4051 | startFreezingDisplayLocked(); |
| 4052 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4053 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4054 | 5000); |
| 4055 | } |
| 4056 | } |
| 4057 | final int N = wtoken.allAppWindows.size(); |
| 4058 | for (int i=0; i<N; i++) { |
| 4059 | WindowState w = wtoken.allAppWindows.get(i); |
| 4060 | w.mAppFreezing = true; |
| 4061 | } |
| 4062 | } |
| 4063 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4064 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4065 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4066 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4067 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4068 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4072 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4073 | 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] | 4074 | return; |
| 4075 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4076 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4078 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4079 | 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] | 4080 | return; |
| 4081 | } |
| 4082 | final long origId = Binder.clearCallingIdentity(); |
| 4083 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4084 | Binder.restoreCallingIdentity(origId); |
| 4085 | } |
| 4086 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4087 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4089 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4090 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4091 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | synchronized(mWindowMap) { |
| 4095 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4096 | if (wtoken == null || wtoken.appToken == null) { |
| 4097 | return; |
| 4098 | } |
| 4099 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4100 | 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] | 4101 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4102 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4103 | Binder.restoreCallingIdentity(origId); |
| 4104 | } |
| 4105 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4107 | public void removeAppToken(IBinder token) { |
| 4108 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4109 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4110 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4111 | } |
| 4112 | |
| 4113 | AppWindowToken wtoken = null; |
| 4114 | AppWindowToken startingToken = null; |
| 4115 | boolean delayed = false; |
| 4116 | |
| 4117 | final long origId = Binder.clearCallingIdentity(); |
| 4118 | synchronized(mWindowMap) { |
| 4119 | WindowToken basewtoken = mTokenMap.remove(token); |
| 4120 | mTokenList.remove(basewtoken); |
| 4121 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4122 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4123 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | wtoken.inPendingTransaction = false; |
| 4125 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4126 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | if (mClosingApps.contains(wtoken)) { |
| 4128 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4129 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4130 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4131 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | delayed = true; |
| 4133 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4134 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4136 | + " animation=" + wtoken.animation |
| 4137 | + " animating=" + wtoken.animating); |
| 4138 | if (delayed) { |
| 4139 | // set the token aside because it has an active animation to be finished |
| 4140 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4141 | } else { |
| 4142 | // Make sure there is no animation running on this token, |
| 4143 | // so any windows associated with it will be removed as |
| 4144 | // soon as their animations are complete |
| 4145 | wtoken.animation = null; |
| 4146 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4147 | } |
| 4148 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4149 | if (mLastEnterAnimToken == wtoken) { |
| 4150 | mLastEnterAnimToken = null; |
| 4151 | mLastEnterAnimParams = null; |
| 4152 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | wtoken.removed = true; |
| 4154 | if (wtoken.startingData != null) { |
| 4155 | startingToken = wtoken; |
| 4156 | } |
| 4157 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4158 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4159 | 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] | 4160 | mFocusedApp = null; |
| 4161 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4162 | mInputMonitor.setFocusedAppLw(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | } |
| 4164 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4165 | 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] | 4166 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | if (!delayed && wtoken != null) { |
| 4169 | wtoken.updateReportedVisibilityLocked(); |
| 4170 | } |
| 4171 | } |
| 4172 | Binder.restoreCallingIdentity(origId); |
| 4173 | |
| 4174 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4175 | 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] | 4176 | + startingToken + ": app token removed"); |
| 4177 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4178 | mH.sendMessage(m); |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4183 | final int NW = token.windows.size(); |
| 4184 | for (int i=0; i<NW; i++) { |
| 4185 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4186 | 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] | 4187 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4188 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | int j = win.mChildWindows.size(); |
| 4190 | while (j > 0) { |
| 4191 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4192 | WindowState cwin = win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4193 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4194 | "Tmp removing child window " + cwin); |
| 4195 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | } |
| 4197 | } |
| 4198 | return NW > 0; |
| 4199 | } |
| 4200 | |
| 4201 | void dumpAppTokensLocked() { |
| 4202 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4203 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4204 | } |
| 4205 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | void dumpWindowsLocked() { |
| 4208 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4209 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4210 | } |
| 4211 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4213 | private int findWindowOffsetLocked(int tokenPos) { |
| 4214 | final int NW = mWindows.size(); |
| 4215 | |
| 4216 | if (tokenPos >= mAppTokens.size()) { |
| 4217 | int i = NW; |
| 4218 | while (i > 0) { |
| 4219 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4220 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | if (win.getAppToken() != null) { |
| 4222 | return i+1; |
| 4223 | } |
| 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | while (tokenPos > 0) { |
| 4228 | // Find the first app token below the new position that has |
| 4229 | // a window displayed. |
| 4230 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4231 | 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] | 4232 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4233 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4234 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4235 | "Skipping token -- currently sending to bottom"); |
| 4236 | tokenPos--; |
| 4237 | continue; |
| 4238 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4239 | int i = wtoken.windows.size(); |
| 4240 | while (i > 0) { |
| 4241 | i--; |
| 4242 | WindowState win = wtoken.windows.get(i); |
| 4243 | int j = win.mChildWindows.size(); |
| 4244 | while (j > 0) { |
| 4245 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4246 | WindowState cwin = win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4247 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4248 | for (int pos=NW-1; pos>=0; pos--) { |
| 4249 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4250 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4251 | "Found child win @" + (pos+1)); |
| 4252 | return pos+1; |
| 4253 | } |
| 4254 | } |
| 4255 | } |
| 4256 | } |
| 4257 | for (int pos=NW-1; pos>=0; pos--) { |
| 4258 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4259 | 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] | 4260 | return pos+1; |
| 4261 | } |
| 4262 | } |
| 4263 | } |
| 4264 | tokenPos--; |
| 4265 | } |
| 4266 | |
| 4267 | return 0; |
| 4268 | } |
| 4269 | |
| 4270 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4271 | final int NCW = win.mChildWindows.size(); |
| 4272 | boolean added = false; |
| 4273 | for (int j=0; j<NCW; j++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4274 | WindowState cwin = win.mChildWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4275 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4276 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4277 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | mWindows.add(index, win); |
| 4279 | index++; |
| 4280 | added = true; |
| 4281 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4282 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4283 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | mWindows.add(index, cwin); |
| 4285 | index++; |
| 4286 | } |
| 4287 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4288 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4289 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | mWindows.add(index, win); |
| 4291 | index++; |
| 4292 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4293 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4294 | return index; |
| 4295 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4296 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4297 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4298 | final int NW = token.windows.size(); |
| 4299 | for (int i=0; i<NW; i++) { |
| 4300 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4301 | } |
| 4302 | return index; |
| 4303 | } |
| 4304 | |
| 4305 | public void moveAppToken(int index, IBinder token) { |
| 4306 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4307 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4308 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4312 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4313 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4314 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4315 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4316 | 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] | 4317 | + token + " (" + wtoken + ")"); |
| 4318 | return; |
| 4319 | } |
| 4320 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4321 | 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] | 4322 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4325 | 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] | 4326 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4327 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4328 | 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] | 4329 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4330 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4331 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4333 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | mLayoutNeeded = true; |
| 4335 | performLayoutAndPlaceSurfacesLocked(); |
| 4336 | } |
| 4337 | Binder.restoreCallingIdentity(origId); |
| 4338 | } |
| 4339 | } |
| 4340 | |
| 4341 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4342 | // XXX This should be done more efficiently! |
| 4343 | // (take advantage of the fact that both lists should be |
| 4344 | // ordered in the same way.) |
| 4345 | int N = tokens.size(); |
| 4346 | for (int i=0; i<N; i++) { |
| 4347 | IBinder token = tokens.get(i); |
| 4348 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4349 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4350 | 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] | 4351 | + token + " (" + wtoken + ")"); |
| 4352 | i--; |
| 4353 | N--; |
| 4354 | } |
| 4355 | } |
| 4356 | } |
| 4357 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4358 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4359 | boolean updateFocusAndLayout) { |
| 4360 | // First remove all of the windows from the list. |
| 4361 | tmpRemoveAppWindowsLocked(wtoken); |
| 4362 | |
| 4363 | // Where to start adding? |
| 4364 | int pos = findWindowOffsetLocked(tokenPos); |
| 4365 | |
| 4366 | // And now add them back at the correct place. |
| 4367 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4368 | |
| 4369 | if (updateFocusAndLayout) { |
| 4370 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4371 | assignLayersLocked(); |
| 4372 | } |
| 4373 | mLayoutNeeded = true; |
| 4374 | performLayoutAndPlaceSurfacesLocked(); |
| 4375 | } |
| 4376 | } |
| 4377 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4379 | // First remove all of the windows from the list. |
| 4380 | final int N = tokens.size(); |
| 4381 | int i; |
| 4382 | for (i=0; i<N; i++) { |
| 4383 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4384 | if (token != null) { |
| 4385 | tmpRemoveAppWindowsLocked(token); |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | // Where to start adding? |
| 4390 | int pos = findWindowOffsetLocked(tokenPos); |
| 4391 | |
| 4392 | // And now add them back at the correct place. |
| 4393 | for (i=0; i<N; i++) { |
| 4394 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4395 | if (token != null) { |
| 4396 | pos = reAddAppWindowsLocked(pos, token); |
| 4397 | } |
| 4398 | } |
| 4399 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4400 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4401 | assignLayersLocked(); |
| 4402 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | mLayoutNeeded = true; |
| 4404 | performLayoutAndPlaceSurfacesLocked(); |
| 4405 | |
| 4406 | //dump(); |
| 4407 | } |
| 4408 | |
| 4409 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4410 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4411 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4412 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | final long origId = Binder.clearCallingIdentity(); |
| 4416 | synchronized(mWindowMap) { |
| 4417 | removeAppTokensLocked(tokens); |
| 4418 | final int N = tokens.size(); |
| 4419 | for (int i=0; i<N; i++) { |
| 4420 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4421 | if (wt != null) { |
| 4422 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4423 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4424 | mToTopApps.remove(wt); |
| 4425 | mToBottomApps.remove(wt); |
| 4426 | mToTopApps.add(wt); |
| 4427 | wt.sendingToBottom = false; |
| 4428 | wt.sendingToTop = true; |
| 4429 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4430 | } |
| 4431 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4432 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4433 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4434 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4435 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | } |
| 4437 | Binder.restoreCallingIdentity(origId); |
| 4438 | } |
| 4439 | |
| 4440 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4441 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4442 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4443 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | final long origId = Binder.clearCallingIdentity(); |
| 4447 | synchronized(mWindowMap) { |
| 4448 | removeAppTokensLocked(tokens); |
| 4449 | final int N = tokens.size(); |
| 4450 | int pos = 0; |
| 4451 | for (int i=0; i<N; i++) { |
| 4452 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4453 | if (wt != null) { |
| 4454 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4455 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4456 | mToTopApps.remove(wt); |
| 4457 | mToBottomApps.remove(wt); |
| 4458 | mToBottomApps.add(i, wt); |
| 4459 | wt.sendingToTop = false; |
| 4460 | wt.sendingToBottom = true; |
| 4461 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | pos++; |
| 4463 | } |
| 4464 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4465 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4466 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4467 | moveAppWindowsLocked(tokens, 0); |
| 4468 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | } |
| 4470 | Binder.restoreCallingIdentity(origId); |
| 4471 | } |
| 4472 | |
| 4473 | // ------------------------------------------------------------- |
| 4474 | // Misc IWindowSession methods |
| 4475 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4476 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4477 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4478 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4479 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4480 | // called before DevicePolicyManagerService has started. |
| 4481 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4482 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4483 | Context.DEVICE_POLICY_SERVICE); |
| 4484 | if (dpm != null) { |
| 4485 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4486 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4487 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4488 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4489 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4490 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4491 | } |
| 4492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4494 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4495 | != PackageManager.PERMISSION_GRANTED) { |
| 4496 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4497 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4498 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4499 | synchronized (mKeyguardTokenWatcher) { |
| 4500 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4501 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4505 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | != PackageManager.PERMISSION_GRANTED) { |
| 4507 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4508 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4510 | synchronized (mKeyguardTokenWatcher) { |
| 4511 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4512 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4513 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4514 | // If we are the last one to reenable the keyguard wait until |
| 4515 | // we have actually finished reenabling until returning. |
| 4516 | // It is possible that reenableKeyguard() can be called before |
| 4517 | // the previous disableKeyguard() is handled, in which case |
| 4518 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4519 | // be called. In that case mKeyguardDisabled will be false here |
| 4520 | // and we have nothing to wait for. |
| 4521 | while (mKeyguardDisabled) { |
| 4522 | try { |
| 4523 | mKeyguardTokenWatcher.wait(); |
| 4524 | } catch (InterruptedException e) { |
| 4525 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | } |
| 4527 | } |
| 4528 | } |
| 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | /** |
| 4533 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4534 | */ |
| 4535 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4536 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4537 | != PackageManager.PERMISSION_GRANTED) { |
| 4538 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4539 | } |
| 4540 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4541 | public void onKeyguardExitResult(boolean success) { |
| 4542 | try { |
| 4543 | callback.onKeyguardExitResult(success); |
| 4544 | } catch (RemoteException e) { |
| 4545 | // Client has died, we don't care. |
| 4546 | } |
| 4547 | } |
| 4548 | }); |
| 4549 | } |
| 4550 | |
| 4551 | public boolean inKeyguardRestrictedInputMode() { |
| 4552 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4553 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4554 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4555 | public void closeSystemDialogs(String reason) { |
| 4556 | synchronized(mWindowMap) { |
| 4557 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4558 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4559 | if (w.mSurface != null) { |
| 4560 | try { |
| 4561 | w.mClient.closeSystemDialogs(reason); |
| 4562 | } catch (RemoteException e) { |
| 4563 | } |
| 4564 | } |
| 4565 | } |
| 4566 | } |
| 4567 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4568 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4569 | static float fixScale(float scale) { |
| 4570 | if (scale < 0) scale = 0; |
| 4571 | else if (scale > 20) scale = 20; |
| 4572 | return Math.abs(scale); |
| 4573 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4575 | public void setAnimationScale(int which, float scale) { |
| 4576 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4577 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4578 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | if (scale < 0) scale = 0; |
| 4582 | else if (scale > 20) scale = 20; |
| 4583 | scale = Math.abs(scale); |
| 4584 | switch (which) { |
| 4585 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4586 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4587 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4589 | // Persist setting |
| 4590 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4591 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4592 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4593 | public void setAnimationScales(float[] scales) { |
| 4594 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4595 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4596 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | if (scales != null) { |
| 4600 | if (scales.length >= 1) { |
| 4601 | mWindowAnimationScale = fixScale(scales[0]); |
| 4602 | } |
| 4603 | if (scales.length >= 2) { |
| 4604 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4605 | } |
| 4606 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4608 | // Persist setting |
| 4609 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4610 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | public float getAnimationScale(int which) { |
| 4613 | switch (which) { |
| 4614 | case 0: return mWindowAnimationScale; |
| 4615 | case 1: return mTransitionAnimationScale; |
| 4616 | } |
| 4617 | return 0; |
| 4618 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4619 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4620 | public float[] getAnimationScales() { |
| 4621 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4622 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | public int getSwitchState(int sw) { |
| 4625 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4626 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4627 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4628 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4629 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4630 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4631 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4632 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4633 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4634 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4635 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4636 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4637 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4638 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4639 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4640 | public int getScancodeState(int sw) { |
| 4641 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4642 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4643 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4645 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4647 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4649 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4650 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4651 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4652 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4653 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4654 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4655 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4656 | public int getTrackballScancodeState(int sw) { |
| 4657 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4658 | "getTrackballScancodeState()")) { |
| 4659 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4660 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4661 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | public int getDPadScancodeState(int sw) { |
| 4665 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4666 | "getDPadScancodeState()")) { |
| 4667 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4668 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4669 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4670 | } |
| 4671 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4672 | public int getKeycodeState(int sw) { |
| 4673 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4674 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4675 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4676 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4677 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4678 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4680 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4681 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4682 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4683 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4685 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4686 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4687 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4688 | public int getTrackballKeycodeState(int sw) { |
| 4689 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4690 | "getTrackballKeycodeState()")) { |
| 4691 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4692 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4693 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4694 | } |
| 4695 | |
| 4696 | public int getDPadKeycodeState(int sw) { |
| 4697 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4698 | "getDPadKeycodeState()")) { |
| 4699 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4700 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4701 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4702 | } |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4703 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4704 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4705 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4707 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4708 | public InputChannel monitorInput(String inputChannelName) { |
| 4709 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4710 | "monitorInput()")) { |
| 4711 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4712 | } |
| 4713 | return mInputManager.monitorInput(inputChannelName); |
| 4714 | } |
| 4715 | |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4716 | public InputDevice getInputDevice(int deviceId) { |
| 4717 | return mInputManager.getInputDevice(deviceId); |
| 4718 | } |
| 4719 | |
| 4720 | public int[] getInputDeviceIds() { |
| 4721 | return mInputManager.getInputDeviceIds(); |
| 4722 | } |
| 4723 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | public void enableScreenAfterBoot() { |
| 4725 | synchronized(mWindowMap) { |
| 4726 | if (mSystemBooted) { |
| 4727 | return; |
| 4728 | } |
| 4729 | mSystemBooted = true; |
| 4730 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4731 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4732 | performEnableScreen(); |
| 4733 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4734 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4735 | public void enableScreenIfNeededLocked() { |
| 4736 | if (mDisplayEnabled) { |
| 4737 | return; |
| 4738 | } |
| 4739 | if (!mSystemBooted) { |
| 4740 | return; |
| 4741 | } |
| 4742 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4745 | public void performEnableScreen() { |
| 4746 | synchronized(mWindowMap) { |
| 4747 | if (mDisplayEnabled) { |
| 4748 | return; |
| 4749 | } |
| 4750 | if (!mSystemBooted) { |
| 4751 | return; |
| 4752 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4753 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4754 | // Don't enable the screen until all existing windows |
| 4755 | // have been drawn. |
| 4756 | final int N = mWindows.size(); |
| 4757 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4758 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4759 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4760 | return; |
| 4761 | } |
| 4762 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4763 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4764 | mDisplayEnabled = true; |
| 4765 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4766 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4767 | StringWriter sw = new StringWriter(); |
| 4768 | PrintWriter pw = new PrintWriter(sw); |
| 4769 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4770 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4771 | } |
| 4772 | try { |
| 4773 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4774 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4775 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4776 | Parcel data = Parcel.obtain(); |
| 4777 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4778 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4779 | data, null, 0); |
| 4780 | data.recycle(); |
| 4781 | } |
| 4782 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4783 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4784 | } |
| 4785 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4786 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4787 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4789 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4790 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4791 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4792 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4793 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | public void setInTouchMode(boolean mode) { |
| 4795 | synchronized(mWindowMap) { |
| 4796 | mInTouchMode = mode; |
| 4797 | } |
| 4798 | } |
| 4799 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4800 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4801 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4802 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4803 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4804 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4805 | } |
| 4806 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4807 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4808 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4809 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4810 | public void setRotationUnchecked(int rotation, |
| 4811 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4812 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4813 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4814 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4815 | long origId = Binder.clearCallingIdentity(); |
| 4816 | boolean changed; |
| 4817 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4818 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4819 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4820 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4821 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | sendNewConfiguration(); |
| 4823 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4824 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4825 | Binder.restoreCallingIdentity(origId); |
| 4826 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4827 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4828 | /** |
| 4829 | * Apply a new rotation to the screen, respecting the requests of |
| 4830 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4831 | * re-evaluate the desired rotation. |
| 4832 | * |
| 4833 | * Returns null if the rotation has been changed. In this case YOU |
| 4834 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4835 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4836 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4837 | boolean changed; |
| 4838 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4839 | rotation = mRequestedRotation; |
| 4840 | } else { |
| 4841 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4842 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4843 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4844 | 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] | 4845 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4846 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4847 | 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] | 4848 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4850 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4851 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4852 | "Rotation changed to " + rotation |
| 4853 | + " from " + mRotation |
| 4854 | + " (forceApp=" + mForcedAppOrientation |
| 4855 | + ", req=" + mRequestedRotation + ")"); |
| 4856 | mRotation = rotation; |
| 4857 | mWindowsFreezingScreen = true; |
| 4858 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4859 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4860 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4861 | mWaitingForConfig = true; |
| 4862 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4863 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4864 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4865 | mInputManager.setDisplayOrientation(0, rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4866 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4867 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4868 | } |
| 4869 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4870 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | if (w.mSurface != null) { |
| 4872 | w.mOrientationChanging = true; |
| 4873 | } |
| 4874 | } |
| 4875 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4876 | try { |
| 4877 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4878 | } catch (RemoteException e) { |
| 4879 | } |
| 4880 | } |
| 4881 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | return changed; |
| 4884 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | public int getRotation() { |
| 4887 | return mRotation; |
| 4888 | } |
| 4889 | |
| 4890 | public int watchRotation(IRotationWatcher watcher) { |
| 4891 | final IBinder watcherBinder = watcher.asBinder(); |
| 4892 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4893 | public void binderDied() { |
| 4894 | synchronized (mWindowMap) { |
| 4895 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4896 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4897 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4898 | if (removed != null) { |
| 4899 | removed.asBinder().unlinkToDeath(this, 0); |
| 4900 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4901 | i--; |
| 4902 | } |
| 4903 | } |
| 4904 | } |
| 4905 | } |
| 4906 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4907 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | synchronized (mWindowMap) { |
| 4909 | try { |
| 4910 | watcher.asBinder().linkToDeath(dr, 0); |
| 4911 | mRotationWatchers.add(watcher); |
| 4912 | } catch (RemoteException e) { |
| 4913 | // Client died, no cleanup needed. |
| 4914 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4916 | return mRotation; |
| 4917 | } |
| 4918 | } |
| 4919 | |
| 4920 | /** |
| 4921 | * Starts the view server on the specified port. |
| 4922 | * |
| 4923 | * @param port The port to listener to. |
| 4924 | * |
| 4925 | * @return True if the server was successfully started, false otherwise. |
| 4926 | * |
| 4927 | * @see com.android.server.ViewServer |
| 4928 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4929 | */ |
| 4930 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4931 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4932 | return false; |
| 4933 | } |
| 4934 | |
| 4935 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4936 | return false; |
| 4937 | } |
| 4938 | |
| 4939 | if (port < 1024) { |
| 4940 | return false; |
| 4941 | } |
| 4942 | |
| 4943 | if (mViewServer != null) { |
| 4944 | if (!mViewServer.isRunning()) { |
| 4945 | try { |
| 4946 | return mViewServer.start(); |
| 4947 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4948 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4949 | } |
| 4950 | } |
| 4951 | return false; |
| 4952 | } |
| 4953 | |
| 4954 | try { |
| 4955 | mViewServer = new ViewServer(this, port); |
| 4956 | return mViewServer.start(); |
| 4957 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4958 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4959 | } |
| 4960 | return false; |
| 4961 | } |
| 4962 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4963 | private boolean isSystemSecure() { |
| 4964 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4965 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4966 | } |
| 4967 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4968 | /** |
| 4969 | * Stops the view server if it exists. |
| 4970 | * |
| 4971 | * @return True if the server stopped, false if it wasn't started or |
| 4972 | * couldn't be stopped. |
| 4973 | * |
| 4974 | * @see com.android.server.ViewServer |
| 4975 | */ |
| 4976 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4977 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4978 | return false; |
| 4979 | } |
| 4980 | |
| 4981 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4982 | return false; |
| 4983 | } |
| 4984 | |
| 4985 | if (mViewServer != null) { |
| 4986 | return mViewServer.stop(); |
| 4987 | } |
| 4988 | return false; |
| 4989 | } |
| 4990 | |
| 4991 | /** |
| 4992 | * Indicates whether the view server is running. |
| 4993 | * |
| 4994 | * @return True if the server is running, false otherwise. |
| 4995 | * |
| 4996 | * @see com.android.server.ViewServer |
| 4997 | */ |
| 4998 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4999 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5000 | return false; |
| 5001 | } |
| 5002 | |
| 5003 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5004 | return false; |
| 5005 | } |
| 5006 | |
| 5007 | return mViewServer != null && mViewServer.isRunning(); |
| 5008 | } |
| 5009 | |
| 5010 | /** |
| 5011 | * Lists all availble windows in the system. The listing is written in the |
| 5012 | * specified Socket's output stream with the following syntax: |
| 5013 | * windowHashCodeInHexadecimal windowName |
| 5014 | * Each line of the ouput represents a different window. |
| 5015 | * |
| 5016 | * @param client The remote client to send the listing to. |
| 5017 | * @return False if an error occured, true otherwise. |
| 5018 | */ |
| 5019 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5020 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5021 | return false; |
| 5022 | } |
| 5023 | |
| 5024 | boolean result = true; |
| 5025 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5026 | WindowState[] windows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5027 | synchronized (mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5028 | //noinspection unchecked |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5029 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | BufferedWriter out = null; |
| 5033 | |
| 5034 | // Any uncaught exception will crash the system process |
| 5035 | try { |
| 5036 | OutputStream clientStream = client.getOutputStream(); |
| 5037 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5038 | |
| 5039 | final int count = windows.length; |
| 5040 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5041 | final WindowState w = windows[i]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5042 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5043 | out.write(' '); |
| 5044 | out.append(w.mAttrs.getTitle()); |
| 5045 | out.write('\n'); |
| 5046 | } |
| 5047 | |
| 5048 | out.write("DONE.\n"); |
| 5049 | out.flush(); |
| 5050 | } catch (Exception e) { |
| 5051 | result = false; |
| 5052 | } finally { |
| 5053 | if (out != null) { |
| 5054 | try { |
| 5055 | out.close(); |
| 5056 | } catch (IOException e) { |
| 5057 | result = false; |
| 5058 | } |
| 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | return result; |
| 5063 | } |
| 5064 | |
| 5065 | /** |
| Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5066 | * Returns the focused window in the following format: |
| 5067 | * windowHashCodeInHexadecimal windowName |
| 5068 | * |
| 5069 | * @param client The remote client to send the listing to. |
| 5070 | * @return False if an error occurred, true otherwise. |
| 5071 | */ |
| 5072 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5073 | if (isSystemSecure()) { |
| 5074 | return false; |
| 5075 | } |
| 5076 | |
| 5077 | boolean result = true; |
| 5078 | |
| 5079 | WindowState focusedWindow = getFocusedWindow(); |
| 5080 | |
| 5081 | BufferedWriter out = null; |
| 5082 | |
| 5083 | // Any uncaught exception will crash the system process |
| 5084 | try { |
| 5085 | OutputStream clientStream = client.getOutputStream(); |
| 5086 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5087 | |
| 5088 | if(focusedWindow != null) { |
| 5089 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5090 | out.write(' '); |
| 5091 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5092 | } |
| 5093 | out.write('\n'); |
| 5094 | out.flush(); |
| 5095 | } catch (Exception e) { |
| 5096 | result = false; |
| 5097 | } finally { |
| 5098 | if (out != null) { |
| 5099 | try { |
| 5100 | out.close(); |
| 5101 | } catch (IOException e) { |
| 5102 | result = false; |
| 5103 | } |
| 5104 | } |
| 5105 | } |
| 5106 | |
| 5107 | return result; |
| 5108 | } |
| 5109 | |
| 5110 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5111 | * Sends a command to a target window. The result of the command, if any, will be |
| 5112 | * written in the output stream of the specified socket. |
| 5113 | * |
| 5114 | * The parameters must follow this syntax: |
| 5115 | * windowHashcode extra |
| 5116 | * |
| 5117 | * Where XX is the length in characeters of the windowTitle. |
| 5118 | * |
| 5119 | * The first parameter is the target window. The window with the specified hashcode |
| 5120 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5121 | * will be delivered to the target window and as parameters to the command itself. |
| 5122 | * |
| 5123 | * @param client The remote client to sent the result, if any, to. |
| 5124 | * @param command The command to execute. |
| 5125 | * @param parameters The command parameters. |
| 5126 | * |
| 5127 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5128 | * not indicate whether the command itself was successful. |
| 5129 | */ |
| 5130 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5131 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5132 | return false; |
| 5133 | } |
| 5134 | |
| 5135 | boolean success = true; |
| 5136 | Parcel data = null; |
| 5137 | Parcel reply = null; |
| 5138 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5139 | BufferedWriter out = null; |
| 5140 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5141 | // Any uncaught exception will crash the system process |
| 5142 | try { |
| 5143 | // Find the hashcode of the window |
| 5144 | int index = parameters.indexOf(' '); |
| 5145 | if (index == -1) { |
| 5146 | index = parameters.length(); |
| 5147 | } |
| 5148 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5149 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5150 | |
| 5151 | // Extract the command's parameter after the window description |
| 5152 | if (index < parameters.length()) { |
| 5153 | parameters = parameters.substring(index + 1); |
| 5154 | } else { |
| 5155 | parameters = ""; |
| 5156 | } |
| 5157 | |
| 5158 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5159 | if (window == null) { |
| 5160 | return false; |
| 5161 | } |
| 5162 | |
| 5163 | data = Parcel.obtain(); |
| 5164 | data.writeInterfaceToken("android.view.IWindow"); |
| 5165 | data.writeString(command); |
| 5166 | data.writeString(parameters); |
| 5167 | data.writeInt(1); |
| 5168 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5169 | |
| 5170 | reply = Parcel.obtain(); |
| 5171 | |
| 5172 | final IBinder binder = window.mClient.asBinder(); |
| 5173 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5174 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5175 | |
| 5176 | reply.readException(); |
| 5177 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5178 | if (!client.isOutputShutdown()) { |
| 5179 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5180 | out.write("DONE\n"); |
| 5181 | out.flush(); |
| 5182 | } |
| 5183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5185 | 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] | 5186 | success = false; |
| 5187 | } finally { |
| 5188 | if (data != null) { |
| 5189 | data.recycle(); |
| 5190 | } |
| 5191 | if (reply != null) { |
| 5192 | reply.recycle(); |
| 5193 | } |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5194 | if (out != null) { |
| 5195 | try { |
| 5196 | out.close(); |
| 5197 | } catch (IOException e) { |
| 5198 | |
| 5199 | } |
| 5200 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | return success; |
| 5204 | } |
| 5205 | |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5206 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5207 | synchronized(mWindowMap) { |
| 5208 | mWindowChangeListeners.add(listener); |
| 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5213 | synchronized(mWindowMap) { |
| 5214 | mWindowChangeListeners.remove(listener); |
| 5215 | } |
| 5216 | } |
| 5217 | |
| 5218 | private void notifyWindowsChanged() { |
| 5219 | WindowChangeListener[] windowChangeListeners; |
| 5220 | synchronized(mWindowMap) { |
| 5221 | if(mWindowChangeListeners.isEmpty()) { |
| 5222 | return; |
| 5223 | } |
| 5224 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5225 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5226 | } |
| 5227 | int N = windowChangeListeners.length; |
| 5228 | for(int i = 0; i < N; i++) { |
| 5229 | windowChangeListeners[i].windowsChanged(); |
| 5230 | } |
| 5231 | } |
| 5232 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5233 | private void notifyFocusChanged() { |
| 5234 | WindowChangeListener[] windowChangeListeners; |
| 5235 | synchronized(mWindowMap) { |
| 5236 | if(mWindowChangeListeners.isEmpty()) { |
| 5237 | return; |
| 5238 | } |
| 5239 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5240 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5241 | } |
| 5242 | int N = windowChangeListeners.length; |
| 5243 | for(int i = 0; i < N; i++) { |
| 5244 | windowChangeListeners[i].focusChanged(); |
| 5245 | } |
| 5246 | } |
| 5247 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5248 | private WindowState findWindow(int hashCode) { |
| 5249 | if (hashCode == -1) { |
| 5250 | return getFocusedWindow(); |
| 5251 | } |
| 5252 | |
| 5253 | synchronized (mWindowMap) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5254 | final ArrayList<WindowState> windows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5255 | final int count = windows.size(); |
| 5256 | |
| 5257 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5258 | WindowState w = windows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5259 | if (System.identityHashCode(w) == hashCode) { |
| 5260 | return w; |
| 5261 | } |
| 5262 | } |
| 5263 | } |
| 5264 | |
| 5265 | return null; |
| 5266 | } |
| 5267 | |
| 5268 | /* |
| 5269 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5270 | * that to config-changed listeners if appropriate. |
| 5271 | */ |
| 5272 | void sendNewConfiguration() { |
| 5273 | try { |
| 5274 | mActivityManager.updateConfiguration(null); |
| 5275 | } catch (RemoteException e) { |
| 5276 | } |
| 5277 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5278 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | public Configuration computeNewConfiguration() { |
| 5280 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5281 | return computeNewConfigurationLocked(); |
| 5282 | } |
| 5283 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5284 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5285 | Configuration computeNewConfigurationLocked() { |
| 5286 | Configuration config = new Configuration(); |
| 5287 | if (!computeNewConfigurationLocked(config)) { |
| 5288 | return null; |
| 5289 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5290 | return config; |
| 5291 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5292 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5293 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5294 | if (mDisplay == null) { |
| 5295 | return false; |
| 5296 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5297 | |
| 5298 | mInputManager.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5299 | |
| 5300 | // Use the effective "visual" dimensions based on current rotation |
| 5301 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5302 | || mRotation == Surface.ROTATION_270); |
| 5303 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5304 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5305 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5306 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5307 | if (dw < dh) { |
| 5308 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5309 | } else if (dw > dh) { |
| 5310 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5311 | } |
| 5312 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5313 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5314 | DisplayMetrics dm = new DisplayMetrics(); |
| 5315 | mDisplay.getMetrics(dm); |
| 5316 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5317 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5318 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5319 | // Note we only do this once because at this point we don't |
| 5320 | // expect the screen to change in this way at runtime, and want |
| 5321 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5322 | int longSize = dw; |
| 5323 | int shortSize = dh; |
| 5324 | if (longSize < shortSize) { |
| 5325 | int tmp = longSize; |
| 5326 | longSize = shortSize; |
| 5327 | shortSize = tmp; |
| 5328 | } |
| 5329 | longSize = (int)(longSize/dm.density); |
| 5330 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5331 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5332 | // These semi-magic numbers define our compatibility modes for |
| 5333 | // applications with different screens. Don't change unless you |
| 5334 | // make sure to test lots and lots of apps! |
| 5335 | if (longSize < 470) { |
| 5336 | // This is shorter than an HVGA normal density screen (which |
| 5337 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5338 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5339 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5340 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5341 | // What size is this screen screen? |
| 5342 | if (longSize >= 800 && shortSize >= 600) { |
| 5343 | // SVGA or larger screens at medium density are the point |
| 5344 | // at which we consider it to be an extra large screen. |
| 5345 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 5346 | } else if (longSize >= 640 && shortSize >= 480) { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5347 | // VGA or larger screens at medium density are the point |
| 5348 | // at which we consider it to be a large screen. |
| 5349 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5350 | } else { |
| 5351 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5352 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5353 | // If this screen is wider than normal HVGA, or taller |
| 5354 | // than FWVGA, then for old apps we want to run in size |
| 5355 | // compatibility mode. |
| 5356 | if (shortSize > 321 || longSize > 570) { |
| 5357 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5358 | } |
| 5359 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5360 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5361 | // Is this a long screen? |
| 5362 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5363 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5364 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5365 | } else { |
| 5366 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5367 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5368 | } |
| 5369 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5370 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5371 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5372 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5373 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5374 | mPolicy.adjustConfigurationLw(config); |
| 5375 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5376 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5377 | |
| 5378 | // ------------------------------------------------------------- |
| 5379 | // Drag and drop |
| 5380 | // ------------------------------------------------------------- |
| 5381 | |
| 5382 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| 5383 | boolean localOnly, int width, int height, Surface outSurface) { |
| 5384 | if (DEBUG_DRAG) { |
| 5385 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| 5386 | + " local=" + localOnly + " win=" + window |
| 5387 | + " asbinder=" + window.asBinder()); |
| 5388 | } |
| 5389 | |
| 5390 | final int callerPid = Binder.getCallingPid(); |
| 5391 | final long origId = Binder.clearCallingIdentity(); |
| 5392 | IBinder token = null; |
| 5393 | |
| 5394 | try { |
| 5395 | synchronized (mWindowMap) { |
| 5396 | try { |
| 5397 | // !!! TODO: fail if the given window does not currently have touch focus? |
| 5398 | |
| 5399 | if (mDragState == null) { |
| 5400 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5401 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5402 | outSurface.copyFrom(surface); |
| 5403 | token = new Binder(); |
| 5404 | mDragState = new DragState(token, surface, localOnly); |
| 5405 | mDragState.mSurface = surface; |
| 5406 | mDragState.mLocalOnly = localOnly; |
| 5407 | token = mDragState.mToken = new Binder(); |
| 5408 | |
| 5409 | // 5 second timeout for this window to actually begin the drag |
| 5410 | mH.removeMessages(H.DRAG_START_TIMEOUT, window); |
| 5411 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 5412 | mH.sendMessageDelayed(msg, 5000); |
| 5413 | } else { |
| 5414 | Slog.w(TAG, "Drag already in progress"); |
| 5415 | } |
| 5416 | } catch (Surface.OutOfResourcesException e) { |
| 5417 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5418 | if (mDragState != null) { |
| 5419 | mDragState.reset(); |
| 5420 | mDragState = null; |
| 5421 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5422 | } |
| 5423 | } |
| 5424 | } finally { |
| 5425 | Binder.restoreCallingIdentity(origId); |
| 5426 | } |
| 5427 | |
| 5428 | return token; |
| 5429 | } |
| 5430 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5431 | // ------------------------------------------------------------- |
| 5432 | // Input Events and Focus Management |
| 5433 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5434 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5435 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5436 | |
| 5437 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5438 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5439 | * other relevant Window Manager state transitions. */ |
| 5440 | final class InputMonitor { |
| 5441 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5442 | private WindowState mInputFocus; |
| 5443 | |
| 5444 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5445 | private boolean mInputDispatchFrozen; |
| 5446 | |
| 5447 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5448 | private boolean mInputDispatchEnabled = true; |
| 5449 | |
| 5450 | // Temporary list of windows information to provide to the input dispatcher. |
| 5451 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5452 | |
| 5453 | // Temporary input application object to provide to the input dispatcher. |
| 5454 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5455 | |
| 5456 | /* Notifies the window manager about a broken input channel. |
| 5457 | * |
| 5458 | * Called by the InputManager. |
| 5459 | */ |
| 5460 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5461 | synchronized (mWindowMap) { |
| 5462 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5463 | if (windowState == null) { |
| 5464 | return; // irrelevant |
| 5465 | } |
| 5466 | |
| 5467 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5468 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5469 | } |
| 5470 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5471 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5472 | /* Notifies the window manager about an application that is not responding. |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5473 | * 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] | 5474 | * |
| 5475 | * Called by the InputManager. |
| 5476 | */ |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5477 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 5478 | AppWindowToken appWindowToken = null; |
| 5479 | if (inputChannel != null) { |
| 5480 | synchronized (mWindowMap) { |
| 5481 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5482 | if (windowState != null) { |
| 5483 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5484 | + windowState.mAttrs.getTitle()); |
| 5485 | appWindowToken = windowState.mAppToken; |
| 5486 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5487 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5488 | } |
| 5489 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5490 | if (appWindowToken == null && token != null) { |
| 5491 | appWindowToken = (AppWindowToken) token; |
| 5492 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5493 | + appWindowToken.stringName); |
| 5494 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5495 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5496 | if (appWindowToken != null && appWindowToken.appToken != null) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5497 | try { |
| 5498 | // Notify the activity manager about the timeout and let it decide whether |
| 5499 | // to abort dispatching or keep waiting. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5500 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5501 | if (! abort) { |
| 5502 | // The activity manager declined to abort dispatching. |
| 5503 | // Wait a bit longer and timeout again later. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5504 | return appWindowToken.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5505 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5506 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5507 | } |
| 5508 | } |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5509 | return 0; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5510 | } |
| 5511 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5512 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5513 | synchronized (mWindowMap) { |
| 5514 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5515 | } |
| 5516 | } |
| 5517 | |
| 5518 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5519 | int windowCount = mWindows.size(); |
| 5520 | for (int i = 0; i < windowCount; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5521 | WindowState windowState = mWindows.get(i); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5522 | if (windowState.mInputChannel == inputChannel) { |
| 5523 | return windowState; |
| 5524 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5525 | } |
| 5526 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5527 | return null; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5528 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5529 | |
| 5530 | private void addDragInputWindow(InputWindowList windowList) { |
| 5531 | final InputWindow inputWindow = windowList.add(); |
| 5532 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5533 | inputWindow.name = "drag"; |
| 5534 | inputWindow.layoutParamsFlags = 0; |
| 5535 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5536 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5537 | inputWindow.visible = true; |
| 5538 | inputWindow.canReceiveKeys = false; |
| 5539 | inputWindow.hasFocus = true; |
| 5540 | inputWindow.hasWallpaper = false; |
| 5541 | inputWindow.paused = false; |
| 5542 | inputWindow.layer = mPolicy.windowTypeToLayerLw(inputWindow.layoutParamsType) |
| 5543 | * TYPE_LAYER_MULTIPLIER |
| 5544 | + TYPE_LAYER_OFFSET; |
| 5545 | inputWindow.ownerPid = Process.myPid(); |
| 5546 | inputWindow.ownerUid = Process.myUid(); |
| 5547 | |
| 5548 | // The drag window covers the entire display |
| 5549 | inputWindow.frameLeft = 0; |
| 5550 | inputWindow.frameTop = 0; |
| 5551 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5552 | inputWindow.frameBottom = mDisplay.getHeight(); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5553 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5554 | inputWindow.visibleFrameLeft = inputWindow.frameLeft; |
| 5555 | inputWindow.visibleFrameTop = inputWindow.frameTop; |
| 5556 | inputWindow.visibleFrameRight = inputWindow.frameRight; |
| 5557 | inputWindow.visibleFrameBottom = inputWindow.frameBottom; |
| 5558 | |
| 5559 | inputWindow.touchableAreaLeft = inputWindow.frameLeft; |
| 5560 | inputWindow.touchableAreaTop = inputWindow.frameTop; |
| 5561 | inputWindow.touchableAreaRight = inputWindow.frameRight; |
| 5562 | inputWindow.touchableAreaBottom = inputWindow.frameBottom; |
| 5563 | } |
| 5564 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5565 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5566 | public void updateInputWindowsLw() { |
| 5567 | // Populate the input window list with information about all of the windows that |
| 5568 | // could potentially receive input. |
| 5569 | // As an optimization, we could try to prune the list of windows but this turns |
| 5570 | // out to be difficult because only the native code knows for sure which window |
| 5571 | // currently has touch focus. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5572 | final ArrayList<WindowState> windows = mWindows; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5573 | |
| 5574 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5575 | final boolean inDrag = (mDragState != null); |
| 5576 | if (inDrag) { |
| 5577 | if (DEBUG_DRAG) { |
| 5578 | Log.d(TAG, "Inserting drag window"); |
| 5579 | } |
| 5580 | addDragInputWindow(mTempInputWindows); |
| 5581 | } |
| 5582 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5583 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5584 | for (int i = N - 1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5585 | final WindowState child = windows.get(i); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5586 | if (child.mInputChannel == null || child.mRemoved) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5587 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5588 | continue; |
| 5589 | } |
| 5590 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5591 | final int flags = child.mAttrs.flags; |
| 5592 | final int type = child.mAttrs.type; |
| 5593 | |
| 5594 | final boolean hasFocus = (child == mInputFocus); |
| 5595 | final boolean isVisible = child.isVisibleLw(); |
| 5596 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5597 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5598 | |
| 5599 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5600 | // make sure it's been told about the drag |
| 5601 | if (inDrag && isVisible) { |
| 5602 | mDragState.sendDragStartedIfNeededLw(child); |
| 5603 | } |
| 5604 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5605 | // Add a window to our list of input windows. |
| 5606 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5607 | inputWindow.inputChannel = child.mInputChannel; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5608 | inputWindow.name = child.toString(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5609 | inputWindow.layoutParamsFlags = flags; |
| 5610 | inputWindow.layoutParamsType = type; |
| 5611 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5612 | inputWindow.visible = isVisible; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5613 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5614 | inputWindow.hasFocus = hasFocus; |
| 5615 | inputWindow.hasWallpaper = hasWallpaper; |
| 5616 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5617 | inputWindow.layer = child.mLayer; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5618 | inputWindow.ownerPid = child.mSession.mPid; |
| 5619 | inputWindow.ownerUid = child.mSession.mUid; |
| 5620 | |
| 5621 | final Rect frame = child.mFrame; |
| 5622 | inputWindow.frameLeft = frame.left; |
| 5623 | inputWindow.frameTop = frame.top; |
| Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5624 | inputWindow.frameRight = frame.right; |
| 5625 | inputWindow.frameBottom = frame.bottom; |
| 5626 | |
| 5627 | final Rect visibleFrame = child.mVisibleFrame; |
| 5628 | inputWindow.visibleFrameLeft = visibleFrame.left; |
| 5629 | inputWindow.visibleFrameTop = visibleFrame.top; |
| 5630 | inputWindow.visibleFrameRight = visibleFrame.right; |
| 5631 | inputWindow.visibleFrameBottom = visibleFrame.bottom; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5632 | |
| 5633 | switch (child.mTouchableInsets) { |
| 5634 | default: |
| 5635 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5636 | inputWindow.touchableAreaLeft = frame.left; |
| 5637 | inputWindow.touchableAreaTop = frame.top; |
| 5638 | inputWindow.touchableAreaRight = frame.right; |
| 5639 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5640 | break; |
| 5641 | |
| 5642 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5643 | Rect inset = child.mGivenContentInsets; |
| 5644 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5645 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5646 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5647 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5648 | break; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5649 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5650 | |
| 5651 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5652 | Rect inset = child.mGivenVisibleInsets; |
| 5653 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5654 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5655 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5656 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5657 | break; |
| 5658 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5659 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5660 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5661 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5662 | // Send windows to native code. |
| 5663 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5664 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5665 | // Clear the list in preparation for the next round. |
| 5666 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5667 | mTempInputWindows.clear(); |
| 5668 | } |
| 5669 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5670 | /* Provides feedback for a virtual key down. */ |
| 5671 | public void virtualKeyDownFeedback() { |
| 5672 | synchronized (mWindowMap) { |
| 5673 | mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5674 | } |
| 5675 | } |
| 5676 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5677 | /* Notifies that the lid switch changed state. */ |
| 5678 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5679 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5680 | } |
| 5681 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5682 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5683 | * processing as soon as the key has been read from the device. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5684 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5685 | int policyFlags, boolean isScreenOn) { |
| 5686 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5687 | keyCode, down, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | /* Provides an opportunity for the window manager policy to process a key before |
| 5691 | * ordinary dispatch. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5692 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5693 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5694 | int policyFlags) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5695 | WindowState windowState = getWindowStateForInputChannel(focus); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5696 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5697 | keyCode, metaState, repeatCount, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | /* Called when the current input focus changes. |
| 5701 | * Layer assignment is assumed to be complete by the time this is called. |
| 5702 | */ |
| 5703 | public void setInputFocusLw(WindowState newWindow) { |
| 5704 | if (DEBUG_INPUT) { |
| 5705 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5706 | } |
| 5707 | |
| 5708 | if (newWindow != mInputFocus) { |
| 5709 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5710 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5711 | // This is to protect against bugs if someone pauses dispatching but |
| 5712 | // forgets to resume. |
| 5713 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5714 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5715 | |
| 5716 | mInputFocus = newWindow; |
| 5717 | updateInputWindowsLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5718 | } |
| 5719 | } |
| 5720 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5721 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5722 | // Focused app has changed. |
| 5723 | if (newApp == null) { |
| 5724 | mInputManager.setFocusedApplication(null); |
| 5725 | } else { |
| 5726 | mTempInputApplication.name = newApp.toString(); |
| 5727 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5728 | newApp.inputDispatchingTimeoutNanos; |
| 5729 | mTempInputApplication.token = newApp; |
| 5730 | |
| 5731 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5732 | } |
| 5733 | } |
| 5734 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5735 | public void pauseDispatchingLw(WindowToken window) { |
| 5736 | if (! window.paused) { |
| 5737 | if (DEBUG_INPUT) { |
| 5738 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5739 | } |
| 5740 | |
| 5741 | window.paused = true; |
| 5742 | updateInputWindowsLw(); |
| 5743 | } |
| 5744 | } |
| 5745 | |
| 5746 | public void resumeDispatchingLw(WindowToken window) { |
| 5747 | if (window.paused) { |
| 5748 | if (DEBUG_INPUT) { |
| 5749 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5750 | } |
| 5751 | |
| 5752 | window.paused = false; |
| 5753 | updateInputWindowsLw(); |
| 5754 | } |
| 5755 | } |
| 5756 | |
| 5757 | public void freezeInputDispatchingLw() { |
| 5758 | if (! mInputDispatchFrozen) { |
| 5759 | if (DEBUG_INPUT) { |
| 5760 | Slog.v(TAG, "Freezing input dispatching"); |
| 5761 | } |
| 5762 | |
| 5763 | mInputDispatchFrozen = true; |
| 5764 | updateInputDispatchModeLw(); |
| 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | public void thawInputDispatchingLw() { |
| 5769 | if (mInputDispatchFrozen) { |
| 5770 | if (DEBUG_INPUT) { |
| 5771 | Slog.v(TAG, "Thawing input dispatching"); |
| 5772 | } |
| 5773 | |
| 5774 | mInputDispatchFrozen = false; |
| 5775 | updateInputDispatchModeLw(); |
| 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | public void setEventDispatchingLw(boolean enabled) { |
| 5780 | if (mInputDispatchEnabled != enabled) { |
| 5781 | if (DEBUG_INPUT) { |
| 5782 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5783 | } |
| 5784 | |
| 5785 | mInputDispatchEnabled = enabled; |
| 5786 | updateInputDispatchModeLw(); |
| 5787 | } |
| 5788 | } |
| 5789 | |
| 5790 | private void updateInputDispatchModeLw() { |
| 5791 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5792 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5793 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | public void pauseKeyDispatching(IBinder _token) { |
| 5796 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5797 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5798 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5799 | } |
| 5800 | |
| 5801 | synchronized (mWindowMap) { |
| 5802 | WindowToken token = mTokenMap.get(_token); |
| 5803 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5804 | mInputMonitor.pauseDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5805 | } |
| 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | public void resumeKeyDispatching(IBinder _token) { |
| 5810 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5811 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5812 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5813 | } |
| 5814 | |
| 5815 | synchronized (mWindowMap) { |
| 5816 | WindowToken token = mTokenMap.get(_token); |
| 5817 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5818 | mInputMonitor.resumeDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5819 | } |
| 5820 | } |
| 5821 | } |
| 5822 | |
| 5823 | public void setEventDispatching(boolean enabled) { |
| 5824 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5825 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5826 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | synchronized (mWindowMap) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5830 | mInputMonitor.setEventDispatchingLw(enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5831 | } |
| 5832 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5834 | /** |
| 5835 | * Injects a keystroke event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5836 | * Even when sync is false, this method may block while waiting for current |
| 5837 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5838 | * |
| 5839 | * @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] | 5840 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5841 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5842 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5843 | */ |
| 5844 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5845 | long downTime = ev.getDownTime(); |
| 5846 | long eventTime = ev.getEventTime(); |
| 5847 | |
| 5848 | int action = ev.getAction(); |
| 5849 | int code = ev.getKeyCode(); |
| 5850 | int repeatCount = ev.getRepeatCount(); |
| 5851 | int metaState = ev.getMetaState(); |
| 5852 | int deviceId = ev.getDeviceId(); |
| 5853 | int scancode = ev.getScanCode(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5854 | int source = ev.getSource(); |
| 5855 | |
| 5856 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5857 | source = InputDevice.SOURCE_KEYBOARD; |
| 5858 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5859 | |
| 5860 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5861 | if (downTime == 0) downTime = eventTime; |
| 5862 | |
| 5863 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5864 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5865 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5866 | final int pid = Binder.getCallingPid(); |
| 5867 | final int uid = Binder.getCallingUid(); |
| 5868 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5869 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5870 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5871 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5872 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5873 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5874 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5875 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5876 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5877 | } |
| 5878 | |
| 5879 | /** |
| 5880 | * Inject a pointer (touch) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5881 | * Even when sync is false, this method may block while waiting for current |
| 5882 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5883 | * |
| 5884 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5885 | * {@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] | 5886 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5887 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5888 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5889 | */ |
| 5890 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5891 | final int pid = Binder.getCallingPid(); |
| 5892 | final int uid = Binder.getCallingUid(); |
| 5893 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5894 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5895 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5896 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5897 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5898 | } |
| 5899 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5900 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5901 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5902 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5903 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5904 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5905 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5906 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5907 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5909 | /** |
| 5910 | * Inject a trackball (navigation device) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5911 | * Even when sync is false, this method may block while waiting for current |
| 5912 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5913 | * |
| 5914 | * @param ev A motion event describing the trackball action. (As noted in |
| 5915 | * {@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] | 5916 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5917 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5918 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5919 | */ |
| 5920 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5921 | final int pid = Binder.getCallingPid(); |
| 5922 | final int uid = Binder.getCallingUid(); |
| 5923 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5924 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5925 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5926 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5927 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5928 | } |
| 5929 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5930 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5931 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5932 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5933 | INJECTION_TIMEOUT_MILLIS); |
| 5934 | |
| 5935 | Binder.restoreCallingIdentity(ident); |
| 5936 | return reportInjectionResult(result); |
| 5937 | } |
| 5938 | |
| 5939 | /** |
| 5940 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5941 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5942 | * block any longer than it takes to enqueue the input event. |
| 5943 | * |
| 5944 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5945 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5946 | */ |
| 5947 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5948 | final int pid = Binder.getCallingPid(); |
| 5949 | final int uid = Binder.getCallingUid(); |
| 5950 | final long ident = Binder.clearCallingIdentity(); |
| 5951 | |
| 5952 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5953 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5954 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5955 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5956 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5957 | return reportInjectionResult(result); |
| 5958 | } |
| 5959 | |
| 5960 | private boolean reportInjectionResult(int result) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5961 | switch (result) { |
| 5962 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5963 | Slog.w(TAG, "Input event injection permission denied."); |
| 5964 | throw new SecurityException( |
| 5965 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5966 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5967 | //Slog.v(TAG, "Input event injection succeeded."); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5968 | return true; |
| 5969 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5970 | Slog.w(TAG, "Input event injection timed out."); |
| 5971 | return false; |
| 5972 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5973 | default: |
| 5974 | Slog.w(TAG, "Input event injection failed."); |
| 5975 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5976 | } |
| 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 | private WindowState getFocusedWindow() { |
| 5980 | synchronized (mWindowMap) { |
| 5981 | return getFocusedWindowLocked(); |
| 5982 | } |
| 5983 | } |
| 5984 | |
| 5985 | private WindowState getFocusedWindowLocked() { |
| 5986 | return mCurrentFocus; |
| 5987 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5988 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5989 | public boolean detectSafeMode() { |
| 5990 | mSafeMode = mPolicy.detectSafeMode(); |
| 5991 | return mSafeMode; |
| 5992 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5994 | public void systemReady() { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5995 | synchronized(mWindowMap) { |
| 5996 | if (mDisplay != null) { |
| 5997 | throw new IllegalStateException("Display already initialized"); |
| 5998 | } |
| 5999 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6000 | mDisplay = wm.getDefaultDisplay(); |
| 6001 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6002 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 6003 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 6004 | } |
| 6005 | |
| 6006 | try { |
| 6007 | mActivityManager.updateConfiguration(null); |
| 6008 | } catch (RemoteException e) { |
| 6009 | } |
| Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6010 | |
| 6011 | mPolicy.systemReady(); |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6012 | } |
| 6013 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | // ------------------------------------------------------------- |
| 6015 | // Client Session State |
| 6016 | // ------------------------------------------------------------- |
| 6017 | |
| 6018 | private final class Session extends IWindowSession.Stub |
| 6019 | implements IBinder.DeathRecipient { |
| 6020 | final IInputMethodClient mClient; |
| 6021 | final IInputContext mInputContext; |
| 6022 | final int mUid; |
| 6023 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6024 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6025 | SurfaceSession mSurfaceSession; |
| 6026 | int mNumWindow = 0; |
| 6027 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6029 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6030 | mClient = client; |
| 6031 | mInputContext = inputContext; |
| 6032 | mUid = Binder.getCallingUid(); |
| 6033 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6034 | StringBuilder sb = new StringBuilder(); |
| 6035 | sb.append("Session{"); |
| 6036 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6037 | sb.append(" uid "); |
| 6038 | sb.append(mUid); |
| 6039 | sb.append("}"); |
| 6040 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6041 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6042 | synchronized (mWindowMap) { |
| 6043 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6044 | IBinder b = ServiceManager.getService( |
| 6045 | Context.INPUT_METHOD_SERVICE); |
| 6046 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6047 | } |
| 6048 | } |
| 6049 | long ident = Binder.clearCallingIdentity(); |
| 6050 | try { |
| 6051 | // Note: it is safe to call in to the input method manager |
| 6052 | // here because we are not holding our lock. |
| 6053 | if (mInputMethodManager != null) { |
| 6054 | mInputMethodManager.addClient(client, inputContext, |
| 6055 | mUid, mPid); |
| 6056 | } else { |
| 6057 | client.setUsingInputMethod(false); |
| 6058 | } |
| 6059 | client.asBinder().linkToDeath(this, 0); |
| 6060 | } catch (RemoteException e) { |
| 6061 | // The caller has died, so we can just forget about this. |
| 6062 | try { |
| 6063 | if (mInputMethodManager != null) { |
| 6064 | mInputMethodManager.removeClient(client); |
| 6065 | } |
| 6066 | } catch (RemoteException ee) { |
| 6067 | } |
| 6068 | } finally { |
| 6069 | Binder.restoreCallingIdentity(ident); |
| 6070 | } |
| 6071 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6072 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6073 | @Override |
| 6074 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6075 | throws RemoteException { |
| 6076 | try { |
| 6077 | return super.onTransact(code, data, reply, flags); |
| 6078 | } catch (RuntimeException e) { |
| 6079 | // Log all 'real' exceptions thrown to the caller |
| 6080 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6081 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6082 | } |
| 6083 | throw e; |
| 6084 | } |
| 6085 | } |
| 6086 | |
| 6087 | public void binderDied() { |
| 6088 | // Note: it is safe to call in to the input method manager |
| 6089 | // here because we are not holding our lock. |
| 6090 | try { |
| 6091 | if (mInputMethodManager != null) { |
| 6092 | mInputMethodManager.removeClient(mClient); |
| 6093 | } |
| 6094 | } catch (RemoteException e) { |
| 6095 | } |
| 6096 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6097 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6098 | mClientDead = true; |
| 6099 | killSessionLocked(); |
| 6100 | } |
| 6101 | } |
| 6102 | |
| 6103 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6104 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6105 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6106 | outInputChannel); |
| 6107 | } |
| 6108 | |
| 6109 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6110 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6111 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6112 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6113 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6114 | public void remove(IWindow window) { |
| 6115 | removeWindow(this, window); |
| 6116 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6117 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6118 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6119 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6120 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6121 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6122 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6123 | int res = relayoutWindow(this, window, attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6124 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6125 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6126 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6127 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6128 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6130 | public void setTransparentRegion(IWindow window, Region region) { |
| 6131 | setTransparentRegionWindow(this, window, region); |
| 6132 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6134 | public void setInsets(IWindow window, int touchableInsets, |
| 6135 | Rect contentInsets, Rect visibleInsets) { |
| 6136 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6137 | visibleInsets); |
| 6138 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6140 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6141 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6142 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6143 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6145 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6146 | TAG, "IWindow finishDrawing called for " + window); |
| 6147 | finishDrawingWindow(this, window); |
| 6148 | } |
| 6149 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6150 | public void setInTouchMode(boolean mode) { |
| 6151 | synchronized(mWindowMap) { |
| 6152 | mInTouchMode = mode; |
| 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | public boolean getInTouchMode() { |
| 6157 | synchronized(mWindowMap) { |
| 6158 | return mInTouchMode; |
| 6159 | } |
| 6160 | } |
| 6161 | |
| 6162 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6163 | boolean always) { |
| 6164 | synchronized(mWindowMap) { |
| 6165 | long ident = Binder.clearCallingIdentity(); |
| 6166 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6167 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6168 | windowForClientLocked(this, window, true), |
| 6169 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | } finally { |
| 6171 | Binder.restoreCallingIdentity(ident); |
| 6172 | } |
| 6173 | } |
| 6174 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6175 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6176 | /* Drag/drop */ |
| 6177 | public IBinder prepareDrag(IWindow window, boolean localOnly, |
| 6178 | int width, int height, Surface outSurface) { |
| 6179 | return prepareDragSurface(window, mSurfaceSession, localOnly, |
| 6180 | width, height, outSurface); |
| 6181 | } |
| 6182 | |
| 6183 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6184 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6185 | ClipData data) { |
| 6186 | if (DEBUG_DRAG) { |
| 6187 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6188 | } |
| 6189 | |
| 6190 | synchronized (mWindowMap) { |
| 6191 | if (mDragState == null) { |
| 6192 | Slog.w(TAG, "No drag prepared"); |
| 6193 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6194 | } |
| 6195 | |
| 6196 | if (dragToken != mDragState.mToken) { |
| 6197 | Slog.w(TAG, "Performing mismatched drag"); |
| 6198 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6199 | } |
| 6200 | |
| 6201 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6202 | if (callingWin == null) { |
| 6203 | Slog.w(TAG, "Bad requesting window " + window); |
| 6204 | return false; // !!! TODO: throw here? |
| 6205 | } |
| 6206 | |
| 6207 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6208 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6209 | // called performDrag() |
| 6210 | |
| 6211 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6212 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6213 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6214 | // will let us eliminate the (touchX,touchY) parameters from the API. |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6215 | |
| 6216 | mDragState.register(); |
| 6217 | mInputMonitor.updateInputWindowsLw(); |
| 6218 | mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6219 | mDragState.mServerChannel); |
| 6220 | |
| 6221 | mDragState.mData = data; |
| 6222 | mDragState.broadcastDragStartedLw(); |
| 6223 | |
| 6224 | // remember the thumb offsets for later |
| 6225 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6226 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6227 | |
| 6228 | // Make the surface visible at the proper location |
| 6229 | final Surface surface = mDragState.mSurface; |
| 6230 | surface.openTransaction(); |
| 6231 | try { |
| 6232 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6233 | (int)(touchY - thumbCenterY)); |
| 6234 | surface.setAlpha(.5f); |
| 6235 | surface.show(); |
| 6236 | } finally { |
| 6237 | surface.closeTransaction(); |
| 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | return true; // success! |
| 6242 | } |
| 6243 | |
| 6244 | public void dragRecipientEntered(IWindow window) { |
| 6245 | if (DEBUG_DRAG) { |
| 6246 | Slog.d(TAG, "Drag into new candidate view @ " + window); |
| 6247 | } |
| 6248 | } |
| 6249 | |
| 6250 | public void dragRecipientExited(IWindow window) { |
| 6251 | if (DEBUG_DRAG) { |
| 6252 | Slog.d(TAG, "Drag from old candidate view @ " + window); |
| 6253 | } |
| 6254 | } |
| 6255 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6256 | 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] | 6257 | synchronized(mWindowMap) { |
| 6258 | long ident = Binder.clearCallingIdentity(); |
| 6259 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6260 | setWindowWallpaperPositionLocked( |
| 6261 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6262 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6263 | } finally { |
| 6264 | Binder.restoreCallingIdentity(ident); |
| 6265 | } |
| 6266 | } |
| 6267 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6268 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6269 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6270 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6271 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6272 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6273 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6274 | int z, Bundle extras, boolean sync) { |
| 6275 | synchronized(mWindowMap) { |
| 6276 | long ident = Binder.clearCallingIdentity(); |
| 6277 | try { |
| 6278 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6279 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6280 | action, x, y, z, extras, sync); |
| 6281 | } finally { |
| 6282 | Binder.restoreCallingIdentity(ident); |
| 6283 | } |
| 6284 | } |
| 6285 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6286 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6287 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6288 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6289 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6290 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6291 | void windowAddedLocked() { |
| 6292 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6293 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6294 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6295 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6296 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6297 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6298 | mSessions.add(this); |
| 6299 | } |
| 6300 | mNumWindow++; |
| 6301 | } |
| 6302 | |
| 6303 | void windowRemovedLocked() { |
| 6304 | mNumWindow--; |
| 6305 | killSessionLocked(); |
| 6306 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | void killSessionLocked() { |
| 6309 | if (mNumWindow <= 0 && mClientDead) { |
| 6310 | mSessions.remove(this); |
| 6311 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6312 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | TAG, "Last window removed from " + this |
| 6314 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6315 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6316 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6317 | try { |
| 6318 | mSurfaceSession.kill(); |
| 6319 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6320 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6321 | + mSurfaceSession + " in session " + this |
| 6322 | + ": " + e.toString()); |
| 6323 | } |
| 6324 | mSurfaceSession = null; |
| 6325 | } |
| 6326 | } |
| 6327 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6330 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6331 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6332 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | } |
| 6334 | |
| 6335 | @Override |
| 6336 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6337 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6338 | } |
| 6339 | } |
| 6340 | |
| 6341 | // ------------------------------------------------------------- |
| 6342 | // Client Window State |
| 6343 | // ------------------------------------------------------------- |
| 6344 | |
| 6345 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6346 | final Session mSession; |
| 6347 | final IWindow mClient; |
| 6348 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6349 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6350 | AppWindowToken mAppToken; |
| 6351 | AppWindowToken mTargetAppToken; |
| 6352 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6353 | final DeathRecipient mDeathRecipient; |
| 6354 | final WindowState mAttachedWindow; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6355 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | final int mBaseLayer; |
| 6357 | final int mSubLayer; |
| 6358 | final boolean mLayoutAttached; |
| 6359 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6360 | final boolean mIsWallpaper; |
| 6361 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6362 | int mViewVisibility; |
| 6363 | boolean mPolicyVisibility = true; |
| 6364 | boolean mPolicyVisibilityAfterAnim = true; |
| 6365 | boolean mAppFreezing; |
| 6366 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6367 | boolean mReportDestroySurface; |
| 6368 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6369 | boolean mAttachedHidden; // is our parent window hidden? |
| 6370 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6371 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6372 | int mRequestedWidth; |
| 6373 | int mRequestedHeight; |
| 6374 | int mLastRequestedWidth; |
| 6375 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | int mLayer; |
| 6377 | int mAnimLayer; |
| 6378 | int mLastLayer; |
| 6379 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6380 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6381 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6382 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6383 | int mLayoutSeq = -1; |
| 6384 | |
| 6385 | Configuration mConfiguration = null; |
| 6386 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | // Actual frame shown on-screen (may be modified by animation) |
| 6388 | final Rect mShownFrame = new Rect(); |
| 6389 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6390 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6392 | * Set when we have changed the size of the surface, to know that |
| 6393 | * we must tell them application to resize (and thus redraw itself). |
| 6394 | */ |
| 6395 | boolean mSurfaceResized; |
| 6396 | |
| 6397 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | * Insets that determine the actually visible area |
| 6399 | */ |
| 6400 | final Rect mVisibleInsets = new Rect(); |
| 6401 | final Rect mLastVisibleInsets = new Rect(); |
| 6402 | boolean mVisibleInsetsChanged; |
| 6403 | |
| 6404 | /** |
| 6405 | * Insets that are covered by system windows |
| 6406 | */ |
| 6407 | final Rect mContentInsets = new Rect(); |
| 6408 | final Rect mLastContentInsets = new Rect(); |
| 6409 | boolean mContentInsetsChanged; |
| 6410 | |
| 6411 | /** |
| 6412 | * Set to true if we are waiting for this window to receive its |
| 6413 | * given internal insets before laying out other windows based on it. |
| 6414 | */ |
| 6415 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6417 | /** |
| 6418 | * These are the content insets that were given during layout for |
| 6419 | * this window, to be applied to windows behind it. |
| 6420 | */ |
| 6421 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6422 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6423 | /** |
| 6424 | * These are the visible insets that were given during layout for |
| 6425 | * this window, to be applied to windows behind it. |
| 6426 | */ |
| 6427 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6428 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6429 | /** |
| 6430 | * Flag indicating whether the touchable region should be adjusted by |
| 6431 | * the visible insets; if false the area outside the visible insets is |
| 6432 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6433 | * tests. |
| 6434 | */ |
| 6435 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6437 | // Current transformation being applied. |
| 6438 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6439 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6440 | float mHScale=1, mVScale=1; |
| 6441 | float mLastHScale=1, mLastVScale=1; |
| 6442 | final Matrix mTmpMatrix = new Matrix(); |
| 6443 | |
| 6444 | // "Real" frame that the application sees. |
| 6445 | final Rect mFrame = new Rect(); |
| 6446 | final Rect mLastFrame = new Rect(); |
| 6447 | |
| 6448 | final Rect mContainingFrame = new Rect(); |
| 6449 | final Rect mDisplayFrame = new Rect(); |
| 6450 | final Rect mContentFrame = new Rect(); |
| 6451 | final Rect mVisibleFrame = new Rect(); |
| 6452 | |
| 6453 | float mShownAlpha = 1; |
| 6454 | float mAlpha = 1; |
| 6455 | float mLastAlpha = 1; |
| 6456 | |
| 6457 | // Set to true if, when the window gets displayed, it should perform |
| 6458 | // an enter animation. |
| 6459 | boolean mEnterAnimationPending; |
| 6460 | |
| 6461 | // Currently running animation. |
| 6462 | boolean mAnimating; |
| 6463 | boolean mLocalAnimating; |
| 6464 | Animation mAnimation; |
| 6465 | boolean mAnimationIsEntrance; |
| 6466 | boolean mHasTransformation; |
| 6467 | boolean mHasLocalTransformation; |
| 6468 | final Transformation mTransformation = new Transformation(); |
| 6469 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6470 | // If a window showing a wallpaper: the requested offset for the |
| 6471 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6472 | float mWallpaperX = -1; |
| 6473 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6474 | |
| 6475 | // If a window showing a wallpaper: what fraction of the offset |
| 6476 | // range corresponds to a full virtual screen. |
| 6477 | float mWallpaperXStep = -1; |
| 6478 | float mWallpaperYStep = -1; |
| 6479 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6480 | // Wallpaper windows: pixels offset based on above variables. |
| 6481 | int mXOffset; |
| 6482 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6484 | // This is set after IWindowSession.relayout() has been called at |
| 6485 | // least once for the window. It allows us to detect the situation |
| 6486 | // where we don't yet have a surface, but should have one soon, so |
| 6487 | // we can give the window focus before waiting for the relayout. |
| 6488 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6490 | // This is set after the Surface has been created but before the |
| 6491 | // window has been drawn. During this time the surface is hidden. |
| 6492 | boolean mDrawPending; |
| 6493 | |
| 6494 | // This is set after the window has finished drawing for the first |
| 6495 | // time but before its surface is shown. The surface will be |
| 6496 | // displayed when the next layout is run. |
| 6497 | boolean mCommitDrawPending; |
| 6498 | |
| 6499 | // This is set during the time after the window's drawing has been |
| 6500 | // committed, and before its surface is actually shown. It is used |
| 6501 | // to delay showing the surface until all windows in a token are ready |
| 6502 | // to be shown. |
| 6503 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | // Set when the window has been shown in the screen the first time. |
| 6506 | boolean mHasDrawn; |
| 6507 | |
| 6508 | // Currently running an exit animation? |
| 6509 | boolean mExiting; |
| 6510 | |
| 6511 | // Currently on the mDestroySurface list? |
| 6512 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6513 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6514 | // Completely remove from window manager after exit animation? |
| 6515 | boolean mRemoveOnExit; |
| 6516 | |
| 6517 | // Set when the orientation is changing and this window has not yet |
| 6518 | // been updated for the new orientation. |
| 6519 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6520 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | // Is this window now (or just being) removed? |
| 6522 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6523 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6524 | // For debugging, this is the last information given to the surface flinger. |
| 6525 | boolean mSurfaceShown; |
| 6526 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6527 | int mSurfaceLayer; |
| 6528 | float mSurfaceAlpha; |
| 6529 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6530 | // Input channel |
| 6531 | InputChannel mInputChannel; |
| 6532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | WindowState(Session s, IWindow c, WindowToken token, |
| 6534 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6535 | int viewVisibility) { |
| 6536 | mSession = s; |
| 6537 | mClient = c; |
| 6538 | mToken = token; |
| 6539 | mAttrs.copyFrom(a); |
| 6540 | mViewVisibility = viewVisibility; |
| 6541 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6542 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6543 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6544 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6545 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6546 | try { |
| 6547 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6548 | } catch (RemoteException e) { |
| 6549 | mDeathRecipient = null; |
| 6550 | mAttachedWindow = null; |
| 6551 | mLayoutAttached = false; |
| 6552 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6553 | mIsWallpaper = false; |
| 6554 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6555 | mBaseLayer = 0; |
| 6556 | mSubLayer = 0; |
| 6557 | return; |
| 6558 | } |
| 6559 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6561 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6562 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6563 | // The multiplier here is to reserve space for multiple |
| 6564 | // windows in the same type layer. |
| 6565 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6566 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6567 | + TYPE_LAYER_OFFSET; |
| 6568 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6569 | mAttachedWindow = attachedWindow; |
| 6570 | mAttachedWindow.mChildWindows.add(this); |
| 6571 | mLayoutAttached = mAttrs.type != |
| 6572 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6573 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6574 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6575 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6576 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6577 | } else { |
| 6578 | // The multiplier here is to reserve space for multiple |
| 6579 | // windows in the same type layer. |
| 6580 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6581 | * TYPE_LAYER_MULTIPLIER |
| 6582 | + TYPE_LAYER_OFFSET; |
| 6583 | mSubLayer = 0; |
| 6584 | mAttachedWindow = null; |
| 6585 | mLayoutAttached = false; |
| 6586 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6587 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6588 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6589 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6590 | } |
| 6591 | |
| 6592 | WindowState appWin = this; |
| 6593 | while (appWin.mAttachedWindow != null) { |
| 6594 | appWin = mAttachedWindow; |
| 6595 | } |
| 6596 | WindowToken appToken = appWin.mToken; |
| 6597 | while (appToken.appWindowToken == null) { |
| 6598 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6599 | if (parent == null || appToken == parent) { |
| 6600 | break; |
| 6601 | } |
| 6602 | appToken = parent; |
| 6603 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6604 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6605 | mAppToken = appToken.appWindowToken; |
| 6606 | |
| 6607 | mSurface = null; |
| 6608 | mRequestedWidth = 0; |
| 6609 | mRequestedHeight = 0; |
| 6610 | mLastRequestedWidth = 0; |
| 6611 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6612 | mXOffset = 0; |
| 6613 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6614 | mLayer = 0; |
| 6615 | mAnimLayer = 0; |
| 6616 | mLastLayer = 0; |
| 6617 | } |
| 6618 | |
| 6619 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6620 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | TAG, "Attaching " + this + " token=" + mToken |
| 6622 | + ", list=" + mToken.windows); |
| 6623 | mSession.windowAddedLocked(); |
| 6624 | } |
| 6625 | |
| 6626 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6627 | mHaveFrame = true; |
| 6628 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6629 | final Rect container = mContainingFrame; |
| 6630 | container.set(pf); |
| 6631 | |
| 6632 | final Rect display = mDisplayFrame; |
| 6633 | display.set(df); |
| 6634 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6635 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6636 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6637 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6638 | display.intersect(mCompatibleScreenFrame); |
| 6639 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6640 | } |
| 6641 | |
| 6642 | final int pw = container.right - container.left; |
| 6643 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6644 | |
| 6645 | int w,h; |
| 6646 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6647 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6648 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6649 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6650 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6651 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6653 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6654 | final Rect content = mContentFrame; |
| 6655 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6656 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | final Rect visible = mVisibleFrame; |
| 6658 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6660 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6661 | final int fw = frame.width(); |
| 6662 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6663 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6664 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6665 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6666 | |
| 6667 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6668 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6669 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6670 | |
| 6671 | //System.out.println("Out: " + mFrame); |
| 6672 | |
| 6673 | // Now make sure the window fits in the overall display. |
| 6674 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6675 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6676 | // Make sure the content and visible frames are inside of the |
| 6677 | // final window frame. |
| 6678 | if (content.left < frame.left) content.left = frame.left; |
| 6679 | if (content.top < frame.top) content.top = frame.top; |
| 6680 | if (content.right > frame.right) content.right = frame.right; |
| 6681 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6682 | if (visible.left < frame.left) visible.left = frame.left; |
| 6683 | if (visible.top < frame.top) visible.top = frame.top; |
| 6684 | if (visible.right > frame.right) visible.right = frame.right; |
| 6685 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6686 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6687 | final Rect contentInsets = mContentInsets; |
| 6688 | contentInsets.left = content.left-frame.left; |
| 6689 | contentInsets.top = content.top-frame.top; |
| 6690 | contentInsets.right = frame.right-content.right; |
| 6691 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6693 | final Rect visibleInsets = mVisibleInsets; |
| 6694 | visibleInsets.left = visible.left-frame.left; |
| 6695 | visibleInsets.top = visible.top-frame.top; |
| 6696 | visibleInsets.right = frame.right-visible.right; |
| 6697 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6698 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6699 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6700 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6701 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6702 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6703 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6704 | if (localLOGV) { |
| 6705 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6706 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6707 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | + mRequestedWidth + ", mRequestedheight=" |
| 6709 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6710 | + "): frame=" + mFrame.toShortString() |
| 6711 | + " ci=" + contentInsets.toShortString() |
| 6712 | + " vi=" + visibleInsets.toShortString()); |
| 6713 | //} |
| 6714 | } |
| 6715 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6716 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | public Rect getFrameLw() { |
| 6718 | return mFrame; |
| 6719 | } |
| 6720 | |
| 6721 | public Rect getShownFrameLw() { |
| 6722 | return mShownFrame; |
| 6723 | } |
| 6724 | |
| 6725 | public Rect getDisplayFrameLw() { |
| 6726 | return mDisplayFrame; |
| 6727 | } |
| 6728 | |
| 6729 | public Rect getContentFrameLw() { |
| 6730 | return mContentFrame; |
| 6731 | } |
| 6732 | |
| 6733 | public Rect getVisibleFrameLw() { |
| 6734 | return mVisibleFrame; |
| 6735 | } |
| 6736 | |
| 6737 | public boolean getGivenInsetsPendingLw() { |
| 6738 | return mGivenInsetsPending; |
| 6739 | } |
| 6740 | |
| 6741 | public Rect getGivenContentInsetsLw() { |
| 6742 | return mGivenContentInsets; |
| 6743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6745 | public Rect getGivenVisibleInsetsLw() { |
| 6746 | return mGivenVisibleInsets; |
| 6747 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | public WindowManager.LayoutParams getAttrs() { |
| 6750 | return mAttrs; |
| 6751 | } |
| 6752 | |
| 6753 | public int getSurfaceLayer() { |
| 6754 | return mLayer; |
| 6755 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6757 | public IApplicationToken getAppToken() { |
| 6758 | return mAppToken != null ? mAppToken.appToken : null; |
| 6759 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6760 | |
| 6761 | public long getInputDispatchingTimeoutNanos() { |
| 6762 | return mAppToken != null |
| 6763 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6764 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6765 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | |
| 6767 | public boolean hasAppShownWindows() { |
| 6768 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6769 | } |
| 6770 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6771 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6772 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | TAG, "Setting animation in " + this + ": " + anim); |
| 6774 | mAnimating = false; |
| 6775 | mLocalAnimating = false; |
| 6776 | mAnimation = anim; |
| 6777 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6778 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6779 | } |
| 6780 | |
| 6781 | public void clearAnimation() { |
| 6782 | if (mAnimation != null) { |
| 6783 | mAnimating = true; |
| 6784 | mLocalAnimating = false; |
| 6785 | mAnimation = null; |
| 6786 | } |
| 6787 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6789 | Surface createSurfaceLocked() { |
| 6790 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6791 | mReportDestroySurface = false; |
| 6792 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6793 | mDrawPending = true; |
| 6794 | mCommitDrawPending = false; |
| 6795 | mReadyToShow = false; |
| 6796 | if (mAppToken != null) { |
| 6797 | mAppToken.allDrawn = false; |
| 6798 | } |
| 6799 | |
| 6800 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6801 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | flags |= Surface.PUSH_BUFFERS; |
| 6803 | } |
| 6804 | |
| 6805 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6806 | flags |= Surface.SECURE; |
| 6807 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6808 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6809 | TAG, "Creating surface in session " |
| 6810 | + mSession.mSurfaceSession + " window " + this |
| 6811 | + " w=" + mFrame.width() |
| 6812 | + " h=" + mFrame.height() + " format=" |
| 6813 | + mAttrs.format + " flags=" + flags); |
| 6814 | |
| 6815 | int w = mFrame.width(); |
| 6816 | int h = mFrame.height(); |
| 6817 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6818 | // for a scaled surface, we always want the requested |
| 6819 | // size. |
| 6820 | w = mRequestedWidth; |
| 6821 | h = mRequestedHeight; |
| 6822 | } |
| 6823 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6824 | // Something is wrong and SurfaceFlinger will not like this, |
| 6825 | // try to revert to sane values |
| 6826 | if (w <= 0) w = 1; |
| 6827 | if (h <= 0) h = 1; |
| 6828 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6829 | mSurfaceShown = false; |
| 6830 | mSurfaceLayer = 0; |
| 6831 | mSurfaceAlpha = 1; |
| 6832 | mSurfaceX = 0; |
| 6833 | mSurfaceY = 0; |
| 6834 | mSurfaceW = w; |
| 6835 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | try { |
| 6837 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6838 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6839 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6840 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6841 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6842 | + mSurface + " IN SESSION " |
| 6843 | + mSession.mSurfaceSession |
| 6844 | + ": pid=" + mSession.mPid + " format=" |
| 6845 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6846 | + Integer.toHexString(flags) |
| 6847 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6849 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6851 | return null; |
| 6852 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6853 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6854 | return null; |
| 6855 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6856 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6857 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6858 | TAG, "Got surface: " + mSurface |
| 6859 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6860 | + ", animLayer=" + mAnimLayer); |
| 6861 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6862 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6863 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6864 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6865 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6866 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | } |
| 6868 | Surface.openTransaction(); |
| 6869 | try { |
| 6870 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6871 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6872 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6873 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6874 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6876 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | mSurface.hide(); |
| 6878 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6879 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6881 | Surface.SURFACE_DITHER); |
| 6882 | } |
| 6883 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6884 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6885 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6886 | } |
| 6887 | mLastHidden = true; |
| 6888 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6889 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6890 | Surface.closeTransaction(); |
| 6891 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6892 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6893 | TAG, "Created surface " + this); |
| 6894 | } |
| 6895 | return mSurface; |
| 6896 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6897 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6898 | void destroySurfaceLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6900 | mAppToken.startingDisplayed = false; |
| 6901 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6902 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6903 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6904 | mDrawPending = false; |
| 6905 | mCommitDrawPending = false; |
| 6906 | mReadyToShow = false; |
| 6907 | |
| 6908 | int i = mChildWindows.size(); |
| 6909 | while (i > 0) { |
| 6910 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6911 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6912 | c.mAttachedHidden = true; |
| 6913 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6914 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6915 | if (mReportDestroySurface) { |
| 6916 | mReportDestroySurface = false; |
| 6917 | mSurfacePendingDestroy = true; |
| 6918 | try { |
| 6919 | mClient.dispatchGetNewSurface(); |
| 6920 | // We'll really destroy on the next time around. |
| 6921 | return; |
| 6922 | } catch (RemoteException e) { |
| 6923 | } |
| 6924 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6925 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6926 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6927 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6928 | RuntimeException e = null; |
| 6929 | if (!HIDE_STACK_CRAWLS) { |
| 6930 | e = new RuntimeException(); |
| 6931 | e.fillInStackTrace(); |
| 6932 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6933 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6934 | + mSurface + ", session " + mSession, e); |
| 6935 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6936 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6937 | RuntimeException e = null; |
| 6938 | if (!HIDE_STACK_CRAWLS) { |
| 6939 | e = new RuntimeException(); |
| 6940 | e.fillInStackTrace(); |
| 6941 | } |
| 6942 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6943 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6944 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6946 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | + " surface " + mSurface + " session " + mSession |
| 6948 | + ": " + e.toString()); |
| 6949 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6950 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6951 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | boolean finishDrawingLocked() { |
| 6957 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6958 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6959 | TAG, "finishDrawingLocked: " + mSurface); |
| 6960 | mCommitDrawPending = true; |
| 6961 | mDrawPending = false; |
| 6962 | return true; |
| 6963 | } |
| 6964 | return false; |
| 6965 | } |
| 6966 | |
| 6967 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6968 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6969 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6971 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6972 | } |
| 6973 | mCommitDrawPending = false; |
| 6974 | mReadyToShow = true; |
| 6975 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6976 | final AppWindowToken atoken = mAppToken; |
| 6977 | if (atoken == null || atoken.allDrawn || starting) { |
| 6978 | performShowLocked(); |
| 6979 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6980 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6981 | } |
| 6982 | |
| 6983 | // This must be called while inside a transaction. |
| 6984 | boolean performShowLocked() { |
| 6985 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6986 | RuntimeException e = null; |
| 6987 | if (!HIDE_STACK_CRAWLS) { |
| 6988 | e = new RuntimeException(); |
| 6989 | e.fillInStackTrace(); |
| 6990 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6991 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6992 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6993 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6994 | } |
| 6995 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6996 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 6997 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6998 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6999 | + " during animation: policyVis=" + mPolicyVisibility |
| 7000 | + " attHidden=" + mAttachedHidden |
| 7001 | + " tok.hiddenRequested=" |
| 7002 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7003 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7004 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7005 | + " animating=" + mAnimating |
| 7006 | + " tok animating=" |
| 7007 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7008 | if (!showSurfaceRobustlyLocked(this)) { |
| 7009 | return false; |
| 7010 | } |
| 7011 | mLastAlpha = -1; |
| 7012 | mHasDrawn = true; |
| 7013 | mLastHidden = false; |
| 7014 | mReadyToShow = false; |
| 7015 | enableScreenIfNeededLocked(); |
| 7016 | |
| 7017 | applyEnterAnimationLocked(this); |
| 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 | int i = mChildWindows.size(); |
| 7020 | while (i > 0) { |
| 7021 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7022 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7023 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7024 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7025 | if (c.mSurface != null) { |
| 7026 | c.performShowLocked(); |
| 7027 | // It hadn't been shown, which means layout not |
| 7028 | // performed on it, so now we want to make sure to |
| 7029 | // do a layout. If called from within the transaction |
| 7030 | // loop, this will cause it to restart with a new |
| 7031 | // layout. |
| 7032 | mLayoutNeeded = true; |
| 7033 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7034 | } |
| 7035 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7037 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7038 | && mAppToken != null) { |
| 7039 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7040 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7041 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7042 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7043 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7044 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7045 | // If this initial window is animating, stop it -- we |
| 7046 | // will do an animation to reveal it from behind the |
| 7047 | // starting window, so there is no need for it to also |
| 7048 | // be doing its own stuff. |
| 7049 | if (mAnimation != null) { |
| 7050 | mAnimation = null; |
| 7051 | // Make sure we clean up the animation. |
| 7052 | mAnimating = true; |
| 7053 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7054 | mFinishedStarting.add(mAppToken); |
| 7055 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7056 | } |
| 7057 | mAppToken.updateReportedVisibilityLocked(); |
| 7058 | } |
| 7059 | } |
| 7060 | return true; |
| 7061 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7062 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | // This must be called while inside a transaction. Returns true if |
| 7064 | // there is more animation to run. |
| 7065 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7066 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7067 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7068 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7069 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7070 | mHasTransformation = true; |
| 7071 | mHasLocalTransformation = true; |
| 7072 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7073 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | TAG, "Starting animation in " + this + |
| 7075 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7076 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7077 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7078 | mAnimation.setStartTime(currentTime); |
| 7079 | mLocalAnimating = true; |
| 7080 | mAnimating = true; |
| 7081 | } |
| 7082 | mTransformation.clear(); |
| 7083 | final boolean more = mAnimation.getTransformation( |
| 7084 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7085 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7086 | TAG, "Stepped animation in " + this + |
| 7087 | ": more=" + more + ", xform=" + mTransformation); |
| 7088 | if (more) { |
| 7089 | // we're not done! |
| 7090 | return true; |
| 7091 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7092 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7093 | TAG, "Finished animation in " + this + |
| 7094 | " @ " + currentTime); |
| 7095 | mAnimation = null; |
| 7096 | //WindowManagerService.this.dump(); |
| 7097 | } |
| 7098 | mHasLocalTransformation = false; |
| 7099 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7100 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7101 | // When our app token is animating, we kind-of pretend like |
| 7102 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7103 | // part of this check means that we will only do this if |
| 7104 | // our window is not currently exiting, or it is not |
| 7105 | // locally animating itself. The idea being that one that |
| 7106 | // is exiting and doing a local animation should be removed |
| 7107 | // once that animation is done. |
| 7108 | mAnimating = true; |
| 7109 | mHasTransformation = true; |
| 7110 | mTransformation.clear(); |
| 7111 | return false; |
| 7112 | } else if (mHasTransformation) { |
| 7113 | // Little trick to get through the path below to act like |
| 7114 | // we have finished an animation. |
| 7115 | mAnimating = true; |
| 7116 | } else if (isAnimating()) { |
| 7117 | mAnimating = true; |
| 7118 | } |
| 7119 | } else if (mAnimation != null) { |
| 7120 | // If the display is frozen, and there is a pending animation, |
| 7121 | // clear it and make sure we run the cleanup code. |
| 7122 | mAnimating = true; |
| 7123 | mLocalAnimating = true; |
| 7124 | mAnimation = null; |
| 7125 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7126 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7127 | if (!mAnimating && !mLocalAnimating) { |
| 7128 | return false; |
| 7129 | } |
| 7130 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7131 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7132 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7133 | + ", reportedVisible=" |
| 7134 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7135 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7136 | mAnimating = false; |
| 7137 | mLocalAnimating = false; |
| 7138 | mAnimation = null; |
| 7139 | mAnimLayer = mLayer; |
| 7140 | if (mIsImWindow) { |
| 7141 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7142 | } else if (mIsWallpaper) { |
| 7143 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7144 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7145 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7146 | + " anim layer: " + mAnimLayer); |
| 7147 | mHasTransformation = false; |
| 7148 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7149 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7150 | if (DEBUG_VISIBILITY) { |
| 7151 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7152 | + mPolicyVisibilityAfterAnim); |
| 7153 | } |
| 7154 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7155 | if (!mPolicyVisibility) { |
| 7156 | if (mCurrentFocus == this) { |
| 7157 | mFocusMayChange = true; |
| 7158 | } |
| 7159 | // Window is no longer visible -- make sure if we were waiting |
| 7160 | // for it to be displayed before enabling the display, that |
| 7161 | // we allow the display to be enabled now. |
| 7162 | enableScreenIfNeededLocked(); |
| 7163 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7164 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7165 | mTransformation.clear(); |
| 7166 | if (mHasDrawn |
| 7167 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7168 | && mAppToken != null |
| 7169 | && mAppToken.firstWindowDrawn |
| 7170 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7171 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7172 | + mToken + ": first real window done animating"); |
| 7173 | mFinishedStarting.add(mAppToken); |
| 7174 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7175 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7176 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7177 | finishExit(); |
| 7178 | |
| 7179 | if (mAppToken != null) { |
| 7180 | mAppToken.updateReportedVisibilityLocked(); |
| 7181 | } |
| 7182 | |
| 7183 | return false; |
| 7184 | } |
| 7185 | |
| 7186 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7187 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7188 | TAG, "finishExit in " + this |
| 7189 | + ": exiting=" + mExiting |
| 7190 | + " remove=" + mRemoveOnExit |
| 7191 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7192 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7193 | final int N = mChildWindows.size(); |
| 7194 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7195 | mChildWindows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7196 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7198 | if (!mExiting) { |
| 7199 | return; |
| 7200 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7201 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7202 | if (isWindowAnimating()) { |
| 7203 | return; |
| 7204 | } |
| 7205 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7206 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7207 | TAG, "Exit animation finished in " + this |
| 7208 | + ": remove=" + mRemoveOnExit); |
| 7209 | if (mSurface != null) { |
| 7210 | mDestroySurface.add(this); |
| 7211 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7212 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7213 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | try { |
| 7215 | mSurface.hide(); |
| 7216 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7217 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7218 | } |
| 7219 | mLastHidden = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7220 | } |
| 7221 | mExiting = false; |
| 7222 | if (mRemoveOnExit) { |
| 7223 | mPendingRemove.add(this); |
| 7224 | mRemoveOnExit = false; |
| 7225 | } |
| 7226 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7229 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7230 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7231 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7232 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7233 | return true; |
| 7234 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7235 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7236 | void computeShownFrameLocked() { |
| 7237 | final boolean selfTransformation = mHasLocalTransformation; |
| 7238 | Transformation attachedTransformation = |
| 7239 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7240 | ? mAttachedWindow.mTransformation : null; |
| 7241 | Transformation appTransformation = |
| 7242 | (mAppToken != null && mAppToken.hasTransformation) |
| 7243 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7244 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7245 | // Wallpapers are animated based on the "real" window they |
| 7246 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7247 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7248 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7249 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7250 | mWallpaperTarget.mAnimation != null && |
| 7251 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7252 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7253 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7254 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7255 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7256 | } |
| 7257 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7258 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7259 | mWallpaperTarget.mAppToken.animation != null && |
| 7260 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7261 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7262 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7263 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7264 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7265 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7266 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7268 | if (selfTransformation || attachedTransformation != null |
| 7269 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7270 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7271 | final Rect frame = mFrame; |
| 7272 | final float tmpFloats[] = mTmpFloats; |
| 7273 | final Matrix tmpMatrix = mTmpMatrix; |
| 7274 | |
| 7275 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7276 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7277 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7278 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7279 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7280 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7281 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7282 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7283 | } |
| 7284 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7285 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7286 | } |
| 7287 | |
| 7288 | // "convert" it into SurfaceFlinger's format |
| 7289 | // (a 2x2 matrix + an offset) |
| 7290 | // Here we must not transform the position of the surface |
| 7291 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7292 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7294 | tmpMatrix.getValues(tmpFloats); |
| 7295 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7296 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7297 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7298 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7299 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7300 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7301 | int w = frame.width(); |
| 7302 | int h = frame.height(); |
| 7303 | mShownFrame.set(x, y, x+w, y+h); |
| 7304 | |
| 7305 | // Now set the alpha... but because our current hardware |
| 7306 | // can't do alpha transformation on a non-opaque surface, |
| 7307 | // turn it off if we are running an animation that is also |
| 7308 | // transforming since it is more important to have that |
| 7309 | // animation be smooth. |
| 7310 | mShownAlpha = mAlpha; |
| 7311 | if (!mLimitedAlphaCompositing |
| 7312 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7313 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7314 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7315 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7316 | if (selfTransformation) { |
| 7317 | mShownAlpha *= mTransformation.getAlpha(); |
| 7318 | } |
| 7319 | if (attachedTransformation != null) { |
| 7320 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7321 | } |
| 7322 | if (appTransformation != null) { |
| 7323 | mShownAlpha *= appTransformation.getAlpha(); |
| 7324 | } |
| 7325 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7326 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7327 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7328 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7329 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7330 | TAG, "Continuing animation in " + this + |
| 7331 | ": " + mShownFrame + |
| 7332 | ", alpha=" + mTransformation.getAlpha()); |
| 7333 | return; |
| 7334 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7335 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7336 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7337 | if (mXOffset != 0 || mYOffset != 0) { |
| 7338 | mShownFrame.offset(mXOffset, mYOffset); |
| 7339 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7340 | mShownAlpha = mAlpha; |
| 7341 | mDsDx = 1; |
| 7342 | mDtDx = 0; |
| 7343 | mDsDy = 0; |
| 7344 | mDtDy = 1; |
| 7345 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7346 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7347 | /** |
| 7348 | * Is this window visible? It is not visible if there is no |
| 7349 | * surface, or we are in the process of running an exit animation |
| 7350 | * that will remove the surface, or its app token has been hidden. |
| 7351 | */ |
| 7352 | public boolean isVisibleLw() { |
| 7353 | final AppWindowToken atoken = mAppToken; |
| 7354 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7355 | && (atoken == null || !atoken.hiddenRequested) |
| 7356 | && !mExiting && !mDestroying; |
| 7357 | } |
| 7358 | |
| 7359 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7360 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7361 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7362 | * things like window flags that impact the keyguard. |
| 7363 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7364 | * for this "hidden behind keyguard" state rather than overloading |
| 7365 | * mPolicyVisibility. Ungh. |
| 7366 | */ |
| 7367 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7368 | final AppWindowToken atoken = mAppToken; |
| 7369 | return mSurface != null && !mAttachedHidden |
| 7370 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7371 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7372 | && !mExiting && !mDestroying; |
| 7373 | } |
| 7374 | |
| 7375 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7376 | * Is this window visible, ignoring its app token? It is not visible |
| 7377 | * if there is no surface, or we are in the process of running an exit animation |
| 7378 | * that will remove the surface. |
| 7379 | */ |
| 7380 | public boolean isWinVisibleLw() { |
| 7381 | final AppWindowToken atoken = mAppToken; |
| 7382 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7383 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7384 | && !mExiting && !mDestroying; |
| 7385 | } |
| 7386 | |
| 7387 | /** |
| 7388 | * The same as isVisible(), but follows the current hidden state of |
| 7389 | * the associated app token, not the pending requested hidden state. |
| 7390 | */ |
| 7391 | boolean isVisibleNow() { |
| 7392 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7393 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7394 | } |
| 7395 | |
| 7396 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7397 | * Can this window possibly be a drag/drop target? The test here is |
| 7398 | * a combination of the above "visible now" with the check that the |
| 7399 | * Input Manager uses when discarding windows from input consideration. |
| 7400 | */ |
| 7401 | boolean isPotentialDragTarget() { |
| 7402 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7403 | } |
| 7404 | |
| 7405 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7406 | * Same as isVisible(), but we also count it as visible between the |
| 7407 | * call to IWindowSession.add() and the first relayout(). |
| 7408 | */ |
| 7409 | boolean isVisibleOrAdding() { |
| 7410 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7411 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7412 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7413 | && mPolicyVisibility && !mAttachedHidden |
| 7414 | && (atoken == null || !atoken.hiddenRequested) |
| 7415 | && !mExiting && !mDestroying; |
| 7416 | } |
| 7417 | |
| 7418 | /** |
| 7419 | * Is this window currently on-screen? It is on-screen either if it |
| 7420 | * is visible or it is currently running an animation before no longer |
| 7421 | * being visible. |
| 7422 | */ |
| 7423 | boolean isOnScreen() { |
| 7424 | final AppWindowToken atoken = mAppToken; |
| 7425 | if (atoken != null) { |
| 7426 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7427 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7428 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7429 | } else { |
| 7430 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7431 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7432 | } |
| 7433 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7435 | /** |
| 7436 | * Like isOnScreen(), but we don't return true if the window is part |
| 7437 | * of a transition that has not yet been started. |
| 7438 | */ |
| 7439 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7440 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7441 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7442 | return false; |
| 7443 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7444 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7445 | final boolean animating = atoken != null |
| 7446 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7447 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7448 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7449 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7450 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7451 | } |
| 7452 | |
| 7453 | /** Is the window or its container currently animating? */ |
| 7454 | boolean isAnimating() { |
| 7455 | final WindowState attached = mAttachedWindow; |
| 7456 | final AppWindowToken atoken = mAppToken; |
| 7457 | return mAnimation != null |
| 7458 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7459 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7460 | (atoken.animation != null |
| 7461 | || atoken.inPendingTransaction)); |
| 7462 | } |
| 7463 | |
| 7464 | /** Is this window currently animating? */ |
| 7465 | boolean isWindowAnimating() { |
| 7466 | return mAnimation != null; |
| 7467 | } |
| 7468 | |
| 7469 | /** |
| 7470 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7471 | * been drawn. |
| 7472 | */ |
| 7473 | public boolean isDisplayedLw() { |
| 7474 | final AppWindowToken atoken = mAppToken; |
| 7475 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7476 | && !mDrawPending && !mCommitDrawPending |
| 7477 | && ((!mAttachedHidden && |
| 7478 | (atoken == null || !atoken.hiddenRequested)) |
| 7479 | || mAnimating); |
| 7480 | } |
| 7481 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7482 | /** |
| 7483 | * Returns true if the window has a surface that it has drawn a |
| 7484 | * complete UI in to. |
| 7485 | */ |
| 7486 | public boolean isDrawnLw() { |
| 7487 | final AppWindowToken atoken = mAppToken; |
| 7488 | return mSurface != null && !mDestroying |
| 7489 | && !mDrawPending && !mCommitDrawPending; |
| 7490 | } |
| 7491 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7492 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7493 | * Return true if the window is opaque and fully drawn. This indicates |
| 7494 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7495 | */ |
| 7496 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7497 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7498 | || mAttrs.type == TYPE_WALLPAPER) |
| 7499 | && mSurface != null && mAnimation == null |
| 7500 | && (mAppToken == null || mAppToken.animation == null) |
| 7501 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7502 | } |
| 7503 | |
| 7504 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7505 | return |
| 7506 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7507 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7508 | // only if it's visible |
| 7509 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7510 | // and only if the application fills the compatible screen |
| 7511 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7512 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7513 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7514 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7515 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7516 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7517 | } |
| 7518 | |
| 7519 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7520 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7521 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7522 | } |
| 7523 | |
| 7524 | void removeLocked() { |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7525 | disposeInputChannel(); |
| 7526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7527 | if (mAttachedWindow != null) { |
| 7528 | mAttachedWindow.mChildWindows.remove(this); |
| 7529 | } |
| 7530 | destroySurfaceLocked(); |
| 7531 | mSession.windowRemovedLocked(); |
| 7532 | try { |
| 7533 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7534 | } catch (RuntimeException e) { |
| 7535 | // Ignore if it has already been removed (usually because |
| 7536 | // we are doing this as part of processing a death note.) |
| 7537 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | void disposeInputChannel() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7541 | if (mInputChannel != null) { |
| 7542 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7543 | |
| 7544 | mInputChannel.dispose(); |
| 7545 | mInputChannel = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7546 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7547 | } |
| 7548 | |
| 7549 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7550 | public void binderDied() { |
| 7551 | try { |
| 7552 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7553 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7554 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7555 | if (win != null) { |
| 7556 | removeWindowLocked(mSession, win); |
| 7557 | } |
| 7558 | } |
| 7559 | } catch (IllegalArgumentException ex) { |
| 7560 | // This will happen if the window has already been |
| 7561 | // removed. |
| 7562 | } |
| 7563 | } |
| 7564 | } |
| 7565 | |
| 7566 | /** Returns true if this window desires key events. */ |
| 7567 | public final boolean canReceiveKeys() { |
| 7568 | return isVisibleOrAdding() |
| 7569 | && (mViewVisibility == View.VISIBLE) |
| 7570 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7571 | } |
| 7572 | |
| 7573 | public boolean hasDrawnLw() { |
| 7574 | return mHasDrawn; |
| 7575 | } |
| 7576 | |
| 7577 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7578 | return showLw(doAnimation, true); |
| 7579 | } |
| 7580 | |
| 7581 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7582 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7583 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7584 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7585 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7586 | if (doAnimation) { |
| 7587 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7588 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7589 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7590 | doAnimation = false; |
| 7591 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7592 | // Check for the case where we are currently visible and |
| 7593 | // not animating; we do not want to do animation at such a |
| 7594 | // point to become visible when we already are. |
| 7595 | doAnimation = false; |
| 7596 | } |
| 7597 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7598 | mPolicyVisibility = true; |
| 7599 | mPolicyVisibilityAfterAnim = true; |
| 7600 | if (doAnimation) { |
| 7601 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7602 | } |
| 7603 | if (requestAnim) { |
| 7604 | requestAnimationLocked(0); |
| 7605 | } |
| 7606 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7607 | } |
| 7608 | |
| 7609 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7610 | return hideLw(doAnimation, true); |
| 7611 | } |
| 7612 | |
| 7613 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7614 | if (doAnimation) { |
| 7615 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7616 | doAnimation = false; |
| 7617 | } |
| 7618 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7619 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7620 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7621 | if (!current) { |
| 7622 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7624 | if (doAnimation) { |
| 7625 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7626 | if (mAnimation == null) { |
| 7627 | doAnimation = false; |
| 7628 | } |
| 7629 | } |
| 7630 | if (doAnimation) { |
| 7631 | mPolicyVisibilityAfterAnim = false; |
| 7632 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7633 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7634 | mPolicyVisibilityAfterAnim = false; |
| 7635 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7636 | // Window is no longer visible -- make sure if we were waiting |
| 7637 | // for it to be displayed before enabling the display, that |
| 7638 | // we allow the display to be enabled now. |
| 7639 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7640 | if (mCurrentFocus == this) { |
| 7641 | mFocusMayChange = true; |
| 7642 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7643 | } |
| 7644 | if (requestAnim) { |
| 7645 | requestAnimationLocked(0); |
| 7646 | } |
| 7647 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | } |
| 7649 | |
| 7650 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7651 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7652 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7653 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7654 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7655 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7656 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7657 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7658 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7659 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7660 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7661 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7662 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7663 | } |
| 7664 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7665 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7666 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7667 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7668 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7669 | pw.print("="); pw.print(mAnimLayer); |
| 7670 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7671 | if (mSurface != null) { |
| 7672 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7673 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7674 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7675 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7676 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7677 | pw.print(","); pw.print(mSurfaceY); |
| 7678 | pw.print(") "); pw.print(mSurfaceW); |
| 7679 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7680 | } |
| 7681 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7682 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7683 | if (mAppToken != null) { |
| 7684 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7685 | } |
| 7686 | if (mTargetAppToken != null) { |
| 7687 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7688 | } |
| 7689 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7690 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7691 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7692 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7693 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7694 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7695 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7696 | pw.print(mPolicyVisibility); |
| 7697 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7698 | pw.print(mPolicyVisibilityAfterAnim); |
| 7699 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7700 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7701 | if (!mRelayoutCalled) { |
| 7702 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7703 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7704 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7705 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7706 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7707 | if (mXOffset != 0 || mYOffset != 0) { |
| 7708 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7709 | pw.print(" y="); pw.println(mYOffset); |
| 7710 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7711 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7712 | mGivenContentInsets.printShortString(pw); |
| 7713 | pw.print(" mGivenVisibleInsets="); |
| 7714 | mGivenVisibleInsets.printShortString(pw); |
| 7715 | pw.println(); |
| 7716 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7717 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7718 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7719 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7720 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7721 | pw.print(prefix); pw.print("mShownFrame="); |
| 7722 | mShownFrame.printShortString(pw); |
| 7723 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7724 | pw.println(); |
| 7725 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7726 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7727 | pw.println(); |
| 7728 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7729 | mContainingFrame.printShortString(pw); |
| 7730 | pw.print(" mDisplayFrame="); |
| 7731 | mDisplayFrame.printShortString(pw); |
| 7732 | pw.println(); |
| 7733 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7734 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7735 | pw.println(); |
| 7736 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7737 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7738 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7739 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7740 | pw.println(); |
| 7741 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7742 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7743 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7744 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7745 | } |
| 7746 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7747 | || mAnimation != null) { |
| 7748 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7749 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7750 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7751 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7752 | } |
| 7753 | if (mHasTransformation || mHasLocalTransformation) { |
| 7754 | pw.print(prefix); pw.print("XForm: has="); |
| 7755 | pw.print(mHasTransformation); |
| 7756 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7757 | pw.print(" "); mTransformation.printShortString(pw); |
| 7758 | pw.println(); |
| 7759 | } |
| 7760 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7761 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7762 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7763 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7764 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7765 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7766 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7767 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7768 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7769 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7770 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7771 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7772 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7773 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7774 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7775 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7776 | if (mHScale != 1 || mVScale != 1) { |
| 7777 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7778 | pw.print(" mVScale="); pw.println(mVScale); |
| 7779 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7780 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7781 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7782 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7783 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7784 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7785 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7786 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7787 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7788 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7789 | |
| 7790 | String makeInputChannelName() { |
| 7791 | return Integer.toHexString(System.identityHashCode(this)) |
| 7792 | + " " + mAttrs.getTitle(); |
| 7793 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7794 | |
| 7795 | @Override |
| 7796 | public String toString() { |
| 7797 | return "Window{" |
| 7798 | + Integer.toHexString(System.identityHashCode(this)) |
| 7799 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7800 | } |
| 7801 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7802 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7803 | // ------------------------------------------------------------- |
| 7804 | // Window Token State |
| 7805 | // ------------------------------------------------------------- |
| 7806 | |
| 7807 | class WindowToken { |
| 7808 | // The actual token. |
| 7809 | final IBinder token; |
| 7810 | |
| 7811 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7812 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7814 | // Set if this token was explicitly added by a client, so should |
| 7815 | // not be removed when all windows are removed. |
| 7816 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7817 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7818 | // For printing. |
| 7819 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7820 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7821 | // If this is an AppWindowToken, this is non-null. |
| 7822 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7823 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | // All of the windows associated with this token. |
| 7825 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7826 | |
| 7827 | // Is key dispatching paused for this token? |
| 7828 | boolean paused = false; |
| 7829 | |
| 7830 | // Should this token's windows be hidden? |
| 7831 | boolean hidden; |
| 7832 | |
| 7833 | // Temporary for finding which tokens no longer have visible windows. |
| 7834 | boolean hasVisible; |
| 7835 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7836 | // Set to true when this token is in a pending transaction where it |
| 7837 | // will be shown. |
| 7838 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7839 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7840 | // Set to true when this token is in a pending transaction where it |
| 7841 | // will be hidden. |
| 7842 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7843 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7844 | // Set to true when this token is in a pending transaction where its |
| 7845 | // windows will be put to the bottom of the list. |
| 7846 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7847 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7848 | // Set to true when this token is in a pending transaction where its |
| 7849 | // windows will be put to the top of the list. |
| 7850 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7851 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7852 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7853 | token = _token; |
| 7854 | windowType = type; |
| 7855 | explicit = _explicit; |
| 7856 | } |
| 7857 | |
| 7858 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7859 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7860 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7861 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7862 | pw.print(" hidden="); pw.print(hidden); |
| 7863 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7864 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7865 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7866 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7867 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7868 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7869 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7870 | } |
| 7871 | |
| 7872 | @Override |
| 7873 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7874 | if (stringName == null) { |
| 7875 | StringBuilder sb = new StringBuilder(); |
| 7876 | sb.append("WindowToken{"); |
| 7877 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7878 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7879 | stringName = sb.toString(); |
| 7880 | } |
| 7881 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7882 | } |
| 7883 | }; |
| 7884 | |
| 7885 | class AppWindowToken extends WindowToken { |
| 7886 | // Non-null only for application tokens. |
| 7887 | final IApplicationToken appToken; |
| 7888 | |
| 7889 | // All of the windows and child windows that are included in this |
| 7890 | // application token. Note this list is NOT sorted! |
| 7891 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7892 | |
| 7893 | int groupId = -1; |
| 7894 | boolean appFullscreen; |
| 7895 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7896 | |
| 7897 | // The input dispatching timeout for this application token in nanoseconds. |
| 7898 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7900 | // These are used for determining when all windows associated with |
| 7901 | // an activity have been drawn, so they can be made visible together |
| 7902 | // at the same time. |
| 7903 | int lastTransactionSequence = mTransactionSequence-1; |
| 7904 | int numInterestingWindows; |
| 7905 | int numDrawnWindows; |
| 7906 | boolean inPendingTransaction; |
| 7907 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7909 | // Is this token going to be hidden in a little while? If so, it |
| 7910 | // won't be taken into account for setting the screen orientation. |
| 7911 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7913 | // Is this window's surface needed? This is almost like hidden, except |
| 7914 | // it will sometimes be true a little earlier: when the token has |
| 7915 | // been shown, but is still waiting for its app transition to execute |
| 7916 | // before making its windows shown. |
| 7917 | boolean hiddenRequested; |
| 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 | // Have we told the window clients to hide themselves? |
| 7920 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7921 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7922 | // Last visibility state we reported to the app token. |
| 7923 | boolean reportedVisible; |
| 7924 | |
| 7925 | // Set to true when the token has been removed from the window mgr. |
| 7926 | boolean removed; |
| 7927 | |
| 7928 | // Have we been asked to have this token keep the screen frozen? |
| 7929 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7930 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7931 | boolean animating; |
| 7932 | Animation animation; |
| 7933 | boolean hasTransformation; |
| 7934 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7935 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7936 | // Offset to the window of all layers in the token, for use by |
| 7937 | // AppWindowToken animations. |
| 7938 | int animLayerAdjustment; |
| 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 | // Information about an application starting window if displayed. |
| 7941 | StartingData startingData; |
| 7942 | WindowState startingWindow; |
| 7943 | View startingView; |
| 7944 | boolean startingDisplayed; |
| 7945 | boolean startingMoved; |
| 7946 | boolean firstWindowDrawn; |
| 7947 | |
| 7948 | AppWindowToken(IApplicationToken _token) { |
| 7949 | super(_token.asBinder(), |
| 7950 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7951 | appWindowToken = this; |
| 7952 | appToken = _token; |
| 7953 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7955 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7956 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7957 | TAG, "Setting animation in " + this + ": " + anim); |
| 7958 | animation = anim; |
| 7959 | animating = false; |
| 7960 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7961 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7962 | int zorder = anim.getZAdjustment(); |
| 7963 | int adj = 0; |
| 7964 | if (zorder == Animation.ZORDER_TOP) { |
| 7965 | adj = TYPE_LAYER_OFFSET; |
| 7966 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7967 | adj = -TYPE_LAYER_OFFSET; |
| 7968 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7969 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7970 | if (animLayerAdjustment != adj) { |
| 7971 | animLayerAdjustment = adj; |
| 7972 | updateLayers(); |
| 7973 | } |
| 7974 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7976 | public void setDummyAnimation() { |
| 7977 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7978 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7979 | TAG, "Setting dummy animation in " + this); |
| 7980 | animation = sDummyAnimation; |
| 7981 | } |
| 7982 | } |
| 7983 | |
| 7984 | public void clearAnimation() { |
| 7985 | if (animation != null) { |
| 7986 | animation = null; |
| 7987 | animating = true; |
| 7988 | } |
| 7989 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7990 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7991 | void updateLayers() { |
| 7992 | final int N = allAppWindows.size(); |
| 7993 | final int adj = animLayerAdjustment; |
| 7994 | for (int i=0; i<N; i++) { |
| 7995 | WindowState w = allAppWindows.get(i); |
| 7996 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7997 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7998 | + w.mAnimLayer); |
| 7999 | if (w == mInputMethodTarget) { |
| 8000 | setInputMethodAnimLayerAdjustment(adj); |
| 8001 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8002 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8003 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8004 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8005 | } |
| 8006 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8007 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8008 | void sendAppVisibilityToClients() { |
| 8009 | final int N = allAppWindows.size(); |
| 8010 | for (int i=0; i<N; i++) { |
| 8011 | WindowState win = allAppWindows.get(i); |
| 8012 | if (win == startingWindow && clientHidden) { |
| 8013 | // Don't hide the starting window. |
| 8014 | continue; |
| 8015 | } |
| 8016 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8017 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8018 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8019 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8020 | } catch (RemoteException e) { |
| 8021 | } |
| 8022 | } |
| 8023 | } |
| 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 | void showAllWindowsLocked() { |
| 8026 | final int NW = allAppWindows.size(); |
| 8027 | for (int i=0; i<NW; i++) { |
| 8028 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8029 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8030 | "performing show on: " + w); |
| 8031 | w.performShowLocked(); |
| 8032 | } |
| 8033 | } |
| 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 | // This must be called while inside a transaction. |
| 8036 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8037 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8039 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8040 | if (animation == sDummyAnimation) { |
| 8041 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8042 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8043 | // when it is really time to animate, this will be set to |
| 8044 | // a real animation and the next call will execute normally. |
| 8045 | return false; |
| 8046 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8047 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8048 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8049 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8050 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8051 | TAG, "Starting animation in " + this + |
| 8052 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8053 | + " scale=" + mTransitionAnimationScale |
| 8054 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8055 | animation.initialize(dw, dh, dw, dh); |
| 8056 | animation.setStartTime(currentTime); |
| 8057 | animating = true; |
| 8058 | } |
| 8059 | transformation.clear(); |
| 8060 | final boolean more = animation.getTransformation( |
| 8061 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8062 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8063 | TAG, "Stepped animation in " + this + |
| 8064 | ": more=" + more + ", xform=" + transformation); |
| 8065 | if (more) { |
| 8066 | // we're done! |
| 8067 | hasTransformation = true; |
| 8068 | return true; |
| 8069 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8070 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8071 | TAG, "Finished animation in " + this + |
| 8072 | " @ " + currentTime); |
| 8073 | animation = null; |
| 8074 | } |
| 8075 | } else if (animation != null) { |
| 8076 | // If the display is frozen, and there is a pending animation, |
| 8077 | // clear it and make sure we run the cleanup code. |
| 8078 | animating = true; |
| 8079 | animation = null; |
| 8080 | } |
| 8081 | |
| 8082 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8083 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8084 | if (!animating) { |
| 8085 | return false; |
| 8086 | } |
| 8087 | |
| 8088 | clearAnimation(); |
| 8089 | animating = false; |
| 8090 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8091 | moveInputMethodWindowsIfNeededLocked(true); |
| 8092 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8093 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8094 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8095 | TAG, "Animation done in " + this |
| 8096 | + ": reportedVisible=" + reportedVisible); |
| 8097 | |
| 8098 | transformation.clear(); |
| 8099 | if (animLayerAdjustment != 0) { |
| 8100 | animLayerAdjustment = 0; |
| 8101 | updateLayers(); |
| 8102 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8103 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8104 | final int N = windows.size(); |
| 8105 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8106 | windows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8107 | } |
| 8108 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8110 | return false; |
| 8111 | } |
| 8112 | |
| 8113 | void updateReportedVisibilityLocked() { |
| 8114 | if (appToken == null) { |
| 8115 | return; |
| 8116 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8117 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8118 | int numInteresting = 0; |
| 8119 | int numVisible = 0; |
| 8120 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8121 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8122 | 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] | 8123 | final int N = allAppWindows.size(); |
| 8124 | for (int i=0; i<N; i++) { |
| 8125 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8126 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8127 | || win.mViewVisibility != View.VISIBLE |
| 8128 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8129 | continue; |
| 8130 | } |
| 8131 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8132 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8133 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8135 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8136 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | + " pv=" + win.mPolicyVisibility |
| 8138 | + " dp=" + win.mDrawPending |
| 8139 | + " cdp=" + win.mCommitDrawPending |
| 8140 | + " ah=" + win.mAttachedHidden |
| 8141 | + " th=" |
| 8142 | + (win.mAppToken != null |
| 8143 | ? win.mAppToken.hiddenRequested : false) |
| 8144 | + " a=" + win.mAnimating); |
| 8145 | } |
| 8146 | } |
| 8147 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8148 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8149 | if (!win.isAnimating()) { |
| 8150 | numVisible++; |
| 8151 | } |
| 8152 | nowGone = false; |
| 8153 | } else if (win.isAnimating()) { |
| 8154 | nowGone = false; |
| 8155 | } |
| 8156 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8157 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8158 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8159 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8160 | + numInteresting + " visible=" + numVisible); |
| 8161 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8162 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8163 | TAG, "Visibility changed in " + this |
| 8164 | + ": vis=" + nowVisible); |
| 8165 | reportedVisible = nowVisible; |
| 8166 | Message m = mH.obtainMessage( |
| 8167 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8168 | nowVisible ? 1 : 0, |
| 8169 | nowGone ? 1 : 0, |
| 8170 | this); |
| 8171 | mH.sendMessage(m); |
| 8172 | } |
| 8173 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8174 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8175 | WindowState findMainWindow() { |
| 8176 | int j = windows.size(); |
| 8177 | while (j > 0) { |
| 8178 | j--; |
| 8179 | WindowState win = windows.get(j); |
| 8180 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8181 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8182 | return win; |
| 8183 | } |
| 8184 | } |
| 8185 | return null; |
| 8186 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8188 | void dump(PrintWriter pw, String prefix) { |
| 8189 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8190 | if (appToken != null) { |
| 8191 | pw.print(prefix); pw.println("app=true"); |
| 8192 | } |
| 8193 | if (allAppWindows.size() > 0) { |
| 8194 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8195 | } |
| 8196 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8197 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8198 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8199 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8200 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8201 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8202 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8203 | if (paused || freezingScreen) { |
| 8204 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8205 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8206 | } |
| 8207 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8208 | || inPendingTransaction || allDrawn) { |
| 8209 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8210 | pw.print(numInterestingWindows); |
| 8211 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8212 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8213 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8214 | } |
| 8215 | if (animating || animation != null) { |
| 8216 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8217 | pw.print(" animation="); pw.println(animation); |
| 8218 | } |
| 8219 | if (animLayerAdjustment != 0) { |
| 8220 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8221 | } |
| 8222 | if (hasTransformation) { |
| 8223 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8224 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8225 | pw.println(); |
| 8226 | } |
| 8227 | if (startingData != null || removed || firstWindowDrawn) { |
| 8228 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8229 | pw.print(" removed="); pw.print(removed); |
| 8230 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8231 | } |
| 8232 | if (startingWindow != null || startingView != null |
| 8233 | || startingDisplayed || startingMoved) { |
| 8234 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8235 | pw.print(" startingView="); pw.print(startingView); |
| 8236 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8237 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8238 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8239 | } |
| 8240 | |
| 8241 | @Override |
| 8242 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8243 | if (stringName == null) { |
| 8244 | StringBuilder sb = new StringBuilder(); |
| 8245 | sb.append("AppWindowToken{"); |
| 8246 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8247 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8248 | stringName = sb.toString(); |
| 8249 | } |
| 8250 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8251 | } |
| 8252 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8254 | // ------------------------------------------------------------- |
| 8255 | // DummyAnimation |
| 8256 | // ------------------------------------------------------------- |
| 8257 | |
| 8258 | // This is an animation that does nothing: it just immediately finishes |
| 8259 | // itself every time it is called. It is used as a stub animation in cases |
| 8260 | // where we want to synchronize multiple things that may be animating. |
| 8261 | static final class DummyAnimation extends Animation { |
| 8262 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8263 | return false; |
| 8264 | } |
| 8265 | } |
| 8266 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8268 | // ------------------------------------------------------------- |
| 8269 | // Async Handler |
| 8270 | // ------------------------------------------------------------- |
| 8271 | |
| 8272 | static final class StartingData { |
| 8273 | final String pkg; |
| 8274 | final int theme; |
| 8275 | final CharSequence nonLocalizedLabel; |
| 8276 | final int labelRes; |
| 8277 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8278 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8279 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8280 | int _labelRes, int _icon) { |
| 8281 | pkg = _pkg; |
| 8282 | theme = _theme; |
| 8283 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8284 | labelRes = _labelRes; |
| 8285 | icon = _icon; |
| 8286 | } |
| 8287 | } |
| 8288 | |
| 8289 | private final class H extends Handler { |
| 8290 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8291 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8292 | public static final int ANIMATE = 4; |
| 8293 | public static final int ADD_STARTING = 5; |
| 8294 | public static final int REMOVE_STARTING = 6; |
| 8295 | public static final int FINISHED_STARTING = 7; |
| 8296 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8297 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8298 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8299 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8300 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8301 | public static final int FORCE_GC = 15; |
| 8302 | public static final int ENABLE_SCREEN = 16; |
| 8303 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8304 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8305 | public static final int REPORT_WINDOWS_CHANGE = 19; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8306 | public static final int DRAG_START_TIMEOUT = 20; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8308 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8310 | public H() { |
| 8311 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8313 | @Override |
| 8314 | public void handleMessage(Message msg) { |
| 8315 | switch (msg.what) { |
| 8316 | case REPORT_FOCUS_CHANGE: { |
| 8317 | WindowState lastFocus; |
| 8318 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8319 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8320 | synchronized(mWindowMap) { |
| 8321 | lastFocus = mLastFocus; |
| 8322 | newFocus = mCurrentFocus; |
| 8323 | if (lastFocus == newFocus) { |
| 8324 | // Focus is not changing, so nothing to do. |
| 8325 | return; |
| 8326 | } |
| 8327 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8328 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8329 | // + " to " + newFocus); |
| 8330 | if (newFocus != null && lastFocus != null |
| 8331 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8332 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8333 | mLosingFocus.add(lastFocus); |
| 8334 | lastFocus = null; |
| 8335 | } |
| 8336 | } |
| 8337 | |
| 8338 | if (lastFocus != newFocus) { |
| 8339 | //System.out.println("Changing focus from " + lastFocus |
| 8340 | // + " to " + newFocus); |
| 8341 | if (newFocus != null) { |
| 8342 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8343 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8344 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8345 | } catch (RemoteException e) { |
| 8346 | // Ignore if process has died. |
| 8347 | } |
| Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8348 | notifyFocusChanged(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8349 | } |
| 8350 | |
| 8351 | if (lastFocus != null) { |
| 8352 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8353 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8354 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8355 | } catch (RemoteException e) { |
| 8356 | // Ignore if process has died. |
| 8357 | } |
| 8358 | } |
| 8359 | } |
| 8360 | } break; |
| 8361 | |
| 8362 | case REPORT_LOSING_FOCUS: { |
| 8363 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8365 | synchronized(mWindowMap) { |
| 8366 | losers = mLosingFocus; |
| 8367 | mLosingFocus = new ArrayList<WindowState>(); |
| 8368 | } |
| 8369 | |
| 8370 | final int N = losers.size(); |
| 8371 | for (int i=0; i<N; i++) { |
| 8372 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8373 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8374 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8375 | } catch (RemoteException e) { |
| 8376 | // Ignore if process has died. |
| 8377 | } |
| 8378 | } |
| 8379 | } break; |
| 8380 | |
| 8381 | case ANIMATE: { |
| 8382 | synchronized(mWindowMap) { |
| 8383 | mAnimationPending = false; |
| 8384 | performLayoutAndPlaceSurfacesLocked(); |
| 8385 | } |
| 8386 | } break; |
| 8387 | |
| 8388 | case ADD_STARTING: { |
| 8389 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8390 | final StartingData sd = wtoken.startingData; |
| 8391 | |
| 8392 | if (sd == null) { |
| 8393 | // Animation has been canceled... do nothing. |
| 8394 | return; |
| 8395 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8396 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8397 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8398 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8399 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8400 | View view = null; |
| 8401 | try { |
| 8402 | view = mPolicy.addStartingWindow( |
| 8403 | wtoken.token, sd.pkg, |
| 8404 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8405 | sd.icon); |
| 8406 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8407 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8408 | } |
| 8409 | |
| 8410 | if (view != null) { |
| 8411 | boolean abort = false; |
| 8412 | |
| 8413 | synchronized(mWindowMap) { |
| 8414 | if (wtoken.removed || wtoken.startingData == null) { |
| 8415 | // If the window was successfully added, then |
| 8416 | // we need to remove it. |
| 8417 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8418 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8419 | "Aborted starting " + wtoken |
| 8420 | + ": removed=" + wtoken.removed |
| 8421 | + " startingData=" + wtoken.startingData); |
| 8422 | wtoken.startingWindow = null; |
| 8423 | wtoken.startingData = null; |
| 8424 | abort = true; |
| 8425 | } |
| 8426 | } else { |
| 8427 | wtoken.startingView = view; |
| 8428 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8429 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8430 | "Added starting " + wtoken |
| 8431 | + ": startingWindow=" |
| 8432 | + wtoken.startingWindow + " startingView=" |
| 8433 | + wtoken.startingView); |
| 8434 | } |
| 8435 | |
| 8436 | if (abort) { |
| 8437 | try { |
| 8438 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8439 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8440 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8441 | } |
| 8442 | } |
| 8443 | } |
| 8444 | } break; |
| 8445 | |
| 8446 | case REMOVE_STARTING: { |
| 8447 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8448 | IBinder token = null; |
| 8449 | View view = null; |
| 8450 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8451 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8452 | + wtoken + ": startingWindow=" |
| 8453 | + wtoken.startingWindow + " startingView=" |
| 8454 | + wtoken.startingView); |
| 8455 | if (wtoken.startingWindow != null) { |
| 8456 | view = wtoken.startingView; |
| 8457 | token = wtoken.token; |
| 8458 | wtoken.startingData = null; |
| 8459 | wtoken.startingView = null; |
| 8460 | wtoken.startingWindow = null; |
| 8461 | } |
| 8462 | } |
| 8463 | if (view != null) { |
| 8464 | try { |
| 8465 | mPolicy.removeStartingWindow(token, view); |
| 8466 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8467 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8468 | } |
| 8469 | } |
| 8470 | } break; |
| 8471 | |
| 8472 | case FINISHED_STARTING: { |
| 8473 | IBinder token = null; |
| 8474 | View view = null; |
| 8475 | while (true) { |
| 8476 | synchronized (mWindowMap) { |
| 8477 | final int N = mFinishedStarting.size(); |
| 8478 | if (N <= 0) { |
| 8479 | break; |
| 8480 | } |
| 8481 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8482 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8483 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8484 | "Finished starting " + wtoken |
| 8485 | + ": startingWindow=" + wtoken.startingWindow |
| 8486 | + " startingView=" + wtoken.startingView); |
| 8487 | |
| 8488 | if (wtoken.startingWindow == null) { |
| 8489 | continue; |
| 8490 | } |
| 8491 | |
| 8492 | view = wtoken.startingView; |
| 8493 | token = wtoken.token; |
| 8494 | wtoken.startingData = null; |
| 8495 | wtoken.startingView = null; |
| 8496 | wtoken.startingWindow = null; |
| 8497 | } |
| 8498 | |
| 8499 | try { |
| 8500 | mPolicy.removeStartingWindow(token, view); |
| 8501 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8502 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8503 | } |
| 8504 | } |
| 8505 | } break; |
| 8506 | |
| 8507 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8508 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8509 | |
| 8510 | boolean nowVisible = msg.arg1 != 0; |
| 8511 | boolean nowGone = msg.arg2 != 0; |
| 8512 | |
| 8513 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8514 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8515 | TAG, "Reporting visible in " + wtoken |
| 8516 | + " visible=" + nowVisible |
| 8517 | + " gone=" + nowGone); |
| 8518 | if (nowVisible) { |
| 8519 | wtoken.appToken.windowsVisible(); |
| 8520 | } else { |
| 8521 | wtoken.appToken.windowsGone(); |
| 8522 | } |
| 8523 | } catch (RemoteException ex) { |
| 8524 | } |
| 8525 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8527 | case WINDOW_FREEZE_TIMEOUT: { |
| 8528 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8529 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8530 | int i = mWindows.size(); |
| 8531 | while (i > 0) { |
| 8532 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8533 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8534 | if (w.mOrientationChanging) { |
| 8535 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8536 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8537 | } |
| 8538 | } |
| 8539 | performLayoutAndPlaceSurfacesLocked(); |
| 8540 | } |
| 8541 | break; |
| 8542 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8543 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8544 | case HOLD_SCREEN_CHANGED: { |
| 8545 | Session oldHold; |
| 8546 | Session newHold; |
| 8547 | synchronized (mWindowMap) { |
| 8548 | oldHold = mLastReportedHold; |
| 8549 | newHold = (Session)msg.obj; |
| 8550 | mLastReportedHold = newHold; |
| 8551 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8552 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8553 | if (oldHold != newHold) { |
| 8554 | try { |
| 8555 | if (oldHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8556 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8557 | "window", |
| 8558 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8559 | } |
| 8560 | if (newHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8561 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8562 | "window", |
| 8563 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8564 | } |
| 8565 | } catch (RemoteException e) { |
| 8566 | } |
| 8567 | } |
| 8568 | break; |
| 8569 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8571 | case APP_TRANSITION_TIMEOUT: { |
| 8572 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8573 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8574 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8575 | "*** APP TRANSITION TIMEOUT"); |
| 8576 | mAppTransitionReady = true; |
| 8577 | mAppTransitionTimeout = true; |
| 8578 | performLayoutAndPlaceSurfacesLocked(); |
| 8579 | } |
| 8580 | } |
| 8581 | break; |
| 8582 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8583 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8584 | case PERSIST_ANIMATION_SCALE: { |
| 8585 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8586 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8587 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8588 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8589 | break; |
| 8590 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8592 | case FORCE_GC: { |
| 8593 | synchronized(mWindowMap) { |
| 8594 | if (mAnimationPending) { |
| 8595 | // If we are animating, don't do the gc now but |
| 8596 | // delay a bit so we don't interrupt the animation. |
| 8597 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8598 | 2000); |
| 8599 | return; |
| 8600 | } |
| 8601 | // If we are currently rotating the display, it will |
| 8602 | // schedule a new message when done. |
| 8603 | if (mDisplayFrozen) { |
| 8604 | return; |
| 8605 | } |
| 8606 | mFreezeGcPending = 0; |
| 8607 | } |
| 8608 | Runtime.getRuntime().gc(); |
| 8609 | break; |
| 8610 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8612 | case ENABLE_SCREEN: { |
| 8613 | performEnableScreen(); |
| 8614 | break; |
| 8615 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8616 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8617 | case APP_FREEZE_TIMEOUT: { |
| 8618 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8619 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | int i = mAppTokens.size(); |
| 8621 | while (i > 0) { |
| 8622 | i--; |
| 8623 | AppWindowToken tok = mAppTokens.get(i); |
| 8624 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8625 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8626 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8627 | } |
| 8628 | } |
| 8629 | } |
| 8630 | break; |
| 8631 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8632 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8633 | case SEND_NEW_CONFIGURATION: { |
| 8634 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8635 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8636 | break; |
| 8637 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8638 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8639 | case REPORT_WINDOWS_CHANGE: { |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8640 | if (mWindowsChanged) { |
| 8641 | synchronized (mWindowMap) { |
| 8642 | mWindowsChanged = false; |
| 8643 | } |
| 8644 | notifyWindowsChanged(); |
| 8645 | } |
| 8646 | break; |
| 8647 | } |
| 8648 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8649 | case DRAG_START_TIMEOUT: { |
| 8650 | IBinder win = (IBinder)msg.obj; |
| 8651 | if (DEBUG_DRAG) { |
| 8652 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 8653 | } |
| 8654 | synchronized (mWindowMap) { |
| 8655 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 8656 | if (mDragState != null) { |
| 8657 | mDragState.reset(); |
| 8658 | mDragState = null; |
| 8659 | } |
| 8660 | } |
| 8661 | } |
| 8662 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8663 | } |
| 8664 | } |
| 8665 | } |
| 8666 | |
| 8667 | // ------------------------------------------------------------- |
| 8668 | // IWindowManager API |
| 8669 | // ------------------------------------------------------------- |
| 8670 | |
| 8671 | public IWindowSession openSession(IInputMethodClient client, |
| 8672 | IInputContext inputContext) { |
| 8673 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8674 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8675 | Session session = new Session(client, inputContext); |
| 8676 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8677 | } |
| 8678 | |
| 8679 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8680 | synchronized (mWindowMap) { |
| 8681 | // The focus for the client is the window immediately below |
| 8682 | // where we would place the input method window. |
| 8683 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8684 | WindowState imFocus; |
| 8685 | if (idx > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8686 | imFocus = mWindows.get(idx-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8687 | if (imFocus != null) { |
| 8688 | if (imFocus.mSession.mClient != null && |
| 8689 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8690 | return true; |
| 8691 | } |
| 8692 | } |
| 8693 | } |
| 8694 | } |
| 8695 | return false; |
| 8696 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8697 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8698 | // ------------------------------------------------------------- |
| 8699 | // Internals |
| 8700 | // ------------------------------------------------------------- |
| 8701 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8702 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8703 | boolean throwOnError) { |
| 8704 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8705 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8706 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8707 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8708 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8709 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8710 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8711 | TAG, "Looking up client " + client + ": " + win); |
| 8712 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8713 | RuntimeException ex = new IllegalArgumentException( |
| 8714 | "Requested window " + client + " does not exist"); |
| 8715 | if (throwOnError) { |
| 8716 | throw ex; |
| 8717 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8718 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8719 | return null; |
| 8720 | } |
| 8721 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8722 | RuntimeException ex = new IllegalArgumentException( |
| 8723 | "Requested window " + client + " is in session " + |
| 8724 | win.mSession + ", not " + session); |
| 8725 | if (throwOnError) { |
| 8726 | throw ex; |
| 8727 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8728 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8729 | return null; |
| 8730 | } |
| 8731 | |
| 8732 | return win; |
| 8733 | } |
| 8734 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8735 | final void rebuildAppWindowListLocked() { |
| 8736 | int NW = mWindows.size(); |
| 8737 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8738 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8739 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8740 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8741 | // First remove all existing app windows. |
| 8742 | i=0; |
| 8743 | while (i < NW) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8744 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8745 | if (w.mAppToken != null) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8746 | WindowState win = mWindows.remove(i); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8747 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8748 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8749 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8750 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8751 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8752 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8753 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8754 | && lastWallpaper == i-1) { |
| 8755 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8756 | } |
| 8757 | i++; |
| 8758 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8759 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8760 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8761 | // so skip them before adding app tokens. |
| 8762 | lastWallpaper++; |
| 8763 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8764 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8765 | // First add all of the exiting app tokens... these are no longer |
| 8766 | // in the main app list, but still have windows shown. We put them |
| 8767 | // in the back because now that the animation is over we no longer |
| 8768 | // will care about them. |
| 8769 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8770 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8771 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8772 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8773 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8774 | // And add in the still active app tokens in Z order. |
| 8775 | NT = mAppTokens.size(); |
| 8776 | for (int j=0; j<NT; j++) { |
| 8777 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8778 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8779 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8780 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8781 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8782 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8783 | + " windows but added " + i); |
| 8784 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8785 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8786 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8787 | private final void assignLayersLocked() { |
| 8788 | int N = mWindows.size(); |
| 8789 | int curBaseLayer = 0; |
| 8790 | int curLayer = 0; |
| 8791 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8792 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8793 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8794 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8795 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8796 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8797 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8798 | w.mLayer = curLayer; |
| 8799 | } else { |
| 8800 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8801 | w.mLayer = curLayer; |
| 8802 | } |
| 8803 | if (w.mTargetAppToken != null) { |
| 8804 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8805 | } else if (w.mAppToken != null) { |
| 8806 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8807 | } else { |
| 8808 | w.mAnimLayer = w.mLayer; |
| 8809 | } |
| 8810 | if (w.mIsImWindow) { |
| 8811 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8812 | } else if (w.mIsWallpaper) { |
| 8813 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8814 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8815 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8816 | + w.mAnimLayer); |
| 8817 | //System.out.println( |
| 8818 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8819 | } |
| 8820 | } |
| 8821 | |
| 8822 | private boolean mInLayout = false; |
| 8823 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8824 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8825 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8826 | throw new RuntimeException("Recursive call!"); |
| 8827 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8828 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8829 | return; |
| 8830 | } |
| 8831 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8832 | if (mWaitingForConfig) { |
| 8833 | // Our configuration has changed (most likely rotation), but we |
| 8834 | // don't yet have the complete configuration to report to |
| 8835 | // applications. Don't do any window layout until we have it. |
| 8836 | return; |
| 8837 | } |
| 8838 | |
| Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8839 | if (mDisplay == null) { |
| 8840 | // Not yet initialized, nothing to do. |
| 8841 | return; |
| 8842 | } |
| 8843 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8844 | boolean recoveringMemory = false; |
| 8845 | if (mForceRemoves != null) { |
| 8846 | recoveringMemory = true; |
| 8847 | // Wait a little it for things to settle down, and off we go. |
| 8848 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8849 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8850 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8851 | removeWindowInnerLocked(ws.mSession, ws); |
| 8852 | } |
| 8853 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8854 | 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] | 8855 | Object tmp = new Object(); |
| 8856 | synchronized (tmp) { |
| 8857 | try { |
| 8858 | tmp.wait(250); |
| 8859 | } catch (InterruptedException e) { |
| 8860 | } |
| 8861 | } |
| 8862 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8864 | mInLayout = true; |
| 8865 | try { |
| 8866 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8867 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8868 | int i = mPendingRemove.size()-1; |
| 8869 | if (i >= 0) { |
| 8870 | while (i >= 0) { |
| 8871 | WindowState w = mPendingRemove.get(i); |
| 8872 | removeWindowInnerLocked(w.mSession, w); |
| 8873 | i--; |
| 8874 | } |
| 8875 | mPendingRemove.clear(); |
| 8876 | |
| 8877 | mInLayout = false; |
| 8878 | assignLayersLocked(); |
| 8879 | mLayoutNeeded = true; |
| 8880 | performLayoutAndPlaceSurfacesLocked(); |
| 8881 | |
| 8882 | } else { |
| 8883 | mInLayout = false; |
| 8884 | if (mLayoutNeeded) { |
| 8885 | requestAnimationLocked(0); |
| 8886 | } |
| 8887 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8888 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8889 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8890 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8891 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8892 | } catch (RuntimeException e) { |
| 8893 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8894 | 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] | 8895 | } |
| 8896 | } |
| 8897 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8898 | private final int performLayoutLockedInner() { |
| 8899 | if (!mLayoutNeeded) { |
| 8900 | return 0; |
| 8901 | } |
| 8902 | |
| 8903 | mLayoutNeeded = false; |
| 8904 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8905 | final int dw = mDisplay.getWidth(); |
| 8906 | final int dh = mDisplay.getHeight(); |
| 8907 | |
| 8908 | final int N = mWindows.size(); |
| 8909 | int i; |
| 8910 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8911 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8912 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8913 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8914 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8915 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8916 | int seq = mLayoutSeq+1; |
| 8917 | if (seq < 0) seq = 0; |
| 8918 | mLayoutSeq = seq; |
| 8919 | |
| 8920 | // First perform layout of any root windows (not attached |
| 8921 | // to another window). |
| 8922 | int topAttached = -1; |
| 8923 | for (i = N-1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8924 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8925 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8926 | // Don't do layout of a window if it is not visible, or |
| 8927 | // soon won't be visible, to avoid wasting time and funky |
| 8928 | // changes while a window is animating away. |
| 8929 | final AppWindowToken atoken = win.mAppToken; |
| 8930 | final boolean gone = win.mViewVisibility == View.GONE |
| 8931 | || !win.mRelayoutCalled |
| 8932 | || win.mRootToken.hidden |
| 8933 | || (atoken != null && atoken.hiddenRequested) |
| 8934 | || win.mAttachedHidden |
| 8935 | || win.mExiting || win.mDestroying; |
| 8936 | |
| 8937 | if (!win.mLayoutAttached) { |
| 8938 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 8939 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8940 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 8941 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 8942 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8943 | + win.mRelayoutCalled + " hidden=" |
| 8944 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8945 | + (atoken != null && atoken.hiddenRequested) |
| 8946 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8947 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8948 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8949 | // If this view is GONE, then skip it -- keep the current |
| 8950 | // frame, and let the caller know so they can ignore it |
| 8951 | // if they want. (We do the normal layout for INVISIBLE |
| 8952 | // windows, since that means "perform layout as normal, |
| 8953 | // just don't display"). |
| 8954 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8955 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8956 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8957 | win.mLayoutSeq = seq; |
| 8958 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8959 | + win.mFrame + " mContainingFrame=" |
| 8960 | + win.mContainingFrame + " mDisplayFrame=" |
| 8961 | + win.mDisplayFrame); |
| 8962 | } else { |
| 8963 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8964 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8965 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8966 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8967 | |
| 8968 | // Now perform layout of attached windows, which usually |
| 8969 | // depend on the position of the window they are attached to. |
| 8970 | // XXX does not deal with windows that are attached to windows |
| 8971 | // that are themselves attached. |
| 8972 | for (i = topAttached; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8973 | WindowState win = mWindows.get(i); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8974 | |
| 8975 | // If this view is GONE, then skip it -- keep the current |
| 8976 | // frame, and let the caller know so they can ignore it |
| 8977 | // if they want. (We do the normal layout for INVISIBLE |
| 8978 | // windows, since that means "perform layout as normal, |
| 8979 | // just don't display"). |
| 8980 | if (win.mLayoutAttached) { |
| 8981 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 8982 | + " mHaveFrame=" + win.mHaveFrame |
| 8983 | + " mViewVisibility=" + win.mViewVisibility |
| 8984 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 8985 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8986 | || !win.mHaveFrame) { |
| 8987 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8988 | win.mLayoutSeq = seq; |
| 8989 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8990 | + win.mFrame + " mContainingFrame=" |
| 8991 | + win.mContainingFrame + " mDisplayFrame=" |
| 8992 | + win.mDisplayFrame); |
| 8993 | } |
| 8994 | } |
| 8995 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8996 | |
| 8997 | // Window frames may have changed. Tell the input dispatcher about it. |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8998 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8999 | |
| 9000 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9001 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9002 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9003 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9004 | boolean recoveringMemory) { |
| Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9005 | if (mDisplay == null) { |
| 9006 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9007 | return; |
| 9008 | } |
| 9009 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9010 | final long currentTime = SystemClock.uptimeMillis(); |
| 9011 | final int dw = mDisplay.getWidth(); |
| 9012 | final int dh = mDisplay.getHeight(); |
| 9013 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9014 | int i; |
| 9015 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9016 | if (mFocusMayChange) { |
| 9017 | mFocusMayChange = false; |
| 9018 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9019 | } |
| 9020 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9021 | // Initialize state of exiting tokens. |
| 9022 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9023 | mExitingTokens.get(i).hasVisible = false; |
| 9024 | } |
| 9025 | |
| 9026 | // Initialize state of exiting applications. |
| 9027 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9028 | mExitingAppTokens.get(i).hasVisible = false; |
| 9029 | } |
| 9030 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9031 | boolean orientationChangeComplete = true; |
| 9032 | Session holdScreen = null; |
| 9033 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9034 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9035 | boolean focusDisplayed = false; |
| 9036 | boolean animating = false; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9037 | boolean createWatermark = false; |
| 9038 | |
| 9039 | if (mFxSession == null) { |
| 9040 | mFxSession = new SurfaceSession(); |
| 9041 | createWatermark = true; |
| 9042 | } |
| 9043 | |
| 9044 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9045 | |
| 9046 | Surface.openTransaction(); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9047 | |
| 9048 | if (createWatermark) { |
| 9049 | createWatermark(); |
| 9050 | } |
| 9051 | if (mWatermark != null) { |
| 9052 | mWatermark.positionSurface(dw, dh); |
| 9053 | } |
| 9054 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9055 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9056 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9057 | int repeats = 0; |
| 9058 | int changes = 0; |
| 9059 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9060 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9061 | repeats++; |
| 9062 | if (repeats > 6) { |
| 9063 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9064 | mLayoutNeeded = false; |
| 9065 | break; |
| 9066 | } |
| 9067 | |
| 9068 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9069 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9070 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9071 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9072 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9073 | assignLayersLocked(); |
| 9074 | mLayoutNeeded = true; |
| 9075 | } |
| 9076 | } |
| 9077 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9078 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9079 | if (updateOrientationFromAppTokensLocked()) { |
| 9080 | mLayoutNeeded = true; |
| 9081 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9082 | } |
| 9083 | } |
| 9084 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9085 | mLayoutNeeded = true; |
| 9086 | } |
| 9087 | } |
| 9088 | |
| 9089 | // FIRST LOOP: Perform a layout, if needed. |
| 9090 | if (repeats < 4) { |
| 9091 | changes = performLayoutLockedInner(); |
| 9092 | if (changes != 0) { |
| 9093 | continue; |
| 9094 | } |
| 9095 | } else { |
| 9096 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9097 | changes = 0; |
| 9098 | } |
| 9099 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9100 | final int transactionSequence = ++mTransactionSequence; |
| 9101 | |
| 9102 | // Update animations of all applications, including those |
| 9103 | // associated with exiting/removed apps |
| 9104 | boolean tokensAnimating = false; |
| 9105 | final int NAT = mAppTokens.size(); |
| 9106 | for (i=0; i<NAT; i++) { |
| 9107 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9108 | tokensAnimating = true; |
| 9109 | } |
| 9110 | } |
| 9111 | final int NEAT = mExitingAppTokens.size(); |
| 9112 | for (i=0; i<NEAT; i++) { |
| 9113 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9114 | tokensAnimating = true; |
| 9115 | } |
| 9116 | } |
| 9117 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9118 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9119 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9120 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9121 | + transactionSequence + " tokensAnimating=" |
| 9122 | + tokensAnimating); |
| 9123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9125 | |
| 9126 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9127 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9128 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9129 | |
| 9130 | mPolicy.beginAnimationLw(dw, dh); |
| 9131 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9132 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9134 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9135 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9136 | |
| 9137 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9138 | |
| 9139 | if (w.mSurface != null) { |
| 9140 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9141 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9142 | if ((w.mAttrs.flags |
| 9143 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9144 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9145 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9146 | wallpaperMayChange = true; |
| 9147 | } |
| 9148 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9149 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9150 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9151 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9152 | animating = true; |
| 9153 | //w.dump(" "); |
| 9154 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9155 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9156 | wallpaperMayChange = true; |
| 9157 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9158 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9159 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9160 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9161 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9162 | "Animation done that could impact force hide: " |
| 9163 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9164 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9165 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9166 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9167 | forceHiding = true; |
| 9168 | } |
| 9169 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9170 | boolean changed; |
| 9171 | if (forceHiding) { |
| 9172 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9173 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9174 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9175 | } else { |
| 9176 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9177 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9178 | "Now policy shown: " + w); |
| 9179 | if (changed) { |
| 9180 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9181 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9182 | // Assume we will need to animate. If |
| 9183 | // we don't (because the wallpaper will |
| 9184 | // stay with the lock screen), then we will |
| 9185 | // clean up later. |
| 9186 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9187 | if (a != null) { |
| 9188 | w.setAnimation(a); |
| 9189 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9190 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9191 | if (mCurrentFocus == null || |
| 9192 | mCurrentFocus.mLayer < w.mLayer) { |
| 9193 | // We are showing on to of the current |
| 9194 | // focus, so re-evaluate focus to make |
| 9195 | // sure it is correct. |
| 9196 | mFocusMayChange = true; |
| 9197 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9198 | } |
| 9199 | } |
| 9200 | if (changed && (attrs.flags |
| 9201 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9202 | wallpaperMayChange = true; |
| 9203 | } |
| 9204 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9205 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9206 | mPolicy.animatingWindowLw(w, attrs); |
| 9207 | } |
| 9208 | |
| 9209 | final AppWindowToken atoken = w.mAppToken; |
| 9210 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9211 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9212 | atoken.lastTransactionSequence = transactionSequence; |
| 9213 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9214 | atoken.startingDisplayed = false; |
| 9215 | } |
| 9216 | if ((w.isOnScreen() || w.mAttrs.type |
| 9217 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9218 | && !w.mExiting && !w.mDestroying) { |
| 9219 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9220 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9221 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9223 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9224 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9225 | + " pv=" + w.mPolicyVisibility |
| 9226 | + " dp=" + w.mDrawPending |
| 9227 | + " cdp=" + w.mCommitDrawPending |
| 9228 | + " ah=" + w.mAttachedHidden |
| 9229 | + " th=" + atoken.hiddenRequested |
| 9230 | + " a=" + w.mAnimating); |
| 9231 | } |
| 9232 | } |
| 9233 | if (w != atoken.startingWindow) { |
| 9234 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9235 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9236 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9237 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9238 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9239 | "tokenMayBeDrawn: " + atoken |
| 9240 | + " freezingScreen=" + atoken.freezingScreen |
| 9241 | + " mAppFreezing=" + w.mAppFreezing); |
| 9242 | tokenMayBeDrawn = true; |
| 9243 | } |
| 9244 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9245 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9246 | atoken.startingDisplayed = true; |
| 9247 | } |
| 9248 | } |
| 9249 | } else if (w.mReadyToShow) { |
| 9250 | w.performShowLocked(); |
| 9251 | } |
| 9252 | } |
| 9253 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9254 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9255 | |
| 9256 | if (tokenMayBeDrawn) { |
| 9257 | // See if any windows have been drawn, so they (and others |
| 9258 | // associated with them) can now be shown. |
| 9259 | final int NT = mTokenList.size(); |
| 9260 | for (i=0; i<NT; i++) { |
| 9261 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9262 | if (wtoken == null) { |
| 9263 | continue; |
| 9264 | } |
| 9265 | if (wtoken.freezingScreen) { |
| 9266 | int numInteresting = wtoken.numInterestingWindows; |
| 9267 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9268 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9269 | "allDrawn: " + wtoken |
| 9270 | + " interesting=" + numInteresting |
| 9271 | + " drawn=" + wtoken.numDrawnWindows); |
| 9272 | wtoken.showAllWindowsLocked(); |
| 9273 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9274 | orientationChangeComplete = true; |
| 9275 | } |
| 9276 | } else if (!wtoken.allDrawn) { |
| 9277 | int numInteresting = wtoken.numInterestingWindows; |
| 9278 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9279 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9280 | "allDrawn: " + wtoken |
| 9281 | + " interesting=" + numInteresting |
| 9282 | + " drawn=" + wtoken.numDrawnWindows); |
| 9283 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9284 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9285 | |
| 9286 | // We can now show all of the drawn windows! |
| 9287 | if (!mOpeningApps.contains(wtoken)) { |
| 9288 | wtoken.showAllWindowsLocked(); |
| 9289 | } |
| 9290 | } |
| 9291 | } |
| 9292 | } |
| 9293 | } |
| 9294 | |
| 9295 | // If we are ready to perform an app transition, check through |
| 9296 | // all of the app tokens to be shown and see if they are ready |
| 9297 | // to go. |
| 9298 | if (mAppTransitionReady) { |
| 9299 | int NN = mOpeningApps.size(); |
| 9300 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9301 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9302 | "Checking " + NN + " opening apps (frozen=" |
| 9303 | + mDisplayFrozen + " timeout=" |
| 9304 | + mAppTransitionTimeout + ")..."); |
| 9305 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9306 | // If the display isn't frozen, wait to do anything until |
| 9307 | // all of the apps are ready. Otherwise just go because |
| 9308 | // we'll unfreeze the display when everyone is ready. |
| 9309 | for (i=0; i<NN && goodToGo; i++) { |
| 9310 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9311 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9312 | "Check opening app" + wtoken + ": allDrawn=" |
| 9313 | + wtoken.allDrawn + " startingDisplayed=" |
| 9314 | + wtoken.startingDisplayed); |
| 9315 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9316 | && !wtoken.startingMoved) { |
| 9317 | goodToGo = false; |
| 9318 | } |
| 9319 | } |
| 9320 | } |
| 9321 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9322 | 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] | 9323 | int transit = mNextAppTransition; |
| 9324 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9325 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9326 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9327 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9328 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9329 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9330 | mAppTransitionTimeout = false; |
| 9331 | mStartingIconInTransition = false; |
| 9332 | mSkipAppTransitionAnimation = false; |
| 9333 | |
| 9334 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9335 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9336 | // If there are applications waiting to come to the |
| 9337 | // top of the stack, now is the time to move their windows. |
| 9338 | // (Note that we don't do apps going to the bottom |
| 9339 | // here -- we want to keep their windows in the old |
| 9340 | // Z-order until the animation completes.) |
| 9341 | if (mToTopApps.size() > 0) { |
| 9342 | NN = mAppTokens.size(); |
| 9343 | for (i=0; i<NN; i++) { |
| 9344 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9345 | if (wtoken.sendingToTop) { |
| 9346 | wtoken.sendingToTop = false; |
| 9347 | moveAppWindowsLocked(wtoken, NN, false); |
| 9348 | } |
| 9349 | } |
| 9350 | mToTopApps.clear(); |
| 9351 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9352 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9353 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9354 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9355 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9356 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9357 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9358 | // The top-most window will supply the layout params, |
| 9359 | // and we will determine it below. |
| 9360 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9361 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9362 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9363 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9364 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9365 | "New wallpaper target=" + mWallpaperTarget |
| 9366 | + ", lower target=" + mLowerWallpaperTarget |
| 9367 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9368 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9369 | // Do a first pass through the tokens for two |
| 9370 | // things: |
| 9371 | // (1) Determine if both the closing and opening |
| 9372 | // app token sets are wallpaper targets, in which |
| 9373 | // case special animations are needed |
| 9374 | // (since the wallpaper needs to stay static |
| 9375 | // behind them). |
| 9376 | // (2) Find the layout params of the top-most |
| 9377 | // application window in the tokens, which is |
| 9378 | // what will control the animation theme. |
| 9379 | final int NC = mClosingApps.size(); |
| 9380 | NN = NC + mOpeningApps.size(); |
| 9381 | for (i=0; i<NN; i++) { |
| 9382 | AppWindowToken wtoken; |
| 9383 | int mode; |
| 9384 | if (i < NC) { |
| 9385 | wtoken = mClosingApps.get(i); |
| 9386 | mode = 1; |
| 9387 | } else { |
| 9388 | wtoken = mOpeningApps.get(i-NC); |
| 9389 | mode = 2; |
| 9390 | } |
| 9391 | if (mLowerWallpaperTarget != null) { |
| 9392 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9393 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9394 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9395 | } |
| 9396 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9397 | if (wtoken.appFullscreen) { |
| 9398 | WindowState ws = wtoken.findMainWindow(); |
| 9399 | if (ws != null) { |
| 9400 | // If this is a compatibility mode |
| 9401 | // window, we will always use its anim. |
| 9402 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9403 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9404 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9405 | bestAnimLayer = Integer.MAX_VALUE; |
| 9406 | } else if (ws.mLayer > bestAnimLayer) { |
| 9407 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9408 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9409 | bestAnimLayer = ws.mLayer; |
| 9410 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9411 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9412 | } |
| 9413 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9414 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9415 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9416 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9417 | "Wallpaper animation!"); |
| 9418 | switch (transit) { |
| 9419 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9420 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9421 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9422 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9423 | break; |
| 9424 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9425 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9426 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9427 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9428 | break; |
| 9429 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9430 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9431 | "New transit: " + transit); |
| 9432 | } else if (oldWallpaper != null) { |
| 9433 | // We are transitioning from an activity with |
| 9434 | // a wallpaper to one without. |
| 9435 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9436 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9437 | "New transit away from wallpaper: " + transit); |
| 9438 | } else if (mWallpaperTarget != null) { |
| 9439 | // We are transitioning from an activity without |
| 9440 | // a wallpaper to now showing the wallpaper |
| 9441 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9442 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9443 | "New transit into wallpaper: " + transit); |
| 9444 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9445 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9446 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9447 | mLastEnterAnimToken = animToken; |
| 9448 | mLastEnterAnimParams = animLp; |
| 9449 | } else if (mLastEnterAnimParams != null) { |
| 9450 | animLp = mLastEnterAnimParams; |
| 9451 | mLastEnterAnimToken = null; |
| 9452 | mLastEnterAnimParams = null; |
| 9453 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9454 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9455 | // If all closing windows are obscured, then there is |
| 9456 | // no need to do an animation. This is the case, for |
| 9457 | // example, when this transition is being done behind |
| 9458 | // the lock screen. |
| 9459 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9460 | animLp = null; |
| 9461 | } |
| 9462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9463 | NN = mOpeningApps.size(); |
| 9464 | for (i=0; i<NN; i++) { |
| 9465 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9466 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9467 | "Now opening app" + wtoken); |
| 9468 | wtoken.reportedVisible = false; |
| 9469 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9470 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9471 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9472 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9473 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9474 | wtoken.showAllWindowsLocked(); |
| 9475 | } |
| 9476 | NN = mClosingApps.size(); |
| 9477 | for (i=0; i<NN; i++) { |
| 9478 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9479 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9480 | "Now closing app" + wtoken); |
| 9481 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9482 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9483 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9485 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9486 | // Force the allDrawn flag, because we want to start |
| 9487 | // this guy's animations regardless of whether it's |
| 9488 | // gotten drawn. |
| 9489 | wtoken.allDrawn = true; |
| 9490 | } |
| 9491 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9492 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9494 | mOpeningApps.clear(); |
| 9495 | mClosingApps.clear(); |
| 9496 | |
| 9497 | // This has changed the visibility of windows, so perform |
| 9498 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9499 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9500 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9501 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9502 | assignLayersLocked(); |
| 9503 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9504 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9505 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9506 | } |
| 9507 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9508 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9509 | int adjResult = 0; |
| 9510 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9511 | if (!animating && mAppTransitionRunning) { |
| 9512 | // We have finished the animation of an app transition. To do |
| 9513 | // this, we have delayed a lot of operations like showing and |
| 9514 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9515 | // reflects the correct Z-order, but the window list may now |
| 9516 | // be out of sync with it. So here we will just rebuild the |
| 9517 | // entire app window list. Fun! |
| 9518 | mAppTransitionRunning = false; |
| 9519 | // Clear information about apps that were moving. |
| 9520 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9521 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9522 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9523 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9524 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9525 | moveInputMethodWindowsIfNeededLocked(false); |
| 9526 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9527 | // Since the window list has been rebuilt, focus might |
| 9528 | // have to be recomputed since the actual order of windows |
| 9529 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9530 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9531 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9532 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9533 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9534 | // At this point, there was a window with a wallpaper that |
| 9535 | // was force hiding other windows behind it, but now it |
| 9536 | // is going away. This may be simple -- just animate |
| 9537 | // away the wallpaper and its window -- or it may be |
| 9538 | // hard -- the wallpaper now needs to be shown behind |
| 9539 | // something that was hidden. |
| 9540 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9541 | if (mLowerWallpaperTarget != null |
| 9542 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9543 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9544 | "wallpaperForceHiding changed with lower=" |
| 9545 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9546 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9547 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9548 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9549 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9550 | // The lower target has become hidden before we |
| 9551 | // actually started the animation... let's completely |
| 9552 | // re-evaluate everything. |
| 9553 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9554 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9555 | } |
| 9556 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9557 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9558 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9559 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9560 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9561 | + " NEW: " + mWallpaperTarget |
| 9562 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9563 | if (mLowerWallpaperTarget == null) { |
| 9564 | // Whoops, we don't need a special wallpaper animation. |
| 9565 | // Clear them out. |
| 9566 | forceHiding = false; |
| 9567 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9568 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9569 | if (w.mSurface != null) { |
| 9570 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9571 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9572 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9573 | forceHiding = true; |
| 9574 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9575 | if (!w.mAnimating) { |
| 9576 | // We set the animation above so it |
| 9577 | // is not yet running. |
| 9578 | w.clearAnimation(); |
| 9579 | } |
| 9580 | } |
| 9581 | } |
| 9582 | } |
| 9583 | } |
| 9584 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9585 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9586 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9587 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9588 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9589 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9590 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9591 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9592 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9593 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9594 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9595 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9596 | assignLayersLocked(); |
| 9597 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9598 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9599 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9600 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9601 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9602 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9603 | if (mFocusMayChange) { |
| 9604 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9605 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9606 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9607 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9608 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9609 | } |
| 9610 | |
| 9611 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9612 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9613 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9614 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9615 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9616 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9617 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9618 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9619 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9620 | |
| 9621 | // THIRD LOOP: Update the surfaces of all windows. |
| 9622 | |
| 9623 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9624 | |
| 9625 | boolean obscured = false; |
| 9626 | boolean blurring = false; |
| 9627 | boolean dimming = false; |
| 9628 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9629 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9630 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9631 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9632 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9633 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9634 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9635 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9636 | |
| 9637 | boolean displayed = false; |
| 9638 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9639 | final int attrFlags = attrs.flags; |
| 9640 | |
| 9641 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9642 | // XXX NOTE: The logic here could be improved. We have |
| 9643 | // the decision about whether to resize a window separated |
| 9644 | // from whether to hide the surface. This can cause us to |
| 9645 | // resize a surface even if we are going to hide it. You |
| 9646 | // can see this by (1) holding device in landscape mode on |
| 9647 | // home screen; (2) tapping browser icon (device will rotate |
| 9648 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9649 | // in step 2 but then immediately hidden, causing us to |
| 9650 | // have to resize and then redraw it again in step 3. It |
| 9651 | // would be nice to figure out how to avoid this, but it is |
| 9652 | // difficult because we do need to resize surfaces in some |
| 9653 | // cases while they are hidden such as when first showing a |
| 9654 | // window. |
| 9655 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9656 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9657 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9658 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9659 | + ": new=" + w.mShownFrame + ", old=" |
| 9660 | + w.mLastShownFrame); |
| 9661 | |
| 9662 | boolean resize; |
| 9663 | int width, height; |
| 9664 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9665 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9666 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9667 | // for a scaled surface, we just want to use |
| 9668 | // the requested size. |
| 9669 | width = w.mRequestedWidth; |
| 9670 | height = w.mRequestedHeight; |
| 9671 | w.mLastRequestedWidth = width; |
| 9672 | w.mLastRequestedHeight = height; |
| 9673 | w.mLastShownFrame.set(w.mShownFrame); |
| 9674 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9675 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9676 | "POS " + w.mShownFrame.left |
| 9677 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9678 | w.mSurfaceX = w.mShownFrame.left; |
| 9679 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9680 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9681 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9682 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9683 | if (!recoveringMemory) { |
| 9684 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9685 | } |
| 9686 | } |
| 9687 | } else { |
| 9688 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9689 | width = w.mShownFrame.width(); |
| 9690 | height = w.mShownFrame.height(); |
| 9691 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9692 | } |
| 9693 | |
| 9694 | if (resize) { |
| 9695 | if (width < 1) width = 1; |
| 9696 | if (height < 1) height = 1; |
| 9697 | if (w.mSurface != null) { |
| 9698 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9699 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9700 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9701 | + w.mShownFrame.top + " SIZE " |
| 9702 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9703 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9704 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9705 | w.mSurfaceW = width; |
| 9706 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9707 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9708 | w.mSurfaceX = w.mShownFrame.left; |
| 9709 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9710 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9711 | w.mShownFrame.top); |
| 9712 | } catch (RuntimeException e) { |
| 9713 | // If something goes wrong with the surface (such |
| 9714 | // as running out of memory), don't take down the |
| 9715 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9716 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9717 | + "size=(" + width + "x" + height |
| 9718 | + "), pos=(" + w.mShownFrame.left |
| 9719 | + "," + w.mShownFrame.top + ")", e); |
| 9720 | if (!recoveringMemory) { |
| 9721 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9722 | } |
| 9723 | } |
| 9724 | } |
| 9725 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9726 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9727 | w.mContentInsetsChanged = |
| 9728 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9729 | w.mVisibleInsetsChanged = |
| 9730 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9731 | boolean configChanged = |
| 9732 | w.mConfiguration != mCurConfiguration |
| 9733 | && (w.mConfiguration == null |
| 9734 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9735 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9736 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9737 | + mCurConfiguration); |
| 9738 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9739 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9740 | + ": configChanged=" + configChanged |
| 9741 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9742 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9743 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9744 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9745 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9746 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9747 | w.mLastFrame.set(w.mFrame); |
| 9748 | w.mLastContentInsets.set(w.mContentInsets); |
| 9749 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9750 | // If the screen is currently frozen, then keep |
| 9751 | // it frozen until this window draws at its new |
| 9752 | // orientation. |
| 9753 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9754 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9755 | "Resizing while display frozen: " + w); |
| 9756 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9757 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9758 | mWindowsFreezingScreen = true; |
| 9759 | // XXX should probably keep timeout from |
| 9760 | // when we first froze the display. |
| 9761 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9762 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9763 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9764 | } |
| 9765 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9766 | // If the orientation is changing, then we need to |
| 9767 | // hold off on unfreezing the display until this |
| 9768 | // window has been redrawn; to do that, we need |
| 9769 | // to go through the process of getting informed |
| 9770 | // by the application when it has finished drawing. |
| 9771 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9772 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9773 | "Orientation start waiting for draw in " |
| 9774 | + w + ", surface " + w.mSurface); |
| 9775 | w.mDrawPending = true; |
| 9776 | w.mCommitDrawPending = false; |
| 9777 | w.mReadyToShow = false; |
| 9778 | if (w.mAppToken != null) { |
| 9779 | w.mAppToken.allDrawn = false; |
| 9780 | } |
| 9781 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9782 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9783 | "Resizing window " + w + " to " + w.mFrame); |
| 9784 | mResizingWindows.add(w); |
| 9785 | } else if (w.mOrientationChanging) { |
| 9786 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9787 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9788 | "Orientation not waiting for draw in " |
| 9789 | + w + ", surface " + w.mSurface); |
| 9790 | w.mOrientationChanging = false; |
| 9791 | } |
| 9792 | } |
| 9793 | } |
| 9794 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9795 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9796 | if (!w.mLastHidden) { |
| 9797 | //dump(); |
| 9798 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9799 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9800 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9801 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9802 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9803 | try { |
| 9804 | w.mSurface.hide(); |
| 9805 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9806 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9807 | } |
| 9808 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9809 | } |
| 9810 | // If we are waiting for this window to handle an |
| 9811 | // orientation change, well, it is hidden, so |
| 9812 | // doesn't really matter. Note that this does |
| 9813 | // introduce a potential glitch if the window |
| 9814 | // becomes unhidden before it has drawn for the |
| 9815 | // new orientation. |
| 9816 | if (w.mOrientationChanging) { |
| 9817 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9818 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9819 | "Orientation change skips hidden " + w); |
| 9820 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9821 | } else if (w.mLastLayer != w.mAnimLayer |
| 9822 | || w.mLastAlpha != w.mShownAlpha |
| 9823 | || w.mLastDsDx != w.mDsDx |
| 9824 | || w.mLastDtDx != w.mDtDx |
| 9825 | || w.mLastDsDy != w.mDsDy |
| 9826 | || w.mLastDtDy != w.mDtDy |
| 9827 | || w.mLastHScale != w.mHScale |
| 9828 | || w.mLastVScale != w.mVScale |
| 9829 | || w.mLastHidden) { |
| 9830 | displayed = true; |
| 9831 | w.mLastAlpha = w.mShownAlpha; |
| 9832 | w.mLastLayer = w.mAnimLayer; |
| 9833 | w.mLastDsDx = w.mDsDx; |
| 9834 | w.mLastDtDx = w.mDtDx; |
| 9835 | w.mLastDsDy = w.mDsDy; |
| 9836 | w.mLastDtDy = w.mDtDy; |
| 9837 | w.mLastHScale = w.mHScale; |
| 9838 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9839 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9840 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9841 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9842 | + "," + (w.mDtDx*w.mVScale) |
| 9843 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9844 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9845 | if (w.mSurface != null) { |
| 9846 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9847 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9848 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9849 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9850 | w.mSurface.setLayer(w.mAnimLayer); |
| 9851 | w.mSurface.setMatrix( |
| 9852 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9853 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9854 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9855 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9856 | if (!recoveringMemory) { |
| 9857 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9858 | } |
| 9859 | } |
| 9860 | } |
| 9861 | |
| 9862 | if (w.mLastHidden && !w.mDrawPending |
| 9863 | && !w.mCommitDrawPending |
| 9864 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9865 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9866 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9867 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9868 | + " during relayout"); |
| 9869 | if (showSurfaceRobustlyLocked(w)) { |
| 9870 | w.mHasDrawn = true; |
| 9871 | w.mLastHidden = false; |
| 9872 | } else { |
| 9873 | w.mOrientationChanging = false; |
| 9874 | } |
| 9875 | } |
| 9876 | if (w.mSurface != null) { |
| 9877 | w.mToken.hasVisible = true; |
| 9878 | } |
| 9879 | } else { |
| 9880 | displayed = true; |
| 9881 | } |
| 9882 | |
| 9883 | if (displayed) { |
| 9884 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9885 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9886 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9887 | covered = true; |
| 9888 | } |
| 9889 | } |
| 9890 | if (w.mOrientationChanging) { |
| 9891 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9892 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9893 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9894 | "Orientation continue waiting for draw in " + w); |
| 9895 | } else { |
| 9896 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9897 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9898 | "Orientation change complete in " + w); |
| 9899 | } |
| 9900 | } |
| 9901 | w.mToken.hasVisible = true; |
| 9902 | } |
| 9903 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9904 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9905 | "Orientation change skips hidden " + w); |
| 9906 | w.mOrientationChanging = false; |
| 9907 | } |
| 9908 | |
| 9909 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9910 | |
| 9911 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9912 | focusDisplayed = true; |
| 9913 | } |
| 9914 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9915 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9916 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9917 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9918 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9919 | if (w.mSurface != null) { |
| 9920 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9921 | holdScreen = w.mSession; |
| 9922 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9923 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9924 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9925 | screenBrightness = w.mAttrs.screenBrightness; |
| 9926 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9927 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 9928 | && buttonBrightness < 0) { |
| 9929 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 9930 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 9931 | if (canBeSeen |
| 9932 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9933 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9934 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9935 | syswin = true; |
| 9936 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9937 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9938 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9939 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9940 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9941 | // This window completely covers everything behind it, |
| 9942 | // so we want to leave all of them as unblurred (for |
| 9943 | // performance reasons). |
| 9944 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9945 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9946 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9947 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9948 | obscured = true; |
| 9949 | if (mBackgroundFillerSurface == null) { |
| 9950 | try { |
| 9951 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9952 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9953 | 0, dw, dh, |
| 9954 | PixelFormat.OPAQUE, |
| 9955 | Surface.FX_SURFACE_NORMAL); |
| 9956 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9957 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9958 | } |
| 9959 | } |
| 9960 | try { |
| 9961 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9962 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9963 | // Using the same layer as Dim because they will never be shown at the |
| 9964 | // same time. |
| 9965 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9966 | mBackgroundFillerSurface.show(); |
| 9967 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9968 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9969 | } |
| 9970 | backgroundFillerShown = true; |
| 9971 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9972 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9973 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9974 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9975 | + ": blurring=" + blurring |
| 9976 | + " obscured=" + obscured |
| 9977 | + " displayed=" + displayed); |
| 9978 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9979 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9980 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9981 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9982 | if (mDimAnimator == null) { |
| 9983 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9984 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9985 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9986 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9987 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9988 | } |
| 9989 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9990 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9991 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9992 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9993 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9994 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9995 | + mBlurSurface + ": CREATE"); |
| 9996 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9997 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9998 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9999 | -1, 16, 16, |
| 10000 | PixelFormat.OPAQUE, |
| 10001 | Surface.FX_SURFACE_BLUR); |
| 10002 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10003 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10004 | } |
| 10005 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10006 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10007 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10008 | + mBlurSurface + ": pos=(0,0) (" + |
| 10009 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10010 | mBlurSurface.setPosition(0, 0); |
| 10011 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10012 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10013 | if (!mBlurShown) { |
| 10014 | try { |
| 10015 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10016 | + mBlurSurface + ": SHOW"); |
| 10017 | mBlurSurface.show(); |
| 10018 | } catch (RuntimeException e) { |
| 10019 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10020 | } |
| 10021 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10022 | } |
| 10023 | } |
| 10024 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10025 | } |
| 10026 | } |
| 10027 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10028 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10029 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10030 | // This is the wallpaper target and its obscured state |
| 10031 | // changed... make sure the current wallaper's visibility |
| 10032 | // has been updated accordingly. |
| 10033 | updateWallpaperVisibilityLocked(); |
| 10034 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10035 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10036 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10037 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10038 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10039 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10040 | try { |
| 10041 | mBackgroundFillerSurface.hide(); |
| 10042 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10043 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10044 | } |
| 10045 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10046 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10047 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10048 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10049 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10050 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10051 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10052 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10053 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10054 | + ": HIDE"); |
| 10055 | try { |
| 10056 | mBlurSurface.hide(); |
| 10057 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10058 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10059 | } |
| 10060 | mBlurShown = false; |
| 10061 | } |
| 10062 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10063 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10064 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10065 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10066 | } |
| 10067 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10068 | mInputMonitor.updateInputWindowsLw(); |
| 10069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10070 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10071 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10072 | if (mWatermark != null) { |
| 10073 | mWatermark.drawIfNeeded(); |
| 10074 | } |
| 10075 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10076 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10077 | "With display frozen, orientationChangeComplete=" |
| 10078 | + orientationChangeComplete); |
| 10079 | if (orientationChangeComplete) { |
| 10080 | if (mWindowsFreezingScreen) { |
| 10081 | mWindowsFreezingScreen = false; |
| 10082 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10083 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10084 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10085 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10086 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10087 | i = mResizingWindows.size(); |
| 10088 | if (i > 0) { |
| 10089 | do { |
| 10090 | i--; |
| 10091 | WindowState win = mResizingWindows.get(i); |
| 10092 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10093 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10094 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10095 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10096 | boolean configChanged = |
| 10097 | win.mConfiguration != mCurConfiguration |
| 10098 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10099 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10100 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10101 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10102 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10103 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10104 | + " / " + mCurConfiguration + " / 0x" |
| 10105 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10106 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10107 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10108 | win.mClient.resized(win.mFrame.width(), |
| 10109 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10110 | win.mLastVisibleInsets, win.mDrawPending, |
| 10111 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10112 | win.mContentInsetsChanged = false; |
| 10113 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10114 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10115 | } catch (RemoteException e) { |
| 10116 | win.mOrientationChanging = false; |
| 10117 | } |
| 10118 | } while (i > 0); |
| 10119 | mResizingWindows.clear(); |
| 10120 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10121 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10122 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10123 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10124 | i = mDestroySurface.size(); |
| 10125 | if (i > 0) { |
| 10126 | do { |
| 10127 | i--; |
| 10128 | WindowState win = mDestroySurface.get(i); |
| 10129 | win.mDestroying = false; |
| 10130 | if (mInputMethodWindow == win) { |
| 10131 | mInputMethodWindow = null; |
| 10132 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10133 | if (win == mWallpaperTarget) { |
| 10134 | wallpaperDestroyed = true; |
| 10135 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10136 | win.destroySurfaceLocked(); |
| 10137 | } while (i > 0); |
| 10138 | mDestroySurface.clear(); |
| 10139 | } |
| 10140 | |
| 10141 | // Time to remove any exiting tokens? |
| 10142 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10143 | WindowToken token = mExitingTokens.get(i); |
| 10144 | if (!token.hasVisible) { |
| 10145 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10146 | if (token.windowType == TYPE_WALLPAPER) { |
| 10147 | mWallpaperTokens.remove(token); |
| 10148 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10149 | } |
| 10150 | } |
| 10151 | |
| 10152 | // Time to remove any exiting applications? |
| 10153 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10154 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10155 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10156 | // Make sure there is no animation running on this token, |
| 10157 | // so any windows associated with it will be removed as |
| 10158 | // soon as their animations are complete |
| 10159 | token.animation = null; |
| 10160 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10161 | mAppTokens.remove(token); |
| 10162 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10163 | if (mLastEnterAnimToken == token) { |
| 10164 | mLastEnterAnimToken = null; |
| 10165 | mLastEnterAnimParams = null; |
| 10166 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10167 | } |
| 10168 | } |
| 10169 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10170 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10171 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10172 | if (!animating && mAppTransitionRunning) { |
| 10173 | // We have finished the animation of an app transition. To do |
| 10174 | // this, we have delayed a lot of operations like showing and |
| 10175 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10176 | // reflects the correct Z-order, but the window list may now |
| 10177 | // be out of sync with it. So here we will just rebuild the |
| 10178 | // entire app window list. Fun! |
| 10179 | mAppTransitionRunning = false; |
| 10180 | needRelayout = true; |
| 10181 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10182 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10183 | // Clear information about apps that were moving. |
| 10184 | mToBottomApps.clear(); |
| 10185 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10187 | if (focusDisplayed) { |
| 10188 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10189 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10190 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10191 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10192 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10193 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10194 | requestAnimationLocked(0); |
| 10195 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10196 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10197 | } |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10198 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10199 | mInputMonitor.updateInputWindowsLw(); |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10200 | |
| Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10201 | setHoldScreenLocked(holdScreen != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10202 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10203 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10204 | } else { |
| 10205 | mPowerManager.setScreenBrightnessOverride((int) |
| 10206 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10207 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10208 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10209 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10210 | } else { |
| 10211 | mPowerManager.setButtonBrightnessOverride((int) |
| 10212 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10213 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10214 | if (holdScreen != mHoldingScreenOn) { |
| 10215 | mHoldingScreenOn = holdScreen; |
| 10216 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10217 | mH.sendMessage(m); |
| 10218 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10219 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10220 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10221 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10222 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10223 | LocalPowerManager.BUTTON_EVENT, true); |
| 10224 | mTurnOnScreen = false; |
| 10225 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10226 | |
| 10227 | // Check to see if we are now in a state where the screen should |
| 10228 | // be enabled, because the window obscured flags have changed. |
| 10229 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10230 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10231 | |
| 10232 | /** |
| 10233 | * Must be called with the main window manager lock held. |
| 10234 | */ |
| 10235 | void setHoldScreenLocked(boolean holding) { |
| 10236 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10237 | if (holding != state) { |
| 10238 | if (holding) { |
| 10239 | mHoldingScreenWakeLock.acquire(); |
| 10240 | } else { |
| 10241 | mPolicy.screenOnStoppedLw(); |
| 10242 | mHoldingScreenWakeLock.release(); |
| 10243 | } |
| 10244 | } |
| 10245 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10246 | |
| 10247 | void requestAnimationLocked(long delay) { |
| 10248 | if (!mAnimationPending) { |
| 10249 | mAnimationPending = true; |
| 10250 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10251 | } |
| 10252 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10254 | /** |
| 10255 | * Have the surface flinger show a surface, robustly dealing with |
| 10256 | * error conditions. In particular, if there is not enough memory |
| 10257 | * to show the surface, then we will try to get rid of other surfaces |
| 10258 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10259 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10260 | * @return Returns true if the surface was successfully shown. |
| 10261 | */ |
| 10262 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10263 | try { |
| 10264 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10265 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10266 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10267 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10268 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10269 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10270 | win.mTurnOnScreen = false; |
| 10271 | mTurnOnScreen = true; |
| 10272 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10273 | } |
| 10274 | return true; |
| 10275 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10276 | 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] | 10277 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10278 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10279 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10280 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10281 | return false; |
| 10282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10284 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10285 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10286 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10287 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10288 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10289 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10290 | if (mForceRemoves == null) { |
| 10291 | mForceRemoves = new ArrayList<WindowState>(); |
| 10292 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10294 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10295 | try { |
| 10296 | // There was some problem... first, do a sanity check of the |
| 10297 | // window list to make sure we haven't left any dangling surfaces |
| 10298 | // around. |
| 10299 | int N = mWindows.size(); |
| 10300 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10301 | 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] | 10302 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10303 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10304 | if (ws.mSurface != null) { |
| 10305 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10306 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10307 | + ws + " surface=" + ws.mSurface |
| 10308 | + " token=" + win.mToken |
| 10309 | + " pid=" + ws.mSession.mPid |
| 10310 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10311 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10312 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10313 | ws.mSurface = null; |
| 10314 | mForceRemoves.add(ws); |
| 10315 | i--; |
| 10316 | N--; |
| 10317 | leakedSurface = true; |
| 10318 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10319 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10320 | + ws + " surface=" + ws.mSurface |
| 10321 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10322 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10323 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10324 | ws.mSurface = null; |
| 10325 | leakedSurface = true; |
| 10326 | } |
| 10327 | } |
| 10328 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10329 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10330 | boolean killedApps = false; |
| 10331 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10332 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10333 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10334 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10335 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10336 | if (ws.mSurface != null) { |
| 10337 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10338 | } |
| 10339 | } |
| 10340 | if (pidCandidates.size() > 0) { |
| 10341 | int[] pids = new int[pidCandidates.size()]; |
| 10342 | for (int i=0; i<pids.length; i++) { |
| 10343 | pids[i] = pidCandidates.keyAt(i); |
| 10344 | } |
| 10345 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10346 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10347 | killedApps = true; |
| 10348 | } |
| 10349 | } catch (RemoteException e) { |
| 10350 | } |
| 10351 | } |
| 10352 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10353 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10354 | if (leakedSurface || killedApps) { |
| 10355 | // We managed to reclaim some memory, so get rid of the trouble |
| 10356 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10357 | 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] | 10358 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10359 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10360 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10361 | win.mSurface = null; |
| 10362 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10363 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10364 | try { |
| 10365 | win.mClient.dispatchGetNewSurface(); |
| 10366 | } catch (RemoteException e) { |
| 10367 | } |
| 10368 | } |
| 10369 | } finally { |
| 10370 | Binder.restoreCallingIdentity(callingIdentity); |
| 10371 | } |
| 10372 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10374 | private boolean updateFocusedWindowLocked(int mode) { |
| 10375 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10376 | if (mCurrentFocus != newFocus) { |
| 10377 | // This check makes sure that we don't already have the focus |
| 10378 | // change message pending. |
| 10379 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10380 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10381 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10382 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10383 | final WindowState oldFocus = mCurrentFocus; |
| 10384 | mCurrentFocus = newFocus; |
| 10385 | mLosingFocus.remove(newFocus); |
| 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 | final WindowState imWindow = mInputMethodWindow; |
| 10388 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10389 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10390 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10391 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10392 | mLayoutNeeded = true; |
| 10393 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10394 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10395 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10396 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10397 | // Client will do the layout, but we need to assign layers |
| 10398 | // for handleNewWindowLocked() below. |
| 10399 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10400 | } |
| 10401 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10402 | |
| 10403 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10404 | // If we defer assigning layers, then the caller is responsible for |
| 10405 | // doing this part. |
| 10406 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10407 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10408 | return true; |
| 10409 | } |
| 10410 | return false; |
| 10411 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10412 | |
| 10413 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10414 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10415 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10416 | |
| 10417 | private WindowState computeFocusedWindowLocked() { |
| 10418 | WindowState result = null; |
| 10419 | WindowState win; |
| 10420 | |
| 10421 | int i = mWindows.size() - 1; |
| 10422 | int nextAppIndex = mAppTokens.size()-1; |
| 10423 | WindowToken nextApp = nextAppIndex >= 0 |
| 10424 | ? mAppTokens.get(nextAppIndex) : null; |
| 10425 | |
| 10426 | while (i >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10427 | win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10428 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10429 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10430 | TAG, "Looking for focus: " + i |
| 10431 | + " = " + win |
| 10432 | + ", flags=" + win.mAttrs.flags |
| 10433 | + ", canReceive=" + win.canReceiveKeys()); |
| 10434 | |
| 10435 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10437 | // If this window's application has been removed, just skip it. |
| 10438 | if (thisApp != null && thisApp.removed) { |
| 10439 | i--; |
| 10440 | continue; |
| 10441 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10443 | // If there is a focused app, don't allow focus to go to any |
| 10444 | // windows below it. If this is an application window, step |
| 10445 | // through the app tokens until we find its app. |
| 10446 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10447 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10448 | int origAppIndex = nextAppIndex; |
| 10449 | while (nextAppIndex > 0) { |
| 10450 | if (nextApp == mFocusedApp) { |
| 10451 | // Whoops, we are below the focused app... no focus |
| 10452 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10453 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10454 | TAG, "Reached focused app: " + mFocusedApp); |
| 10455 | return null; |
| 10456 | } |
| 10457 | nextAppIndex--; |
| 10458 | nextApp = mAppTokens.get(nextAppIndex); |
| 10459 | if (nextApp == thisApp) { |
| 10460 | break; |
| 10461 | } |
| 10462 | } |
| 10463 | if (thisApp != nextApp) { |
| 10464 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10465 | // happen, but if it does we can get totally hosed... |
| 10466 | // so restart at the original app. |
| 10467 | nextAppIndex = origAppIndex; |
| 10468 | nextApp = mAppTokens.get(nextAppIndex); |
| 10469 | } |
| 10470 | } |
| 10471 | |
| 10472 | // Dispatch to this window if it is wants key events. |
| 10473 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10474 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10475 | TAG, "Found focus @ " + i + " = " + win); |
| 10476 | result = win; |
| 10477 | break; |
| 10478 | } |
| 10479 | |
| 10480 | i--; |
| 10481 | } |
| 10482 | |
| 10483 | return result; |
| 10484 | } |
| 10485 | |
| 10486 | private void startFreezingDisplayLocked() { |
| 10487 | if (mDisplayFrozen) { |
| 10488 | return; |
| 10489 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10490 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10491 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10493 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10494 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10495 | if (mFreezeGcPending != 0) { |
| 10496 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10497 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10498 | mH.removeMessages(H.FORCE_GC); |
| 10499 | Runtime.getRuntime().gc(); |
| 10500 | mFreezeGcPending = now; |
| 10501 | } |
| 10502 | } else { |
| 10503 | mFreezeGcPending = now; |
| 10504 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10506 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10507 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10508 | mInputMonitor.freezeInputDispatchingLw(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10509 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10510 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10511 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10512 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10513 | mAppTransitionReady = true; |
| 10514 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10516 | if (PROFILE_ORIENTATION) { |
| 10517 | File file = new File("/data/system/frozen"); |
| 10518 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10519 | } |
| 10520 | Surface.freezeDisplay(0); |
| 10521 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10523 | private void stopFreezingDisplayLocked() { |
| 10524 | if (!mDisplayFrozen) { |
| 10525 | return; |
| 10526 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10527 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10528 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10529 | return; |
| 10530 | } |
| 10531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10532 | mDisplayFrozen = false; |
| 10533 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10534 | if (PROFILE_ORIENTATION) { |
| 10535 | Debug.stopMethodTracing(); |
| 10536 | } |
| 10537 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10538 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10539 | mInputMonitor.thawInputDispatchingLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10540 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10541 | // While the display is frozen we don't re-compute the orientation |
| 10542 | // to avoid inconsistent states. However, something interesting |
| 10543 | // could have actually changed during that time so re-evaluate it |
| 10544 | // now to catch that. |
| 10545 | if (updateOrientationFromAppTokensLocked()) { |
| 10546 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10547 | } |
| 10548 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10549 | // A little kludge: a lot could have happened while the |
| 10550 | // display was frozen, so now that we are coming back we |
| 10551 | // do a gc so that any remote references the system |
| 10552 | // processes holds on others can be released if they are |
| 10553 | // no longer needed. |
| 10554 | mH.removeMessages(H.FORCE_GC); |
| 10555 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10556 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10558 | mScreenFrozenLock.release(); |
| 10559 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10560 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10561 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10562 | DisplayMetrics dm) { |
| 10563 | if (index < tokens.length) { |
| 10564 | String str = tokens[index]; |
| 10565 | if (str != null && str.length() > 0) { |
| 10566 | try { |
| 10567 | int val = Integer.parseInt(str); |
| 10568 | return val; |
| 10569 | } catch (Exception e) { |
| 10570 | } |
| 10571 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10572 | } |
| 10573 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10574 | return defDps; |
| 10575 | } |
| 10576 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10577 | return val; |
| 10578 | } |
| 10579 | |
| 10580 | class Watermark { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10581 | final String[] mTokens; |
| 10582 | final String mText; |
| 10583 | final Paint mTextPaint; |
| 10584 | final int mTextWidth; |
| 10585 | final int mTextHeight; |
| 10586 | final int mTextAscent; |
| 10587 | final int mTextDescent; |
| 10588 | final int mDeltaX; |
| 10589 | final int mDeltaY; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10590 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10591 | Surface mSurface; |
| 10592 | int mLastDW; |
| 10593 | int mLastDH; |
| 10594 | boolean mDrawNeeded; |
| 10595 | |
| 10596 | Watermark(SurfaceSession session, String[] tokens) { |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10597 | final DisplayMetrics dm = new DisplayMetrics(); |
| 10598 | mDisplay.getMetrics(dm); |
| 10599 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10600 | if (false) { |
| 10601 | Log.i(TAG, "*********************** WATERMARK"); |
| 10602 | for (int i=0; i<tokens.length; i++) { |
| 10603 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 10604 | } |
| 10605 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10606 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10607 | mTokens = tokens; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10608 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10609 | StringBuilder builder = new StringBuilder(32); |
| 10610 | int len = mTokens[0].length(); |
| 10611 | len = len & ~1; |
| 10612 | for (int i=0; i<len; i+=2) { |
| 10613 | int c1 = mTokens[0].charAt(i); |
| 10614 | int c2 = mTokens[0].charAt(i+1); |
| 10615 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 10616 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 10617 | else c1 -= '0'; |
| 10618 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 10619 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 10620 | else c2 -= '0'; |
| 10621 | builder.append((char)(255-((c1*16)+c2))); |
| 10622 | } |
| 10623 | mText = builder.toString(); |
| 10624 | if (false) { |
| 10625 | Log.i(TAG, "Final text: " + mText); |
| 10626 | } |
| 10627 | |
| 10628 | int fontSize = getPropertyInt(tokens, 1, |
| 10629 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 10630 | |
| 10631 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 10632 | mTextPaint.setTextSize(fontSize); |
| 10633 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 10634 | |
| 10635 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 10636 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 10637 | mTextAscent = fm.ascent; |
| 10638 | mTextDescent = fm.descent; |
| 10639 | mTextHeight = fm.descent - fm.ascent; |
| 10640 | |
| 10641 | mDeltaX = getPropertyInt(tokens, 2, |
| 10642 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 10643 | mDeltaY = getPropertyInt(tokens, 3, |
| 10644 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 10645 | int shadowColor = getPropertyInt(tokens, 4, |
| 10646 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 10647 | int color = getPropertyInt(tokens, 5, |
| 10648 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 10649 | int shadowRadius = getPropertyInt(tokens, 6, |
| 10650 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 10651 | int shadowDx = getPropertyInt(tokens, 8, |
| 10652 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10653 | int shadowDy = getPropertyInt(tokens, 9, |
| 10654 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10655 | |
| 10656 | mTextPaint.setColor(color); |
| 10657 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10658 | |
| 10659 | try { |
| 10660 | mSurface = new Surface(session, 0, |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10661 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10662 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10663 | mSurface.setPosition(0, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10664 | mSurface.show(); |
| 10665 | } catch (OutOfResourcesException e) { |
| 10666 | } |
| 10667 | } |
| 10668 | |
| 10669 | void positionSurface(int dw, int dh) { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10670 | if (mLastDW != dw || mLastDH != dh) { |
| 10671 | mLastDW = dw; |
| 10672 | mLastDH = dh; |
| 10673 | mSurface.setSize(dw, dh); |
| 10674 | mDrawNeeded = true; |
| 10675 | } |
| 10676 | } |
| 10677 | |
| 10678 | void drawIfNeeded() { |
| 10679 | if (mDrawNeeded) { |
| 10680 | final int dw = mLastDW; |
| 10681 | final int dh = mLastDH; |
| 10682 | |
| 10683 | mDrawNeeded = false; |
| 10684 | Rect dirty = new Rect(0, 0, dw, dh); |
| 10685 | Canvas c = null; |
| 10686 | try { |
| 10687 | c = mSurface.lockCanvas(dirty); |
| 10688 | } catch (IllegalArgumentException e) { |
| 10689 | } catch (OutOfResourcesException e) { |
| 10690 | } |
| 10691 | if (c != null) { |
| 10692 | int deltaX = mDeltaX; |
| 10693 | int deltaY = mDeltaY; |
| 10694 | |
| 10695 | // deltaX shouldn't be close to a round fraction of our |
| 10696 | // x step, or else things will line up too much. |
| 10697 | int div = (dw+mTextWidth)/deltaX; |
| 10698 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 10699 | int qdelta = deltaX/4; |
| 10700 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 10701 | deltaX += deltaX/3; |
| 10702 | } |
| 10703 | |
| 10704 | int y = -mTextHeight; |
| 10705 | int x = -mTextWidth; |
| 10706 | while (y < (dh+mTextHeight)) { |
| 10707 | c.drawText(mText, x, y, mTextPaint); |
| 10708 | x += deltaX; |
| 10709 | if (x >= dw) { |
| 10710 | x -= (dw+mTextWidth); |
| 10711 | y += deltaY; |
| 10712 | } |
| 10713 | } |
| 10714 | mSurface.unlockCanvasAndPost(c); |
| 10715 | } |
| 10716 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10717 | } |
| 10718 | } |
| 10719 | |
| 10720 | void createWatermark() { |
| 10721 | if (mWatermark != null) { |
| 10722 | return; |
| 10723 | } |
| 10724 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10725 | File file = new File("/system/etc/setup.conf"); |
| 10726 | FileInputStream in = null; |
| 10727 | try { |
| 10728 | in = new FileInputStream(file); |
| 10729 | DataInputStream ind = new DataInputStream(in); |
| 10730 | String line = ind.readLine(); |
| 10731 | if (line != null) { |
| 10732 | String[] toks = line.split("%"); |
| 10733 | if (toks != null && toks.length > 0) { |
| 10734 | mWatermark = new Watermark(mFxSession, toks); |
| 10735 | } |
| 10736 | } |
| 10737 | } catch (FileNotFoundException e) { |
| 10738 | } catch (IOException e) { |
| 10739 | } finally { |
| 10740 | if (in != null) { |
| 10741 | try { |
| 10742 | in.close(); |
| 10743 | } catch (IOException e) { |
| 10744 | } |
| 10745 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10746 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10747 | } |
| 10748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10749 | @Override |
| 10750 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10751 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10752 | != PackageManager.PERMISSION_GRANTED) { |
| 10753 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10754 | + Binder.getCallingPid() |
| 10755 | + ", uid=" + Binder.getCallingUid()); |
| 10756 | return; |
| 10757 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10758 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10759 | mInputManager.dump(pw); |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10760 | pw.println(" "); |
| 10761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10762 | synchronized(mWindowMap) { |
| 10763 | pw.println("Current Window Manager state:"); |
| 10764 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10765 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10766 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10767 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10768 | w.dump(pw, " "); |
| 10769 | } |
| 10770 | if (mInputMethodDialogs.size() > 0) { |
| 10771 | pw.println(" "); |
| 10772 | pw.println(" Input method dialogs:"); |
| 10773 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10774 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10775 | 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] | 10776 | } |
| 10777 | } |
| 10778 | if (mPendingRemove.size() > 0) { |
| 10779 | pw.println(" "); |
| 10780 | pw.println(" Remove pending for:"); |
| 10781 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10782 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10783 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10784 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10785 | w.dump(pw, " "); |
| 10786 | } |
| 10787 | } |
| 10788 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10789 | pw.println(" "); |
| 10790 | pw.println(" Windows force removing:"); |
| 10791 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10792 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10793 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10794 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10795 | w.dump(pw, " "); |
| 10796 | } |
| 10797 | } |
| 10798 | if (mDestroySurface.size() > 0) { |
| 10799 | pw.println(" "); |
| 10800 | pw.println(" Windows waiting to destroy their surface:"); |
| 10801 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10802 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10803 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10804 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10805 | w.dump(pw, " "); |
| 10806 | } |
| 10807 | } |
| 10808 | if (mLosingFocus.size() > 0) { |
| 10809 | pw.println(" "); |
| 10810 | pw.println(" Windows losing focus:"); |
| 10811 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10812 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10813 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10814 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10815 | w.dump(pw, " "); |
| 10816 | } |
| 10817 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10818 | if (mResizingWindows.size() > 0) { |
| 10819 | pw.println(" "); |
| 10820 | pw.println(" Windows waiting to resize:"); |
| 10821 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10822 | WindowState w = mResizingWindows.get(i); |
| 10823 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10824 | pw.print(w); pw.println(":"); |
| 10825 | w.dump(pw, " "); |
| 10826 | } |
| 10827 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10828 | if (mSessions.size() > 0) { |
| 10829 | pw.println(" "); |
| 10830 | pw.println(" All active sessions:"); |
| 10831 | Iterator<Session> it = mSessions.iterator(); |
| 10832 | while (it.hasNext()) { |
| 10833 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10834 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10835 | s.dump(pw, " "); |
| 10836 | } |
| 10837 | } |
| 10838 | if (mTokenMap.size() > 0) { |
| 10839 | pw.println(" "); |
| 10840 | pw.println(" All tokens:"); |
| 10841 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10842 | while (it.hasNext()) { |
| 10843 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10844 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10845 | token.dump(pw, " "); |
| 10846 | } |
| 10847 | } |
| 10848 | if (mTokenList.size() > 0) { |
| 10849 | pw.println(" "); |
| 10850 | pw.println(" Window token list:"); |
| 10851 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10852 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10853 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10854 | } |
| 10855 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10856 | if (mWallpaperTokens.size() > 0) { |
| 10857 | pw.println(" "); |
| 10858 | pw.println(" Wallpaper tokens:"); |
| 10859 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10860 | WindowToken token = mWallpaperTokens.get(i); |
| 10861 | pw.print(" Wallpaper #"); pw.print(i); |
| 10862 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10863 | token.dump(pw, " "); |
| 10864 | } |
| 10865 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10866 | if (mAppTokens.size() > 0) { |
| 10867 | pw.println(" "); |
| 10868 | pw.println(" Application tokens in Z order:"); |
| 10869 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10870 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10871 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10872 | } |
| 10873 | } |
| 10874 | if (mFinishedStarting.size() > 0) { |
| 10875 | pw.println(" "); |
| 10876 | pw.println(" Finishing start of application tokens:"); |
| 10877 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10878 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10879 | pw.print(" Finished Starting #"); pw.print(i); |
| 10880 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10881 | token.dump(pw, " "); |
| 10882 | } |
| 10883 | } |
| 10884 | if (mExitingTokens.size() > 0) { |
| 10885 | pw.println(" "); |
| 10886 | pw.println(" Exiting tokens:"); |
| 10887 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10888 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10889 | pw.print(" Exiting #"); pw.print(i); |
| 10890 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10891 | token.dump(pw, " "); |
| 10892 | } |
| 10893 | } |
| 10894 | if (mExitingAppTokens.size() > 0) { |
| 10895 | pw.println(" "); |
| 10896 | pw.println(" Exiting application tokens:"); |
| 10897 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10898 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10899 | pw.print(" Exiting App #"); pw.print(i); |
| 10900 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10901 | token.dump(pw, " "); |
| 10902 | } |
| 10903 | } |
| 10904 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10905 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10906 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10907 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10908 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10909 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10910 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10911 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10912 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10913 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10914 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10915 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10916 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10917 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10918 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10919 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10920 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10921 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10922 | if (mDimAnimator != null) { |
| 10923 | mDimAnimator.printTo(pw); |
| 10924 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10925 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10926 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10927 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10928 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10929 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10930 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10931 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10932 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10933 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10934 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10935 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10936 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10937 | pw.print(" mRotation="); pw.print(mRotation); |
| 10938 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10939 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10940 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10941 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10942 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10943 | pw.print(" mNextAppTransition=0x"); |
| 10944 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10945 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10946 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10947 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10948 | if (mNextAppTransitionPackage != null) { |
| 10949 | pw.print(" mNextAppTransitionPackage="); |
| 10950 | pw.print(mNextAppTransitionPackage); |
| 10951 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10952 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10953 | pw.print(", mNextAppTransitionExit=0x"); |
| 10954 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10955 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10956 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10957 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10958 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10959 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10960 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10961 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10962 | if (mOpeningApps.size() > 0) { |
| 10963 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10964 | } |
| 10965 | if (mClosingApps.size() > 0) { |
| 10966 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10967 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10968 | if (mToTopApps.size() > 0) { |
| 10969 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10970 | } |
| 10971 | if (mToBottomApps.size() > 0) { |
| 10972 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10973 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10974 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10975 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10976 | } |
| 10977 | } |
| 10978 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10979 | // 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] | 10980 | public void monitor() { |
| 10981 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10982 | synchronized (mKeyguardTokenWatcher) { } |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10983 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10984 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10985 | /** |
| 10986 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10987 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10988 | */ |
| 10989 | private static class DimAnimator { |
| 10990 | Surface mDimSurface; |
| 10991 | boolean mDimShown = false; |
| 10992 | float mDimCurrentAlpha; |
| 10993 | float mDimTargetAlpha; |
| 10994 | float mDimDeltaPerMs; |
| 10995 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10996 | |
| 10997 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10998 | |
| 10999 | DimAnimator (SurfaceSession session) { |
| 11000 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11001 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11002 | + mDimSurface + ": CREATE"); |
| 11003 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11004 | mDimSurface = new Surface(session, 0, |
| 11005 | "DimSurface", |
| 11006 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11007 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11008 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11009 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11010 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11011 | } |
| 11012 | } |
| 11013 | } |
| 11014 | |
| 11015 | /** |
| 11016 | * Show the dim surface. |
| 11017 | */ |
| 11018 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11019 | if (!mDimShown) { |
| 11020 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11021 | dw + "x" + dh + ")"); |
| 11022 | mDimShown = true; |
| 11023 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11024 | mLastDimWidth = dw; |
| 11025 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11026 | mDimSurface.setPosition(0, 0); |
| 11027 | mDimSurface.setSize(dw, dh); |
| 11028 | mDimSurface.show(); |
| 11029 | } catch (RuntimeException e) { |
| 11030 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11031 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11032 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11033 | mLastDimWidth = dw; |
| 11034 | mLastDimHeight = dh; |
| 11035 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11036 | } |
| 11037 | } |
| 11038 | |
| 11039 | /** |
| 11040 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11041 | * {@link updateSurface} after all windows are examined. |
| 11042 | */ |
| 11043 | void updateParameters(WindowState w, long currentTime) { |
| 11044 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11045 | |
| 11046 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11047 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11048 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11049 | if (mDimTargetAlpha != target) { |
| 11050 | // If the desired dim level has changed, then |
| 11051 | // start an animation to it. |
| 11052 | mLastDimAnimTime = currentTime; |
| 11053 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11054 | ? w.mAnimation.computeDurationHint() |
| 11055 | : DEFAULT_DIM_DURATION; |
| 11056 | if (target > mDimTargetAlpha) { |
| 11057 | // This is happening behind the activity UI, |
| 11058 | // so we can make it run a little longer to |
| 11059 | // give a stronger impression without disrupting |
| 11060 | // the user. |
| 11061 | duration *= DIM_DURATION_MULTIPLIER; |
| 11062 | } |
| 11063 | if (duration < 1) { |
| 11064 | // Don't divide by zero |
| 11065 | duration = 1; |
| 11066 | } |
| 11067 | mDimTargetAlpha = target; |
| 11068 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11069 | } |
| 11070 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11071 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11072 | /** |
| 11073 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11074 | * false when the animation is finished and the dim surface is hidden. |
| 11075 | */ |
| 11076 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11077 | if (!dimming) { |
| 11078 | if (mDimTargetAlpha != 0) { |
| 11079 | mLastDimAnimTime = currentTime; |
| 11080 | mDimTargetAlpha = 0; |
| 11081 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11082 | } |
| 11083 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11084 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11085 | boolean animating = false; |
| 11086 | if (mLastDimAnimTime != 0) { |
| 11087 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11088 | * (currentTime-mLastDimAnimTime); |
| 11089 | boolean more = true; |
| 11090 | if (displayFrozen) { |
| 11091 | // If the display is frozen, there is no reason to animate. |
| 11092 | more = false; |
| 11093 | } else if (mDimDeltaPerMs > 0) { |
| 11094 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11095 | more = false; |
| 11096 | } |
| 11097 | } else if (mDimDeltaPerMs < 0) { |
| 11098 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11099 | more = false; |
| 11100 | } |
| 11101 | } else { |
| 11102 | more = false; |
| 11103 | } |
| 11104 | |
| 11105 | // Do we need to continue animating? |
| 11106 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11107 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11108 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11109 | mLastDimAnimTime = currentTime; |
| 11110 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11111 | animating = true; |
| 11112 | } else { |
| 11113 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11114 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11115 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11116 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11117 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11118 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11119 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11120 | + ": HIDE"); |
| 11121 | try { |
| 11122 | mDimSurface.hide(); |
| 11123 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11124 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11125 | } |
| 11126 | mDimShown = false; |
| 11127 | } |
| 11128 | } |
| 11129 | } |
| 11130 | return animating; |
| 11131 | } |
| 11132 | |
| 11133 | public void printTo(PrintWriter pw) { |
| 11134 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11135 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11136 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11137 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11138 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11139 | } |
| 11140 | } |
| 11141 | |
| 11142 | /** |
| 11143 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11144 | * This is used for opening/closing transition for apps in compatible mode. |
| 11145 | */ |
| 11146 | private static class FadeInOutAnimation extends Animation { |
| 11147 | int mWidth; |
| 11148 | boolean mFadeIn; |
| 11149 | |
| 11150 | public FadeInOutAnimation(boolean fadeIn) { |
| 11151 | setInterpolator(new AccelerateInterpolator()); |
| 11152 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11153 | mFadeIn = fadeIn; |
| 11154 | } |
| 11155 | |
| 11156 | @Override |
| 11157 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11158 | float x = interpolatedTime; |
| 11159 | if (!mFadeIn) { |
| 11160 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11161 | } |
| 11162 | if (x < 0.5) { |
| 11163 | // move the window out of the screen. |
| 11164 | t.getMatrix().setTranslate(mWidth, 0); |
| 11165 | } else { |
| 11166 | t.getMatrix().setTranslate(0, 0);// show |
| 11167 | t.setAlpha((x - 0.5f) * 2); |
| 11168 | } |
| 11169 | } |
| 11170 | |
| 11171 | @Override |
| 11172 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11173 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11174 | mWidth = width; |
| 11175 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11176 | |
| 11177 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11178 | public int getZAdjustment() { |
| 11179 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11180 | } |
| 11181 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11182 | } |